Again, "Use CI to operate Oracle 10g's single-table additions and deletions"

Source: Internet
Author: User
Tags dname

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

}
?>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.