MySQLi apostrophe inconsistency
Hello,
I generated this query which worked just fine:
<?php
$rsAllPresenterData = new WA_MySQLi_RS("rsAllPresenterData",$mysqli_navayogimarga,1);
$rsAllPresenterData->setQuery("SELECT * FROM presenter_data WHERE ID = ?");
$rsAllPresenterData->bindParam("i", "".(isset($_SESSION['SecurityAssist_ID'])?$_SESSION['SecurityAssist_ID']:"") ."", "-1"); //colname
$rsAllPresenterData->execute();
?>
Please notice the single quotes around SecurityAssistID.
I then generated this query, which simply would not work:
<?php
$rsCreateCode = new WA_MySQLi_RS("rsCreateCode",$mysqli_navayogimarga,0);
$rsCreateCode->setQuery("SELECT ID, `Last`, `First` FROM presenter_data WHERE ID = ?");
$rsCreateCode->bindParam("i", "".(isset($_SESSION['SecurityAssist_ID'])?$_SESSION['SecurityAssist_ID']:"") ."", "-1"); //colname
$rsCreateCode->execute();
?>
Again notice the single quotes.
And then I suddenly remembered that MySQLi has on a previous occasion generated an SQL query in which it had used straight quotes instead of backquotes `, in a MySQL query upon the database.
So I tried substituting backquotes for those single quotes and that still did not work.
HOWEVER, I eventually substituted double quotes to give me:
<?php
$rsCreateCode = new WA_MySQLi_RS("rsCreateCode",$mysqli_navayogimarga,0);
$rsCreateCode->setQuery("SELECT ID, `Last`, `First` FROM presenter_data WHERE ID = ?");
$rsCreateCode->bindParam("i", "".(isset($_SESSION["SecurityAssist_ID"])?$_SESSION["SecurityAssist_ID"]:"") ."", "-1"); //colname
$rsCreateCode->execute();
?>
and that is now working like a charm, and allowing me to proceed.
Is there some logical rhyme and reason why MySQLi dodges around amongst these different quotes, because I then experimented with all qypes of quotes in both the direct MySQL queries and within the MySQLi statements, and I can't make a bit of sense of the variability.
It is a little disturbing, when you don't have that much confidence in your coding abilities, to be thrown off course by such a little eventuality, and it would help a lot if I knew that the difficulty might be in these generated scripts, because I spent an absolute age trying to figure out what I was doing wrong, only to have everything working when I changed those quotes. So it would be kind of nice to know what's up, if you are aware of why.
Thank you for your kindness,
KAB