PDA

View Full Version : MySQL PHP API mysqli error



whereisb
05-15-2009, 10:15 AM
this code:

$conn = new mysqli ("localhost", $user, $pwd, $dbname);


produces the following error:

Fatal error: Cannot instantiate non-existent class: mysqli in /home/websiteX/public_html/subX/includes/connection.inc.php on line 21

What am I doing wrong? (i.e., How do I make it run?)

Thanks, John Brown

shadmego
05-15-2009, 10:18 AM
use this:



$conn = mysqli_connect("localhost", $user, $pwd, $dbname);


The reason you got that error is because mysqli is not a class name ... it's the name of a set of funtions, so you don't call them as if you were calling a class (with the new keyword).

whereisb
05-15-2009, 11:22 AM
I changed my code to:


$conn = mysqli_connect("localhost", $user, $pwd, $dbname);

Now I get the following error:


Fatal error: Call to undefined function: mysqli_connect() in /home/whereisb/public_html/ww/includes/connection.inc.php on line 21

What am I missing?

Thanks, John Brown

shadmego
05-15-2009, 11:28 AM
what version of php are you using on your server? the mysqli function is only available in php version 5+. If you are running anything below 5, you will have to use mysql instead of mysqli.

If you are running below 5 I would also encourage you to start using 5 instead.

~regards

P.S. According to this link (http://www.phpbuilder.com/manual/en/function.mysqli-connect.php), you can also use mysqli as you originally posted, though I've never ever seen it used this way. I apologize for the confusion my previous post may have caused.

whereisb
05-15-2009, 11:39 AM
Perhaps I should have mentioned that I am successfully using the original code on another server.

I am moving a website to hostmonster servers and that is where I am getting the error. Your comments will help me find the problem on hostmonster.

Thanks for your help. John Brown

whereisb
05-15-2009, 03:26 PM
Thanks to this forum, I found the solution and got the code to work. The solution was to upgrade the PHP to ver 5, then it worked. Hostmaster has the option to easily specify which version of PHP. It seems odd that they provide as default the lowest version.
Thanks to shadmego.

John Brown