A Little Noise

October 1, 2012

Connection Conundrum

Filed under: MySQL Gotchas,PHP Gotchas — snoyes @ 12:13 pm

Define a user like this:

GRANT ALL ON *.* TO 'myuser'@'localhost' IDENTIFIED BY 'super$ecret';

Then try a PHP script like this:

<?php
mysqli_connect("localhost", "myuser", "super$ecret");
?>

What happens and why? How could you avoid it?

And for glory, what single line could you add that would prevent the error, without making any changes to the mysqli_connect line?

2 Comments »

  1. $ecret = ‘$ecret’;

    Comment by Justin Swanhart — October 1, 2012 @ 12:59 pm

  2. Which is why I quote PHP strings with single quotes, not double quotes.

    Comment by Shlomi Noach — October 2, 2012 @ 12:35 am

RSS feed for comments on this post. TrackBack URL

Leave a comment

Powered by WordPress