php mysql stmt_PHP MySQLi_STMT 用法 手册 | 示例代码

protected$mysql;

function__construct()

{//Get MySQL config values from config.ini fileif($config=parse_ini_file("../config.ini"))

{// Obtener los valores del fichero de configuración config.ini$ip=$config["ip"];$user=$config["usuario"];$pass=$config["password"];$bd=$config["bd"];//Connection between a database and php$this->mysql= newmysqli($ip,$user,$pass,$bd);

}

}

functionsetResultQuery($query,$param)

{$array=NULL;

if(!$this->mysql->connect_errno)

{$stmt=$this->setStatement($query,$param);

try

{

if($stmt!=NULL)

{

if($stmt->execute())

{//Obtener resultados$stmt->store_result();$variables= array();$data= array();$meta=$stmt->result_metadata();

while($field=$meta->fetch_field())

{$variables[] = &$data[$field->name];

}call_user_func_array(array($stmt,'bind_result'),$variables);$i=0;

while($stmt->fetch())

{$array[$i] = array();

foreach($dataas$k=>$v)$array[$i][$k] =$v;$i++;

}$stmt->close();

}

}

}catch(Exception $e){$array=FALSE;

}

}

return$array;

}

functionsetStatement($query,$param)

{

try

{$stmt=$this->mysql->prepare($query);$ref= newReflectionClass('mysqli_stmt');

if(count($param) !=0)

{$method=$ref->getMethod('bind_param');$method->invokeArgs($stmt,$param);

}

}catch(Exception $e){

if($stmt!=null)

{$stmt->close();

}

}

return$stmt;

}

functionsetNoResultQuery($query,$param)

{$validation=FALSE;

if(!$this->mysql->connect_errno)

{

try

{$stmt=$this->setStatement($query,$param);

if($stmt!=null)

{

if($stmt->execute())

{$stmt->close();$validacion=TRUE;

}

}

}catch(Exception $e){$validation=FALSE;

}

}

return$validation;

}

function__destruct()

{$this->mysql->close();

}

}?>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值