有没有办法改变mysqli使用的库只用php.ini?

时间:2016-01-19 16:14:20

标签: php mysql mysqli mysqlnd

所以我尝试在共享主机上运行以下代码。

<?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();

在那里它产生以下输出:

  

5.6.17
  致命错误:在第29行的mysqli_stmt::get_result()中调用未定义的方法/home/user/public_html/beta/test_mysqli_asmallorange.php

在我的本地计算机上,它会产生以下预期输出:

  

5.6.11-1ubuntu3.1array(1){[0] =&gt; string(8)“Religion”}

据我所知,问题是mysqli没有使用mysqlnd。我用phpinfo()进行了测试,并拍了一张我认为是相关部分的照片:

enter image description here

配置命令:

  

'./ 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 / '' - 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'

在那里你可以清楚地看到mysqli使用的是5.5.47-MariaDB,而不是明确安装的mysql。我本地计算机here上的相同部分。

我可以选择不同的PHP版本,但因为它们都没有像我预期的那样工作5.6.17,这是我可以选择的最新版本。

那么有没有办法只用php.ini来改变它?即使它有可能是一个好主意吗?

1 个答案:

答案 0 :(得分:1)

据我所知,您必须决定mysqli在编译时使用的客户端库,并且在运行时无法更改。有关详细信息,请参阅mysqli's documentation on choosing a client library

  

mysqli,PDO_MySQL和mysql PHP扩展是轻量级的   在C客户端库之上的包装器。扩展可以使用   mysqlnd库或libmysqlclient库。选择一个图书馆   是一个编译时决定。

虽然上面的引用没有明确提到mariadb,但是可以安全地假设这也是mariadb的情况。由于您的实时代码位于共享托管环境中,因此只有提供程序可以为您重新编译php。但是,我认为他们不会只为一个客户(你)这样做。我会检查是否可以更改我的代码并使其在没有get_result()方法的情况下工作。