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);

Thursday, December 09, 2010

Generate setter/getter for PHP in Eclipse

很久沒發文了,慶祝今天找到個快速產生setter/getter的套件,特別上來分享一下!

話說使用Eclipse開發Java class時在變數上點右鍵後選source即可看到自動產生setter/getter的選項,但開發PHP class時卻沒有這項貼心的功能~
詢問Google老師之後看到了很多做法,其中不乏自行編輯Eclipse的template for auto code completion,但是最讚的莫過於PHP source plugin這個套件,裝完之後Eclipse的toolbar上會出現"PHP Source",點下去即可選擇要產生特定變數的Getter/Setter :-)

下面的URL是該套件的官方網站:
http://pdt.plugins.e-surf.pl/features.php
裡面有screenshot供人瞻仰。。。