Search Google

Wednesday, December 15, 2010

修改CodeIgniter (aka. CI)使其能正確執行oci_bind_by_name所需步驟

修改CodeIgniter (aka. CI)使其能正確執行oci_bind_by_name所需步驟:
Step 1.
/system/database/DB_driver.php -->
line 293:
--
if (FALSE === ($this->result_id = $this->simple_query($sql)))
++
if (FALSE === ($this->result_id = $this->simple_query($sql, $binds)))
line 440:
--
function simple_query($sql)
++
function simple_query($sql, $binds=FALSE)
line 447:
--
return $this->_execute($sql);
++
return $this->_execute($sql, $binds);

Step 2.
/system/database/drivers/oci8/oci8_driver.php -->
line 165:
--
function _execute($sql)
++
function _execute($sql, $binds=FALSE)
line 172-172:
--
++
if($binds != FALSE) {
foreach($binds as $k => $bind) {
oci_bind_by_name($this->stmt_id, $bind['name'], $bind['value']);
}
}

使用範例:
$sql = "insert
into related_firm
(
TYPE,
NAME,
CONTACT_ADDR,
CONTACT_NUMBER,
CONTACT_FAX,
SN
)
values
(
:TYPE,
:NAME,
:CONTACT_ADDR,
:CONTACT_NUMBER,
:CONTACT_FAX,
:SN
)";
$params[] = array('name'=>':TYPE', 'value'=>$this->type);
$params[] = array('name'=>':NAME', 'value'=>$this->name);
$params[] = array('name'=>':CONTACT_ADDR', 'value'=>$this->contactAddress);
$params[] = array('name'=>':CONTACT_NUMBER', 'value'=>$this->contactNumber);
$params[] = array('name'=>':CONTACT_FAX', 'value'=>$this->contactFax);
$params[] = array('name'=>':SN', 'value'=>$this->serialNumber);
$db = $this->load->database('TESTDB', TRUE);
$db->query($sql, $values, TRUE);

No comments: