Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/270.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php mysqli超全局连接对象,一次有多个连接_Php_Mysqli - Fatal编程技术网

Php mysqli超全局连接对象,一次有多个连接

Php mysqli超全局连接对象,一次有多个连接,php,mysqli,Php,Mysqli,我一直在使用此解决方案获得超级全局mysqli连接: class blst_db { private static $mysqli; private function __construct(){} //no instantiation static function cxn() { if( !self::$mysqli ) { self::$mysqli = new mysqli(...); } return self::$mysqli; }

我一直在使用此解决方案获得超级全局mysqli连接:

class blst_db {
private static $mysqli;
private function __construct(){} //no instantiation

static function cxn() {
    if( !self::$mysqli ) {
        self::$mysqli = new mysqli(...);
    }
    return self::$mysqli;
 }        
//使用 blst_db::cxn()->准备(

我找到了它,它工作得很好,但是当我试图同时获得两个连接时,我得到了一个错误。例如,我有一个类运行这样一个查询:

$query_points = blst_db::cnx()->prepare('SELECT point_id FROM points WHERE id=?');
$query_points->bind_param('i', $this->id);
$query_points->bind_result($point_id);
$query_points->execute();
while ($query_points->fetch()) {
     $point = new blst_point ($point_id);
     $points[] = $point;  }
我在while语句中创建了各种对象,对象构造函数每次运行另一个查询(另一个$query=blst_db::cnx->prepare(…)如果我更改代码,在while语句中创建一个数组,然后在关闭该查询后,在foreach中创建所有对象,我没有问题,但我不喜欢这种解决方案


谢谢!

我发现了问题。我必须存储第一次查询的结果,以便在其中运行其余查询。我刚刚添加:

$query_points->store_result();
在execute()调用之后,在关闭$query\u点之前,我创建了一个free\u result(),它工作得非常好。 我找到了解决办法