dongqiao9583 2014-06-18 12:45
浏览 72
已采纳

使用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'
)
  • 写回答

1条回答 默认 最新

  • dqpu4988 2014-06-25 08:44
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 Python安装cvxpy库出问题
  • ¥15 用前端向数据库插入数据,通过debug发现数据能走到后端,但是放行之后就会提示错误
  • ¥15 python天天向上类似问题,但没有清零
  • ¥30 3天&7天&&15天&销量如何统计同一行
  • ¥30 帮我写一段可以读取LD2450数据并计算距离的Arduino代码
  • ¥15 C#调用python代码(python带有库)
  • ¥15 活动选择题。最多可以参加几个项目?
  • ¥15 飞机曲面部件如机翼,壁板等具体的孔位模型
  • ¥15 vs2019中数据导出问题
  • ¥20 云服务Linux系统TCP-MSS值修改?