SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast
    Join Date
    Dec 2003
    Location
    Boston
    Posts
    71
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    question about substitution variables?

    Is it possible to use substitution variables (single-ampersand "&" like in Oracle) in MySql queries?
    If so, how can you handle it with php?

  2. #2
    Chessplayer kleineme's Avatar
    Join Date
    Apr 2004
    Location
    Germany
    Posts
    608
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    do you mean this or that? If so, just use it as any other query: mysql_query("SET @t1=0");
    Never ascribe to malice,
    that which can be explained by incompetence.
    Your code should not look unmaintainable, just be that way.

  3. #3
    SitePoint Enthusiast
    Join Date
    Dec 2003
    Location
    Boston
    Posts
    71
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    question on substitution variables?

    In oracle you can do this:

    SELECT employee_id, last_name, salary, department_id
    from employees
    where employee_id = &employee_num;

    When you run this query it will ask you for a value for the variable &employee_num.

    It is an interactive way to input values. And, I would like to know if it is possible to do the same in MySQL.
    And how do you handle that with PHP?

  4. #4
    Chessplayer kleineme's Avatar
    Join Date
    Apr 2004
    Location
    Germany
    Posts
    608
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    I haven't seen such a possibility in MySQL yet. But if you have the user input in some PHP variable, you can create a dynamic SQL:

    PHP Code:
    $employee_num 5;
    $sql "SELECT employee_id, last_name, salary, department_id
      FROM employees WHERE employee_id = " 
    $employee_num
    Never ascribe to malice,
    that which can be explained by incompetence.
    Your code should not look unmaintainable, just be that way.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •