Jump to content
Larry Ullman's Book Forums

Recommended Posts

Hi Larry

"You should not end your queries with a semicolon in PHP,  as you do when using the mysqli client........." 

Undoubtedly I'm being really fick, but I'm struggling with the above?  I've searched for examples of this advice in script 9.3, but to no avail.

It's from the top TIP in the second column, p280.

Any help much appreciated.

Warm Regards

 

 

Link to comment
Share on other sites

Hopefully there aren't any examples of queries in PHP scripts having terminating semicolons! Or, put another way, in MySQL you need to use a semicolon to indicate the end of the query to be executed. In PHP you don't need to do this. 

Link to comment
Share on other sites

Thanks Larry

Lock down fickness.  It's a thing!

 

....so, as an example,  using script 9.7,   p293 (in my book),  line 43.....

             $q = "SELECT user_id FROM users WHERE (email='$e' AND pass=SHA1('$p')) ";

Are you saying that this could/should be written as..

            $q = "SELECT user_id FROM users WHERE (email='$e' AND pass=SHA1('$p')) "            -          without the ending semicolon?

 

 

Thanks again.

                              

 

 

Link to comment
Share on other sites

Ah, no, not exactly. The semicolon there terminates the line of PHP code. What I'm saying is you don't need to do this:

 $q = "SELECT user_id FROM users WHERE (email='$e' AND pass=SHA1('$p'));";

so that the query being run from the PHP script becomes

SELECT user_id FROM users WHERE (email='$e' AND pass=SHA1('$p'));
Link to comment
Share on other sites

 Share

×
×
  • Create New...