Hi
I have been struggling with a script written by Kevin Yank on Building A Database Driven Web Site Using PHP and MySQL. It is the Jokes example from the http://dev.mysql.com/tech-resources/articles/ddws/26.html . I have Apache 2.4.7 PHP 5.5.6 and MySQL 5.6.14 installed on a Linux OS at home. I have been trying to get the script to run and access the ‘jokes’ database from the script but it refuses to get a connection. I have upgraded to mysqli from mysql in the code and I include the affected area here–>
// Connect to the database server
$dbcnx = mysqli::_construct(
'http://localhost:3306', 'root', '123456', 'jokes');
if (!$dbcnx) {
echo( "<P>Unable to connect to the " .
"database server at this time.</P>" );
exit();
}
<--
I have the firewall allowing port 3306 through. I have proven that PHP, MySQL and httpd are all running. (I am using Fedora 17 OS). It keeps tripping out with the “Unable to connect…” error message. I have absolutely no idea of what to do next. Port 3306 is listening as I have checked with ‘netstat -a’. I have tried with the alias for ‘mysqli::_construct’ which I believe is ‘mysqli_connect’, but no luck.
I have installed the safe mysql by running ‘/usr/bin/mysql_secure_installation’. I can login through a terminal, without problems. Any help would be greatly appreciated…
Robert
Hi Mittineague
I am glad to be a member of your forum and thank you for the welcome. I got to connect finally using your code and my parameters. Thank you so much. It did not show the ‘host_info’ however. Is there any examples you know of that shows the syntax for the various ‘mysqli’ functions. I struggle with the syntax and a good tutorial or well documented example(s) would be such a great help.
My specific code follows—>
$mysqli = new mysqli(“localhost”, “autorunner”, “123456”, “jokes”);
<----
The reply (which shows up on the html page) when running it is as follows —>
host_info); /* close connection */ $mysqli->close(); ?>
<—
It appears to not grab the host information. I looked through phpMyAdmin and I see the connection is being made but no ‘host info’ is returned.
Cheers…
Robert
Hmmm.
host_info); /* close connection */ $mysqli->close(); ?>
is the ending text of the file. I don’t know what happened there.
While testing code (but not on live code), it’s a good idea to have this at the beginning of the file
<?php
error_reporting(E_ALL);
ini_set('display_errors', true);
// rest of the file vvv
You can download the PHP documentation for offline use http://www.php.net/download-docs.php
But the online documentation has the added benefit that there are often “user contributed notes” that might have just the example you’re looking for http://www.php.net/manual/en/