Pear DB方法类似于bindParam()?

时间:2012-09-18 16:56:04

标签: php pear

有没有办法使用PEAR DB库来执行与PDO bindParam()类似的操作?我有几个准备好的语句将多次使用相同的变量,所以我希望能够将值绑定到预准备语句中的变量。我只是找不到用Pear DB做的方法。

这是我开始做的事情,但这有点痛苦。

$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 个答案:

答案 0 :(得分:1)

Pear的DB软件包已经死了,您应该使用MDB2或PDO。

MDB2支持您可以传递给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);