首页 > 代码库 > 使用CI操作oracle 10g的单表增删改查
使用CI操作oracle 10g的单表增删改查
<?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 */
?>