class StoredProcHelper
{
private static $type = [
'integer'=>PDO::PARAM_INT,
'string'=>PDO::PARAM_STR,
'null'=>PDO::PARAM_NULL,
'boolean'=>PDO::PARAM_BOOL
];
private $sql = '';//此变量在下方说明
private $params = [];//此变量在下方说明
private $connect_info;//此变量在下方说明
private $pdo_connect;
public function __construct($connect_info,$sql,$params){
$this->sql = 'SET NOCOUNT ON;'.$sql;
$this->params = $params;
$this->connect_info = $connect_info;
if(!empty($this->connect_info->dsn) && !empty($this->connect_info->username) && !empty($this->connect_info->password)){
$this->pdo_connect = new PDO($this->connect_info->dsn,$this->connect_info->username, $this->connect_info->password);
}
}
public function ExecuteProc(){
$link = $this->pdo_connect->prepare($this->sql);
foreach ($this->params as $key => $value){
$link->bindParam($key,$value,self::$type[strtolower(gettype($value))]);
}
$link->execute();
$i = 1;
$res[0] = $link->fetchAll();
while($link->nextRowset()){
$res[$i] = $link->fetchAll();
$i++;
}
return $res;
}
}
public static function Example($connect_info,$mobile){
$sql='declare @customParam int;exec you_proc @Mobile = :mobile,@OutParam=@customParam out;select @customParam as outName;';
$params = [
':mobile'=>$mobile
];
$pdo = new StoredProcHelper($connect_info,$sql,$params);
$res = $pdo->ExecuteProc();
var_dump($res);
}
[ 'dsn' => 'sqlsrv:Server=xxxxxxxxxx;Database=xxxxx', 'username' => 'xxxxx', 'password' => 'xxxxxxxxxxxxxxxxxxxx', 'charset' => 'utf8', ] //或 [ 'dsn' => 'dblib:host=xxxxxxxxxx;dbname=xxxxx', 'username' => 'xxxxx', 'password' => 'xxxxxxxxxxxxxxxxxxxx', 'charset' => 'utf8', ],
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有