php 项目怎么使用pdo mysql 存储过程

1 dbConnect>>>链接数据库

---------------配置文件databanse.ini.php----------------------------------------

if(!defined('IN_XIAOCMS'))exit();

return array(

'host'=>'localhost',

'username'=>'root',

'password'=>'123456',

'dbname'=>'tougu',

'prefix'=>'xiao_',

'port'=>'3306',

'charset'=>'utf8',

);

---------------链接部分----------------------------------------

classdbConnect

{

private$pdo;

/**

* dbConnect constructor.

*/

public function__construct()

{

$params= xiaocms::load_config('database');

if(!is_array($params))exit('数据库配置文件不存在');

foreach($paramsas$key=>$value) {

$params[$key] =trim($value);

}

$dsn_array=array();

$dsn_array['host'] =$params['host'];

$dsn_array['port'] =$params['port'];

$dsn_array['dbname'] =$params['dbname'];

$dsn_array['charset'] =$params['charset'];

$params['dsn'] =sprintf('%s:%s','mysql',http_build_query($dsn_array,'',';'));

$options=array(PDO::MYSQL_ATTR_INIT_COMMAND=>"SET NAMES 'utf8';", PDO::ATTR_ERRMODE=> PDO::ERRMODE_EXCEPTION,PDO::ATTR_PERSISTENT=>true);

$this->pdo=newPDO($params['dsn'],$params['username'],$params['password'],$options);

}

public functionexecute($sql)

{

return$this->pdo->query($sql)->fetchAll(PDO::FETCH_ASSOC);

}

}

----------------定义存储过程-------------------------------------------------------------------------------------

public functionqueryTopicAndNewsBySubscriberId($type,$offset,$pageSize,$userId)

{

return$this->procedure

->setProcedureName('queryTopicAndNewsBySubscriberId')

->setArgument($type.','.$offset.','.$pageSize.','.$userId)

->getResult();

}

-----------------调用--------------------------------------------------------------------------------

$content=newcontentDb();

//查询所有的直播

$result=$content->querylive($this->type,$limit,20,$this->getIdentity()->getUserName());

你可能感兴趣的:(php 项目怎么使用pdo mysql 存储过程)