出现此句的中文意思为:命令不同步,你不能运行此命令.出现此问题是在同一个mysqli连接中同时调用了二次MySQL的过程,对于此问题,在网上查找了相当的资料,有的说要通过mysqli::multi_query()方法来分别执行不同的过程,但是通过此方法经研究后发现其实不能解决问题.并且,mysqli::multi_query()对于存贮过程的调用显然没有mysqli_stmt容易和方便.
之后,终于发现了mysqli::next_result()的方法:(此前一直以为是获取mysqli的下一个结果集的方法),但查看了手册才知道其原意为:
Prepare next result from multi_query 为多重查询准备下一个结果集,
好象找到解决问题的方法了:
if ($link->next_result()){
//执行新的mysqli查询
}
代码修改如下:
<?php
class destroyobj3{
private $link;
private $id;
private $name;
private $pwd;
private $ip;
private $mail;
private $mobile;
private $phone;
public function __construct($pid){
if(!is_integer($pid)){
throw new Exception("Parameter must be integer");
exit();
}
$this->id=$pid;
$this->link=new mysqli('localhost','root','750901lanpioneer@!','test');
$this->link->query("set names 'utf8'");
if($stmt=$this->link->prepare("call UP_Get_tuser(?)")){
$stmt->bind_param("i",$this->id);
$stmt->execute();
$stmt->bind_result($this->id,$this->name,$this->pwd,$this->ip,$this->mail,$this->mobile,$this->phone);
$stmt->fetch();
$stmt->free_result();
$stmt->close();
}
}
public function getName(){
return $this->name;
}
public function setName($pname){
$this->name=$pname;
}
public function getPwd(){
return $this->pwd;
}
public function setPwd($pwd){
$this->pwd=md5($pwd);
}
public function getMail(){
return $this->mail;
}
public function setMail($mail){
$this->mail=$mail;
}
public function getMobile(){
return $this->mobile;
}
public function setMobile($mobile){
$this->mobile=$mobile;
}
public function getPhone(){
return $this->phone;
}
public function setPhone($phone){
$this->phone=$phone;
}
public function __destruct(){
//注意:此句相当重要:
if($this->link->next_result()){
$this->link->query("set names 'utf8'") or die($this->link->error);
$stmt=$this->link->prepare("call UP_Update_tuser(?,?,?,?,?,?,?)") or die ("error".$this->link->error);
$stmt->bind_param("issssss",$this->id,$this->name,$this->pwd,$this->ip,$this->mail,$this->mobile,$this->phone);
$stmt->execute();
$stmt->fetch();
$stmt->free_result();
$stmt->close();
}
$this->link->close();
}
}
?>
class destroyobj3{
private $link;
private $id;
private $name;
private $pwd;
private $ip;
private $mail;
private $mobile;
private $phone;
public function __construct($pid){
if(!is_integer($pid)){
throw new Exception("Parameter must be integer");
exit();
}
$this->id=$pid;
$this->link=new mysqli('localhost','root','750901lanpioneer@!','test');
$this->link->query("set names 'utf8'");
if($stmt=$this->link->prepare("call UP_Get_tuser(?)")){
$stmt->bind_param("i",$this->id);
$stmt->execute();
$stmt->bind_result($this->id,$this->name,$this->pwd,$this->ip,$this->mail,$this->mobile,$this->phone);
$stmt->fetch();
$stmt->free_result();
$stmt->close();
}
}
public function getName(){
return $this->name;
}
public function setName($pname){
$this->name=$pname;
}
public function getPwd(){
return $this->pwd;
}
public function setPwd($pwd){
$this->pwd=md5($pwd);
}
public function getMail(){
return $this->mail;
}
public function setMail($mail){
$this->mail=$mail;
}
public function getMobile(){
return $this->mobile;
}
public function setMobile($mobile){
$this->mobile=$mobile;
}
public function getPhone(){
return $this->phone;
}
public function setPhone($phone){
$this->phone=$phone;
}
public function __destruct(){
//注意:此句相当重要:
if($this->link->next_result()){
$this->link->query("set names 'utf8'") or die($this->link->error);
$stmt=$this->link->prepare("call UP_Update_tuser(?,?,?,?,?,?,?)") or die ("error".$this->link->error);
$stmt->bind_param("issssss",$this->id,$this->name,$this->pwd,$this->ip,$this->mail,$this->mobile,$this->phone);
$stmt->execute();
$stmt->fetch();
$stmt->free_result();
$stmt->close();
}
$this->link->close();
}
}
?>
果然解决问题!