So I try to run the following code on a shared hosting.
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
echo phpversion();
$mySqlServername = "localhost";
$mySqlUsername = "auser";
$mySqlPassword = "apassword";
$mySqlDbname = "adatabase";
//Create Connection
$conn = new mysqli($mySqlServername, $mySqlUsername, $mySqlPassword, $mySqlDbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Set charset to UTF-8
if (!$conn->set_charset("utf8")) {
printf("Error loading character set utf8: %s\n", $conn->error);
exit();
}
if ($currConn = $conn->prepare("SELECT DISTINCT subject FROM topics")) {
$currConn->execute();
$result = $currConn->get_result();
$currConn->close();
/*for ($i = 0; $i < $result->num_rows; $i++) {
$array[$i] = $result->fetch_row()[0];
}*/
var_dump($result->fetch_row());
} else {
die("Statement could not be prepared!");
}
$conn->close();
On there it produces the following output:
5.6.17
Fatal error: Call to undefined methodmysqli_stmt::get_result()
in/home/user/public_html/beta/test_mysqli_asmallorange.php
on line 29
Where on my local machine it produces the following expectet Output:
5.6.11-1ubuntu3.1array(1) { [0]=> string(8) "Religion" }
And as far as I understand the problem is that mysqli is not using mysqlnd. Wich I tested with phpinfo()
and I took a picture of what I think is the relevent section:
Configure Command:
'./configure' '--exec-prefix=/usr/local/php56' '--prefix=/usr/local/php56' '--with-config-file-scan-dir=/usr/local/php56/conf.d' '--with-libdir=lib64' '--enable-bcmath' '--enable-calendar' '--enable-exif' '--enable-ftp' '--enable-gd-native-ttf' '--enable-libxml' '--enable-mbstring' '--enable-pdo' '--enable-soap' '--enable-sockets' '--enable-wddx' '--enable-zip' '--with-apxs2=/usr/local/apache/bin/apxs' '--with-bz2' '--with-curl=/opt/curlssl/' '--with-freetype-dir=/usr' '--with-gd' '--with-gettext' '--with-imap-ssl=/usr' '--with-imap=/opt/php_with_imap_client/' '--with-jpeg-dir=/usr' '--with-kerberos' '--with-libexpat-dir=/usr' '--with-mcrypt=/opt/libmcrypt/' '--with-mhash=/opt/mhash/' '--with-mysql-sock=/var/lib/mysql/mysql.sock' '--with-mysql=/usr' '--with-mysqli=/usr/bin/mysql_config' '--with-openssl-dir=/usr' '--with-openssl=/usr' '--with-pcre-regex' '--with-pdo-mysql=shared' '--with-pdo-sqlite=shared,/usr' '--with-pdo-pgsql=shared' '--with-pgsql=shared,/usr/lib64/pgsql' '--with-pic' '--with-png-dir=/usr' '--with-pspell' '--with-snmp' '--with-tidy' '--with-libxml-dir=/opt/xml2/' '--with-xmlrpc' '--with-xpm-dir=/usr' '--with-xsl=/opt/xslt/' '--with-zlib' '--with-zlib-dir=/usr' '--enable-mysqlnd' '--enable-intl'
There you can clearly see that mysqli uses 5.5.47-MariaDB and not mysqlnd wich is clearly installed. Same section on my local machine here.
I can choose diffrent PHP versions, but since none of them work like I expect I settled for 5.6.17
which is the most recent version I can choose.
So is there a way to change this with just the php.ini or not? And even if it is possible is it a good idea?