The useora.php in--control
<?php
if (!defined (' BasePath '))
Exit (' No Direct script access allowed ');
Class Useora extends Ci_controller
{
Public Function Index ()
{
Echo ' Welcome to test CI using Oracle 10g features, you can use the following function parameters in the address bar:<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 ' Arselectdata () use ActiveRecord mode <br> ';
Echo ' Arselectdatawithparam ($DEPTNO) Use ActiveRecord mode <br> ';
Echo ' ========================================================================<br> ';
Echo ' NOTE: The database Universal class has been loaded automatically in autoload.php! <br> ';
Echo ' ========================================================================<br> ';
The database platform that Echo ' uses is: '. $this->db->platform (). The <br> version is: '. $this->db->version ();
}
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 ' number: '. $dept->deptno. ' <br> ';
Echo ' name: '. $dept->dname. ' <br> ';
Echo ' address: '. $dept->loc. ' <br> ';
Echo '----------------------<br> ';
}
}
Public Function Selectdatawitchparm ($DEPTNO)
{
$sql = ' Select Deptno,dname,loc from dept where deptno=? Order by Deptno ';
$res = $this->db->query ($sql, Array ($deptno));
$depts = $res->result ();
Echo ' first method: use? Placeholder, parameter as array <br> ';
foreach ($depts as $dept)
{
Echo ' number: '. $dept->deptno. ' <br> ';
Echo ' Name: '. $dept->dname. ' <br> ';
Echo ' Address: '. $dept->loc. ' <br> ';
Echo '----------------------<br> ';
}
$sql = ' Select Deptno,dname,loc from dept where deptno= '. $deptno;
$res = $this->db->query ($sql);
$depts = $res->result ();
Echo ' second method: construct string <br> ';
foreach ($depts as $dept)
{
echo ' number: '. $dept->deptno. ' <br> ';
Echo ' name: '. $dept->dname. ' <br> ';
Echo ' address: '. $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 ' Insert success! ‘;
}
}
Public Function Deldata ($deptno)
{
$sql = ' Delete from dept where deptno=? ';
$bool = $this->db->query ($sql, Array ($deptno));
if ($bool)
{
Echo ' Delete data successfully! ‘;
}
}
Public Function UpdateData ($detpno, $deptloc)
{
$sql = ' Update dept set loc=? where Deptno =? ‘;
$bool = $this->db->query ($sql, Array ($deptloc, $detpno));
if ($bool)
{
Echo ' Updated data successfully! ‘;
}
}
Public Function Arselectdata ()
{
$this->load->model (' Museora_ar ');
$rows = $this->museora_ar->ar_selectdata ();
foreach ($rows as $row)
{
echo ' number: '. $row->deptno. ' <br> ';
Echo ' name: '. $row->dname. ' <br> ';
Echo ' address: '. $row->loc. ' <br> ';
Echo '----------------------<br> ';
}
}
Public Function Arselectdatawithparam ($DEPTNO)
{
$this->load->model (' Museora_ar ');
$rows = $this->museora_ar->ar_selectdatawithparam ($deptno);
foreach ($rows as $row)
{
Echo ' number: '. $row->deptno. ' <br> ';
Echo ' Name: '. $row->dname. ' <br> ';
Echo ' Address: '. $row->loc. ' <br> ';
Echo '----------------------<br> ';
}
}
}
?>
--The museora_ar.php in model
<?php
Class Museora_ar extends Ci_model
{
function __construct ()
{
Parent::__construct ();
$this->load->database ();
}
function Ar_selectdata ()
{
$this->db->order_by (' Deptno ', ' ASC ');//Sorting method
$this->db->select (' Deptno,dname,loc ');
$res = $this->db->get (' dept ');
return $res->result ();
}
function Ar_selectdatawithparam ($DEPTNO)
{
$this->db->where (' Deptno ', $deptno);
$this->db->select (' Deptno,dname,loc ');
$res = $this->db->get (' dept ');
return $res->result ();
}
}
?>