Support for mysqli?

Web hosting discussion, programming, and shared and dedicated servers.
4 posts Page 1 of 1
by alm » Mon Aug 14, 2017 1:48 pm
I cannot connect to my database using this very simple mysqli. script:

<?php
$servername = "i put my server name here";
$username = "i put my admin user name here";
$password = "i put my admin password here";

// Create connection
$conn = new mysqli($servername, $username, $password);

// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
?>

When I run this, I get the following error message: "<?php
$servername = "alm-0.db.sonic.net";
$username = "alm_0-admin";
$password = "408aba90";

// Create connection
$conn = new mysqli($servername, $username, $password);

// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
?>

When I run this script I get the following error: "Fatal error: Cannot instantiate non-existent class: mysqli in /nfs/www/WWW_pages/alm/yiddish/connect.php on line 7".

Line 7 is this: $conn = new mysqli($servername, $username, $password);

Do I need to do something to get mysqli running on my site? Is the problem something else?

Thanks in advance,
Al
by SonicUser » Tue Aug 15, 2017 3:41 pm
Which version of php are you using? If you are using an older version it may not have mysqli and only the (deprecated) mysql extension. The following link shows how to use php 5.5 or you could use the deprected mysql extension to connect to the database.

https://wiki.sonic.net/wiki/Php5

P.S. Hopefully those weren't your real credentials that you posted to a public forum.
by joemuller » Tue Aug 15, 2017 4:30 pm
When I run this script I get the following error: "Fatal error: Cannot instantiate non-existent class: mysqli in /nfs/www/WWW_pages/alm/yiddish/connect.php on line 7".


You'll need to make sure to turn on PHP 5.2 or later for your site. (the default PHP version is 4.4.9) You'll want to create an empty file in /home/WWW_pages/alm/yiddish/ named .htaccess (the leading dot is required) and put the following code inside: (see SonicWiki - PHP5

Code: Select all

Action php-cgi /cgi-bin/php53
AddHandler php-cgi .php


Also, I recommend changing the password for your database in your original post - this can be done in Member Tools under Databases -> Manage [database name here] -> Change Password. Keep a copy in a safe place and make sure to update your code/site to use the new credentials.

-- Joe
I'm a proud employee of Sonic.net! :-)
by alm » Tue Aug 15, 2017 4:36 pm
Thank you Joe.

This worked. With the addition of the .htaccess file, 'm running php 5.5.38 now, and mysqli is working.

-Al
4 posts Page 1 of 1

Who is online

In total there are 3 users online :: 0 registered, 0 hidden and 3 guests (based on users active over the past 5 minutes)
Most users ever online was 422 on Sat May 26, 2012 5:28 am

Users browsing this forum: No registered users and 3 guests