A short question: I want to insert a variable with parenthesis into my sql query, without it being interpreted as a function. This since I retrieve the variable from a database and the variable is a parameter with the corresponding unit.
$rs= $db_connection->execute("SELECT * FROM table_a WHERE ". $Parameter .">0");
For example, $Parameter might equal to "Depth (m)", and would thus be considered as a function called Depth. I want it to be a complete string, not a function.
Thanks
Last edited by mliungman on Tue Dec 13, 2005 11:38 am, edited 2 times in total.
Actually, that's how I would write the query if $Parameter was an ordinary string. But in this particular case $Parameter is the column name in the database table that I'm querying. Whith single quotes I get the type mismatch error. Without single quotes I get an error saying "Undefined function 'Depth' in expression" (translated from the swedish error message). I have assumed that the string "Depth (m)" that I insert into the query is interpreted as a function. Which brings me back to my problem.
Martin
Last edited by mliungman on Tue Dec 13, 2005 9:53 am, edited 1 time in total.
I'm sorry but no. My problem is that I need the query to search the "Alkalinitet (mekv/l)" column in the table. The query, however, interprets my column name as a function if I omit the single quotes, and as a simple string if I use single quotes.
*Apparently* I'm not a php wizard, and do not claim to be one either. You are most welcome to point me in the right direction.
Thank you for several solutions addressing the actual problem. Backticks solved the problem the easiest way. Of course, changing the column names would too, but then I would have to create a new table with the units, and then rewrite my script to search that table also. It seemed easier to have the units together with the actual parameter, in the column name. It is also easier to add a new parameter to only one table.
Thanks for the help, everone.
P.S. Maybe Weirdan actually helped me in the first reply, but I never saw the backticks. I used single quotes all the time...