close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

MySQLi apostrophe inconsistency

Thread began 1/21/2022 1:00 pm by yogastudents362523 | Last modified 1/21/2022 2:43 pm by Ray Borduin | 170 views | 2 replies |

yogastudents362523

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

Sign in to reply to this post

Ray BorduinWebAssist

Single and double quotes are interchangeable in php.

In MySQL you need single quotes usually for strings.

The slanted quotes in mySQL are encapsulation characters for columns that have restricted words in them... like First and Last in yours since those are also the name of mySQL functions.

Sign in to reply to this post
Did this help? Tips are appreciated...

yogastudents362523

Thank you.
That kind of makes sense ... ... ... except that ... ... ... it was the quotes around SecurityAssistID that I changed.
I didn't touch the others at all.
So I shall just assume that when there are 'function words' or 'reserved terms' of any kind in a query, then it makes a difference to all quotes used in that query. And I shall systematically examine and if necessary change them all.

It would of course be far better to avoid those function words, which I guess means becoming more invinventive in my choice of names.

Thank you again.

Sign in to reply to this post

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...