Good day people,
I’m a noobie with regard to PHP, which I pick up recently. On page 120-121 of the book, I encountered an error although I followed the codes provided there.
<?php
$link = mysql_connect(‘localhost’, ‘root’);
if (!$link)
{
$output = ‘Unable to connect to the database server.’;
include ‘output.html.php’;
exit();
}
if(!mysqli_set_charset($link, ‘utf8’))
{
$output = ‘Unable to set database connection encoding.’;
include ‘output.html.php’;
exit();
}
if(!mysqli_select_db($link, ‘ijdb’))
{
$ouput = ‘unable to locate the joke database.’;
include ‘output.html.php’;
exit();
}
$output = ‘Database connection established.’;
include ‘output.html.php’;
?>
I did not set any password on MySQL, hence removing the password allowed me to enable the DB connection. However, coming to the second part, I was not able to set the database connection encoding.
This was the error message I saw:
Warning: mysqli_set_charset() expects parameter 1 to be mysqli, resource given in C:\xampp\htdocs\Eugene\MySQL1\index.php on line 10
Unable to set database connection encoding.
Any reason why?
Thanks!