February 8th, 2013, 10:17 PM
Php not recognizing mysqli_connect
I'm having a frustrating time trying to find out why php is not connecting to MySQL. Here's what I did;
* installed Apache Web server on a laptop. This is up and running.
* Installed php on the laptop and this is running and configured to Apache. I can bring up a dev website running php.
* installed MySQL database and created tables.
Now I'm trying to connect php to the database and php does not seem to be recognizing mysqli_connect.
I have the following within a php file.
$link = mysql_connect('localhost', 'root', 'password');
If I view the source code after the page comes up it seems as if the webpage hits this piece of code and stops creating the rest of the page.
You help is appreciated.
February 8th, 2013, 10:58 PM
are you talking about mysqli_connect (with an "i") or mysql_connect? Those are two completely different extensions. The first one is the current PHP extension for MySQL, the last one is obsolete.
In any case:
Turn on your error messages with
or in the php.ini
And then check the exact error message. Maybe you don't have the extension activated.
February 9th, 2013, 06:31 AM
I tried both mysqli_connect and mysql_connect. The error_reporting in the php.ini file was set tol
error_reporting = E_ALL;
I tried setting it to
However after I did that I stopped and tried to start apache. Apache wouldn't start as it couldn't parse error_reporting(-1); I do suspect as you indicate though that the mysqli_connect is not being recognized. How do I fix that?
February 9th, 2013, 09:25 AM
In your php.ini file, look for the extension line that enables the mysql or mysqli extensions and uncomment it (if it's commented out). I don't recall exactly what it looks like, but it will say something like "extension=mysqli.dll".
Setting error_reporting alone isn't always enough to see error messages. You also need to enable display_errors. Entry #30 in the FAQ goes into depth on how to do this.
The error_reporting(-1) syntax would be something you would use in your actual php file, rather than in your php.ini file.
February 9th, 2013, 09:37 AM