not sure if this is the right place to post this, i have a space in the variable in my sql string, is there a way to run this when there is a space in it?
$query3 = "Select * from cdump where name = $myrow1[0]";
thanks
i sorted this, i put it into a variable
$temp = $myrow1[0]; $query3 = "Select * from cdump where name = $temp";
Remeber to mark as "Resolved".
If name is not a numeric type of field, you probably need to quote the value:
name
$query3 = "Select * from cdump where name = '$temp'";
You could use the array element itself as:
$query3 = "Select * from cdump where name = '{$myrow1[0]}'";
you can also "exit" the string mode:
"Select * from cdump where name = '". $myrow1[0] ."'";
anyone know if this is faster or slower than NogDog's suguestion? $query3 = "Select * from cdump where name = '{$myrow1[0]}'";
anyone know if this is faster or slower than NogDog's suguestion?
Concatenation is slightly faster, but generally the speed difference is negligible. I personally find variable interpolation clearer than concatenation where such SQL statements are concerned, though it may be clearer to break up a long string. Alternatives that also promote clarity are sprintf() or even just using prepared statements.
laserlight wrote:just using prepared statements.
just using prepared statements.
assuming you have mysql >= 4.1 😉
assuming you have mysql >= 4.1
According to the PHP manual, there are PDO drivers available for MySQL 3.x and 4.x in general, therefore one can use prepared statements with all versions of MySQL from version 3 onwards. Of course, it also supports other database systems, not just MySQL.
Prepared statements work in PDO even if you aren't using them natively (i.e. prepared statement emulation). Such emulation may be turned on by default, as it improves performance in some cases.
Prepared statements make development easier. Ignore runtime performance arguments, they're usually unsubstantiated, often wrong and almost always irrelevant.
Mark