Page 1 of 1

Support for mysqli?

Posted: Mon Aug 14, 2017 1:48 pm
by alm
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

Re: Support for mysqli?

Posted: Tue Aug 15, 2017 3:41 pm
by SonicUser
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.

Re: Support for mysqli?

Posted: Tue Aug 15, 2017 4:30 pm
by joemuller
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

Re: Support for mysqli?

Posted: Tue Aug 15, 2017 4:36 pm
by alm
Thank you Joe.

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

-Al