I have a problem with some SQL code that can be run at the mySQL
command prompt, and in PHP, I can prepare it with no problem, but I
get a syntax error when I try and exexute it.
$sql = <<< EOF
SELECT * from ad where id = ? and
((endDate is null) or (endDate is not null and endDate >=
now()))";
EOF;
$query = $dbh->prepare($sql );
if (DB::iserror($q uery)) {
echo "Query error, " . $query->getMessage() . " please contact
admin<br>";
exit();
}
# works, no compaints, but a few steps later
foreach ($controls as $c) {
$e = $dbh->execute($query , $c);
if (DB::iserror($e )) {
echo "Execute error" . $e->getMessage() . " please contact
admin.<br>";
exit();
}
$e = $e->fetchRow(DB_FE TCHMODE_ASSOC);
}
I get this in my browser:
Execute error DB Error: syntax error please contact admin.
Now, if the sql was broken, I could understand the error, but I would
kind of have expected the prepare to fail.
This works OK if I leave off everything after id = $.
Any ideas?
Thanks in advance,
Randy
command prompt, and in PHP, I can prepare it with no problem, but I
get a syntax error when I try and exexute it.
$sql = <<< EOF
SELECT * from ad where id = ? and
((endDate is null) or (endDate is not null and endDate >=
now()))";
EOF;
$query = $dbh->prepare($sql );
if (DB::iserror($q uery)) {
echo "Query error, " . $query->getMessage() . " please contact
admin<br>";
exit();
}
# works, no compaints, but a few steps later
foreach ($controls as $c) {
$e = $dbh->execute($query , $c);
if (DB::iserror($e )) {
echo "Execute error" . $e->getMessage() . " please contact
admin.<br>";
exit();
}
$e = $e->fetchRow(DB_FE TCHMODE_ASSOC);
}
I get this in my browser:
Execute error DB Error: syntax error please contact admin.
Now, if the sql was broken, I could understand the error, but I would
kind of have expected the prepare to fail.
This works OK if I leave off everything after id = $.
Any ideas?
Thanks in advance,
Randy
Comment