2010-11-01 41 views
0

即时尝试扩展PHP中的mysqli类以创建一个包装类。我想这个类来管理多个连接..我目前正处在一个非常早期的阶段,并已触及一个问题:PHP mysqli分段错误

验证没有连接:1 1045:拒绝访问用户rootty'@“localhost”的(使用密码:YES) 分段故障

看来当第二连接具有分段错误创建但是连接正确一个错误的错误..

<?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"; 
+0

Segfault很可能是mysqli使用的C/C++代码中的一个错误。我无法在5.3.3中重现此问题。 – netcoder 2010-11-01 14:41:34

回答

0

我会把这个报告给PHP/mysqli开发者。脚本语言segfaulting很可能是一个你无法修复的内部错误 - 尽管可能创建一个解决方法,正确的方法是使它在C代码中得到修复。