使用PHP PDO类执行MSSQL存储过程
private function _SP()
{
$sql = "EXEC [DBNAME].[dbo].[SP_NAME] (?), (?), (?)";
$sql = $this->_dbconn->_dbcon->prepare($sql);
//$sql->execute(array($this->_cid, $this->_action_id, $this->_date));
$sql->bindParam(1, $this->_cid, PDO::PARAM_INT);
$sql->bindParam(2, $this->_action_id, PDO::PARAM_INT);
$sql->bindParam(3, $this->_date, PDO::PARAM_STR);
$sql->execute();
//print_r($sql);
return $sql;
/* foreach($this->_dbconn->_dbcon->query($sql) as $row)
{
echo $row["id"];
}
*/
I'm struggling to execute a MSSQL stored procedure using the PHP PDO class.
The comments indicate the various things I've tried but I can't seem to get anywhere with it.
I've been searching Google all day but it doesn't look like many people combine the languages that I've combined.
Please let me know if you can help, or at least point me to a tutorial.
Thanks
Ok so,
To answer your question Jonast92,
I'm using it in a class.
When it's returned, and I print_r() at the other end, I get this:
reports_adv_ajax_errorlogs Object
(
[_dbconn:reports_adv_ajax_errorlogs:private] => database Object
(
[_dbcon] => PDO Object
(
)
)
[_cid:reports_adv_ajax_errorlogs:private] => 4076158
[_action_id:reports_adv_ajax_errorlogs:private] => null
[_date:reports_adv_ajax_errorlogs:private] => '09-Jun-2014'
)
Ok,
So the reason it wasn't working was because PDO can't handle the MSSQL DATETIME data type.
I fixed this by not binding the parameters as shown below:
$sql = "EXEC [DBNAME].[dbo].[SP_NAME] $_cid, $_action_id, $_date";
It's not very secure but this particular query didn't need to be. I wouldn't recommend this method for select statements.