dongse7261 2015-02-26 03:18
浏览 90
已采纳

PHP ADODB和MySQL,绑定参数

I'm using ADODB and MYSQL, trying to execute an INSERT statement.

Though I've read plenty of forum posts and learned that I cannot bind parameters as easily as with oci8, I still have not found an example similiar to what I'm trying to achieve. My code is as follows with oci8:

$street = $branch->getStreet();
$number = $branch->getNumber();
$city = $branch->getCity();
$state = $branch->getState();
$xMap = $branch->getXMap();
$yMap = $branch->getYMap();
$email = $branch->getEmail();

try{

    //$this->db->debug = true;                    
    $sql = "INSERT INTO branch ( nombre_branch, street, number, city, state, x_map, y_map, email ) VALUES (:branchName, :street, :number, :city, :state, :xMap, :yMap, :email)";
    $sp = $this->db->PrepareSP($sql);

    $this->db->InParameter($sp, $branchName, 'branchName');
                $this->db->InParameter($sp, $street, 'street');
                $this->db->InParameter($sp, $number, 'number');
                $this->db->InParameter($sp, $city, 'city');
                $this->db->InParameter($sp, $state, 'state');
                $this->db->InParameter($sp, $xMap, 'xMap');
                $this->db->InParameter($sp, $yMap, 'yMap');
                $this->db->InParameter($sp, $email, 'email');

                $rs = $this->db->Execute($sp);                     

    } catch(ADODB_Exception $adodb_exception){
        $logInfo['exception'] = $adodb_exception->getMessage();
        $message = "'[".__CLASS__."] Error al executing ' insert '";


        if( !$this->rollbackTransaction()){
            if(!is_null($this->log)) $this->log->log("ERROR in DB: ".print_r($logInfo, true), PEAR_LOG_ERR);
            $message .= " Error in ROLLBACK.";

            throw new DAODatabaseTransactionException ($message, $adodb_exception->getCode());
        }           
    }
            return $returnValue;
}

Thanks!

  • 写回答

1条回答 默认 最新

  • dongxing9219 2015-02-26 04:22
    关注

    This is how i got it to work with mysql, without having to implement PDO

     $sql = "INSERT INTO branch( branch_name, street, number, city, state, x_map, y_map, email) VALUES (?, ?, ?, ?, ?, ?, ?, ?)";                            
    
                        $rs = $this->db->Execute($sql, array($branchName, $street, $number, $city, $state, $xMap, $yMap, $email));                     
                        $rs->Close();
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器