脚本宝典收集整理的这篇文章主要介绍了PHP基于PDO调用sqlserver存储过程通用方法【基于Yii框架】,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
本文实例讲述了PHP基于PDO调用sqlserver存储过程的方法。分享给大家供大家参考,具体如下:
由于业务这边存储过程一直在sqlserver上面,所以要用PHP去调用它,然而我们本地的是windows,而线上又是linux,一开始使用Yii框架的一些机制去调用发现在本地一直都是好的然而到线上就不行了,找了很多方案,最后找到了pdo这种方案,而本地使用的驱动是sqlsrv线上是dblib所以需要注意下链接pdo时的驱动形式,在取结果集的时候注意windows和linux好像有所不同,在我加上set nocount on后win若果直接取结果就可以拿到最后的,然而放到linux就没了,气死人的说,索性最后我把所有的都取一遍;
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; } }
以上是脚本宝典为你收集整理的PHP基于PDO调用sqlserver存储过程通用方法【基于Yii框架】全部内容,希望文章能够帮你解决PHP基于PDO调用sqlserver存储过程通用方法【基于Yii框架】所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。