標籤:使用 io 資料 for ar cti 資料庫 sql
<?php
if (!defined(‘BASEPATH‘))
exit(‘No direct script access allowed‘);
class UseOra extends CI_Controller
{
public function index()
{
echo ‘歡迎使用測試CI使用Oracle 10g 的功能,您可以在地址欄中使用如下的函數參數:<br>‘;
echo ‘========================================================================<br>‘;
echo ‘selectData<br>‘;
echo ‘selectDataWitchParm($deptno)<br>‘;
echo ‘addData($deptno,$deptname,$deptloc)<br>‘;
echo ‘delData($deptno)<br>‘;
echo ‘updateData($detpno,$loc)<br>‘;
echo ‘========================================================================<br>‘;
echo ‘注意:已經在autoload.php中自動載入了資料庫通用類了!<br>‘;
}
public function selectData()
{
$sql = ‘select deptno,dname,loc from dept order by deptno‘;
$res = $this->db->query($sql);
$depts = $res->result();
foreach ($depts as $dept)
{
echo ‘編號:‘ . $dept->DEPTNO . ‘<br>‘;
echo ‘名稱:‘ . $dept->DNAME . ‘<br>‘;
echo ‘地址:‘ . $dept->LOC . ‘<br>‘;
echo ‘----------------------<br>‘;
}
}
public function selectDataWitchParm($deptno)
{
echo ‘第一種方法:使用?,參數作為數組<br>‘;
$sql = ‘select deptno,dname,loc from dept where deptno=? ordet by deptno‘;
$res = $this->db->query($sql, array($deptno));
$depts = $res->result();
foreach ($depts as $dept)
{
echo ‘編號:‘ . $dept->DEPTNO . ‘<br>‘;
echo ‘名稱:‘ . $dept->DNAME . ‘<br>‘;
echo ‘地址:‘ . $dept->LOC . ‘<br>‘;
echo ‘----------------------<br>‘;
}
echo ‘第二種方法:構造字串<br>‘;
$sql = ‘select deptno,dname,loc from dept where deptno=‘ . $deptno;
$res = $this->db->query($sql);
$depts = $res->result();
foreach ($depts as $dept)
{
echo ‘編號:‘ . $dept->DEPTNO . ‘<br>‘;
echo ‘名稱:‘ . $dept->DNAME . ‘<br>‘;
echo ‘地址:‘ . $dept->LOC . ‘<br>‘;
echo ‘----------------------<br>‘;
}
}
public function addData($deptno, $deptname, $deptloc)
{
$sql=‘insert into dept(deptno,dname,loc) values(?,?,?)‘;
$bool= $this->db->query($sql,array($deptno,$deptname,$deptloc));
if ($bool)
{
echo ‘插入成功!‘;
}
}
public function delData($deptno)
{
$sql=‘delete from dept where deptno=?‘;
$bool= $this->db->query($sql,array($deptno));
if ($bool)
{
echo ‘刪除資料成功!‘;
}
}
public function updateData($detpno,$deptloc)
{
$sql=‘update dept set loc=? where deptno =? ‘;
$bool= $this->db->query($sql,array($deptloc,$detpno));
if ($bool)
{
echo ‘更新資料成功!‘;
}
}
}
/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */
?>