Please help if you can - stumped!
Got to the stage (p.117) of connecting to MySQL with PHP.
Accessing the php file on localhost which contains:
$link = mysqli_connect('localhost', 'root', 'password');
$output = 'Unable to connect to the database server.';
if (!mysqli_set_charset($link, 'utf8'))
$output = 'Unable to set database connection encoding.';
if (!mysqli_select_db($link, 'ijdb'))
$output = 'Unable to locate the joke database.';
$output = 'Database connection established.';
i.e. http://localhost/connect/index.php or http://localhost/connect
produces a 500 server error.
This seems odd, as I have successfuly accessed and run other php filesin previous exercises in the book. The only difference with this one is that it references mysqli.
I can successfully connect to mysql via the command prompt, so that appears to working.
I'm having this same issue, although I am not getting the 500 server error.
I am given the $output value of !$link ('Unable to connect to the database server.') if I try to access localhost/connect/. Strangely enough, when I remove the 'root' parameter I am given the $output value of !mysqli_select_db($link, 'ijdb')...'Unable to locate the joke database.'
Seems like chapter 4 of this book gives lots of folks problems. I'm guessing robertmarks probably found whatever his problem was - probably not the database if he was getting 500 errors from Apache.
nick, it sounds like your login credentials for your database (in index.php) are not correct, which is why you were getting the 'cannot connect' error message. The 'root' parameter you mention is the user account for accessing the database. If you 'removed' that, then I'd guess values are getting substituted to where mysqli_connect is getting some weird (and incorrect) string for the database name, and as a result 'cannot locate' it.
This topic is now closed. New replies are no longer allowed.