drdl18946 2012-09-18 16:56
浏览 26
已采纳

Pear DB方法类似于bindParam()?

Is there any way using the PEAR DB library to do something similar to the PDO bindParam()? I have a couple prepared statements that are going to use the same variable multiple times so I'd like to be able to bind the value to the variable in the prepared statement. I just can't find a way to do it with Pear DB.

This is what I've started doing, but it is a bit of a pain.

$sSql = "SELECT EventID
            DAY(CONVERT_TZ(EventDate, ?, ?)) as EventDay,
            FROM RacingEvents WHERE
            MONTH(CONVERT_TZ(EventDate, ?, ?)) = ? AND
            YEAR(CONVERT_TZ(EventDate, ?, ?)) = ?";

    $aArgs = array();
    $aArgs[] = DEFAULT_TIMEZONE;
    $aArgs[] = $this->sTimezone;
    $aArgs[] = DEFAULT_TIMEZONE;
    $aArgs[] = $this->sTimezone;
    $aArgs[] = $this->iMonth;
    $aArgs[] = DEFAULT_TIMEZONE;
    $aArgs[] = $this->sTimezone;
    $aArgs[] = $this->iYear;

    if ($this->iSkill) {
        $sSql .= " AND NOT REPLACE(EventSkill, ?, '') = EventSkill";
        $aArgs[] = $this->iSkill;
    }
  • 写回答

1条回答 默认 最新

  • dongqia0240 2012-09-26 11:09
    关注

    Pear's DB package is long dead, and you should either use MDB2 or PDO.

    MDB2 supports named parameters that you can pass to execute():

    <?php
    $types = array('integer', 'text', 'text');
    $sth = $mdb2->prepare('INSERT INTO numbers VALUES (:id, :name, :lang)', $types);
    
    $data = array('id' => 1, 'name' => 'one', 'lang' => 'en');
    $affectedRows = $sth->execute($data);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥30 自适应 LMS 算法实现 FIR 最佳维纳滤波器matlab方案
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥15 Python3.5 相关代码写作
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动