【发布时间】:2010-11-01 14:01:12
【问题描述】:
我试图在 php 中扩展 mysqli 类以创建一个包装类。我希望这个类管理多个连接。我目前处于非常早期的阶段并且遇到了一个问题:
身份验证连接编号:1 1045:用户'rootty'@'localhost'的访问被拒绝(使用密码:是) 分段错误
似乎当第二个连接出错时会创建分段错误,但是连接一个错误正确..
<?php
class mysqli_ls extends mysqli
{
private $link = array();
private $link_no = 0;
/* ************************************************************ */
public function __construct()
{
}
/* ************************************************************ */
public function open($host='', $user='', $pass='', $port='3306', $database='')
{
if ( empty($host) || empty($user) || empty($pass) || empty($database) )
{
$this->error[] = "Missing required connection variables";
return false;
}
$this->link_no++;
@$this->link[ $linkno ] = $this->connect($host, $user, $pass, $database, $port);
if ($this->connect_errno)
{
$this->error[] = $this->connect_errno .':'. $this->connect_error;
return false;
}
return $this->link_no;
}
######测试脚本
#!/usr/bin/php
<?php
require_once('mysqli.class.php');
$_mysqli = new mysqli_ls;
$_auth = $_mysqli->open('localhost','root','xx','3306','auth');
if ($_auth === false) print $_mysqli->get_last_error() ."\n";
else print 'Auth Connected no: '. $_auth ."\n";
$_trak = $_mysqli->open('localhost','root','sxx','3306','wlr_tracker');
if ($_trak === false) print $_mysqli->get_last_error() ."\n";
else print 'Trak Connected no: '. $_trak ."\n";
【问题讨论】:
-
A Segfault mysqli 使用的 C/C++ 代码中很可能存在错误。我无法在 5.3.3 中重现此问题。
标签: php class connection mysqli segmentation-fault