简体   繁体   English

为什么当MySQL驱动程序执行查询时,Codeigniters msqli驱动程序返回null作为查询结果?

[英]Why does Codeigniters msqli driver return null as a query result while the mysql driver executes the query just fine?

I'm on a managed Server from 1and1 and i'm using stored procedures in my current Project. 我在1and1的托管服务器上,并且在当前项目中使用存储过程。 For that I have to use mysqli as the database driver. 为此,我必须使用mysqli作为数据库驱动程序。

1and1 wants to setup a socket for database connections depending wether i use mysql (which is /tmp/mysql5.sock) or mysqli (/tmp/mysqld.sock). 1and1希望根据我使用mysql(/tmp/mysql5.sock)或mysqli(/tmp/mysqld.sock)设置数据库连接套接字。

When I setup my database.php to use the mysqli driver and the hostname with the respective socket my queries will fail and i get the following response as result object. 当我将database.php设置为使用mysqli驱动程序和带有相应套接字的主机名时,我的查询将失败,并且我将以下响应作为结果对象。

object(CI_DB_mysqli_result)#17 (7) { object(CI_DB_mysqli_result)#17(7){

["conn_id"]=> bool(false) [“ conn_id”] => bool(false)

["result_id"]=> NULL [“ result_id”] => NULL

["result_array"]=> array(0) {} [“ result_array”] =>数组(0){}

["result_object"]=> array(0) { } [“ result_object”] =>数组(0){}

["current_row"]=> int(0) [“ current_row”] => int(0)

["num_rows"]=>NULL [“ num_rows”] => NULL

["row_data"]=>NULL [“ row_data”] => NULL

} }

I've checked my phpinfo and it tells me, that mysqli is loaded and its parameter "default_socket" is "/tmp/mysqld.sock". 我检查了我的phpinfo,它告诉我mysqli已加载,其参数“ default_socket”为“ /tmp/mysqld.sock”。

what am i missing? 我想念什么?

The ["conn_id"]=> bool(false) thing seems like there is no database connection at all, am I right? ["conn_id"]=> bool(false)似乎根本没有数据库连接,对吗? How do i get mysqli connections to work with 1and1 in Codeigniter? 如何在Codeigniter中使mysqli连接与1and1一起使用?

@edit: this is one of the queries i try to perform: @edit:这是我尝试执行的查询之一:

function getStreetByReference ( $plz)
{

    $query = $this->db->query("SELECT strasse from dwh_strassen WHERE dwh_strassen.PLZ =  '$plz' GROUP BY dwh_strassen.strasse");
    $temp_result = array();
    foreach ( $query->result_array() as $row )
    {
         $temp_result [] = $row;
    }
    return $temp_result;
}

Ok, long story short, the mysqli Driver from codeigniter does not support working with sockets. 好的,长话短说,来自codeigniter的mysqli驱动程序不支持使用套接字。 Or at least i could not find the right setting to do so. 至少我找不到合适的设置。

I've added the parameter in the driver class and now it works. 我已经在驱动程序类中添加了参数,现在可以使用了。

in /System/database/drivers/mysqli_driver.php 在/System/database/drivers/mysqli_driver.php中

if ($this->port != '')
        {
            return @mysqli_connect($this->hostname, $this->username, $this->password, $this->database, $this->port, $this->socket); // $this->socket is new, i've added the same variable in my database.php
        }
        else
        {
            return @mysqli_connect($this->hostname, $this->username, $this->password, $this->database);
        }

and in /application/config/database.php 并在/application/config/database.php中

$db['live']['socket'] = "/tmp/mysql5.sock";

Thats propably all there is to it. 多数民众赞成在这里。 I've done some testing and even if phpinfo tells me, that the default_socket for mysqli is not the mysql5.sock, it works just fine. 我已经做了一些测试,即使phpinfo告诉我,mysqli的default_socket不是mysql5.sock,它也可以正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM