I am using the mysqli db class found at github
my query looks like
$db->query('
SELECT
memberID,zoneCode,state,zone,countyName,
CONCAT(state,\'Z\',zone) as fullZoneCode
FROM members_zonesToWatch
LEFT JOIN (
SELECT state,zone,countyName
FROM countyPublicForcastZoneCorrelation
) as zones
ON zoneCode = CONCAT(state,\'Z\',zone)');
The issue im getting is
Fatal error: Problem preparing query
(SELECT
memberID,zoneCode,state,zone,countyName,
CONCAT(state,'Z',zone) as fullZoneCode
FROM members_zonesToWatch
LEFT JOIN (
SELECT state,zone,countyName
FROM countyPublicForcastZoneCorrelation
) as zones
ON zoneCode = CONCAT(state,'Z',zone))
You have an error in your SQL syntax; check the manual that corresponds to your
MySQL server version for the right syntax to use near
''Z',zone) as fullZoneCode FROM members_zonesToWatch LEFT' at line 1
This query as it is works in mysql workbench just fine. What is wrong with it using the mysqli class?
After testing on your case, the problem is the
'Z'and$db->queryIt is because the
MysqliDBinternally usesmysqliandmysqlithrows the exception whenprepareyour statement (from the debugger, it seems the quote'turns to').Instead,
MysqliDBproviderawQueryfor cases like yours. So use the below :Reference: PHP-MySQLi-Database-Class / MysqliDb.php;