if (!defined('BASEPATH'))
exit('No direct script access allowed');
class UseOra extends CI_Controller
{
public function index()
{
echo '欢迎使用测试CI使用Oracle 10g 的功能,您可以在地址栏中使用如下的函数参数:
';
echo '========================================================================
';
echo 'selectData
';
echo 'selectDataWitchParm($deptno)
';
echo 'addData($deptno,$deptname,$deptloc)
';
echo 'delData($deptno)
';
echo 'updateData($detpno,$loc)
';
echo '========================================================================
';
echo '注意:已经在autoload.php中自动加载了数据库通用类了!
';
}
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 . '
';
echo '名称:' . $dept->DNAME . '
';
echo '地址:' . $dept->LOC . '
';
echo '----------------------
';
}
}
public function selectDataWitchParm($deptno)
{
echo '第一种方法:使用?,参数作为数组
';
$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 . '
';
echo '名称:' . $dept->DNAME . '
';
echo '地址:' . $dept->LOC . '
';
echo '----------------------
';
}
echo '第二种方法:构造字符串
';
$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 . '
';
echo '名称:' . $dept->DNAME . '
';
echo '地址:' . $dept->LOC . '
';
echo '----------------------
';
}
}
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 */
?>