0

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!

Juan M
  • 4,063
  • 4
  • 19
  • 28

1 Answers1

1

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();
Juan M
  • 4,063
  • 4
  • 19
  • 28