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 2024-五一综合模拟赛
  • ¥15 如何将下列的“无限压缩存储器”设计出来
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口