Mysqli_connect parse error

I am running XAMPP for Windows 8.1.12 under windows 11.
Just trying to do a first connection.
I have used phpmyadmin to create a database.
I run the script below and I get this result on my browser
Parse error: syntax error, unexpected single-quoted string “root”, expecting “)” in C:\xampp\htdocs\Test.php on line 12

Line 12 is $mysqli = mysqli_connect(‘localhost’, ‘root’, ‘’, ‘ftest’);

and the xampp FAQ says “The MySQL administrator (root) has no password.”


echo "Hello";

/* You should enable error reporting for mysqli before attempting to make a connection */

$mysqli = mysqli_connect('localhost', 'root', '', 'ftest');
if (mysqli_connect_errno()) {
    throw new RuntimeException('mysqli connection error: ' . mysqli_connect_error());

/* Set the desired charset after establishing a connection */
mysqli_set_charset($mysqli, 'utf8mb4');

printf("Success... %s\n", mysqli_get_host_info($mysqli));	

The posted code doesn’t produce a php syntax error (just tested.) This type of problem is usually the result of copy/pasting code and the quotes present are smart/curly quotes, which when posted in a forum get converted to straight quotes, which then work.

Some points for the posted code -

  1. If you are just starting out, forget the you ever saw the mysqli extension. Instead, learn and use the much simpler and more modern PDO extension.
  2. Php’s error_reporting should always be set to E_ALL and it should be set in the php.ini on your system.
  3. When learning, developing and debugging code/query(ies), display_errors should be set to ON, again in the php.ini on your system, so that you get immediate feedback as to any problems.
  4. When you put your code onto a live/public server, display_errors should be set to OFF and log_errors should be set to ON, so that all the reported php errors will get logged instead of displayed.
  5. Regardless if which database extension you use, you should use exceptions for database statement errors and in most cases simply let php catch and handle any exception, requiring no code in your application, where php will use its error related settings (see items #2 - #4 on this list) to control what happens with the actual error information (database statement errors will ‘automatically’ get displayed/logged the same as php errors.) The exception to this rule is for user recoverable errors, such as when inserting/updating duplicate or out of range user submitted data. In this case, your code should catch the database exception, test if the error number is for something that your code is designed to handle, and setup a meaningful message letting the user know what was wrong with the data that they submitted. For all other error numbers, just re-throw the exception and let php handle it.
1 Like

Thank you. You were right - copy and paste error.
Notepad++ was in UTF8 mode. Changing to Ansi showed the weird characters.
Re typed by hand and it all worked. - Greatly appreciated.

Sponsor our Newsletter | Privacy Policy | Terms of Service