<?php
Defined (' BasePath ') or exit (' No Direct script access allowed ');
Class Welcome extends My_controller {
/**
* Index Page for the This controller.
*
* Maps to the following URL
* Http://example.com/index.php/welcome
*-OR-
* Http://example.com/index.php/welcome/index
*-OR-
* Since This controller was set as the default controller in
* config/routes.php, it ' s displayed at http://example.com/
*
* So any other public methods not prefixed with an underscore would
* Map to/index.php/welcome/<method_name>
* @see https://codeigniter.com/user_guide/general/urls.html
*/
Public Function Index ()
{
/*
Query table
$res = $this->db->get (' pergoods ');
Var_dump ($res);
foreach ($res->result () as $item) {
Echo $item->username;
Echo $item->userid;
Echo $item->goods;
Echo $item->gdmodel;
Echo $item->gdnumber;
Echo $item->gdtime;
Echo ' <br> ';
}*/
/*
Add Table Data
$data =array (
' UserName ' = ' Zhang San ',
' UserID ' = ' 123 ',
);
$bool = $this->db->insert (' Pergoods ', $data);
Var_dump ($bool);
*/
/*
Modify
$data =array (
' UserName ' = ' John Doe ',
' UserID ' = ' 456 ',
);
$bool = $this->db->update (' Pergoods ', $data, Array (' RecordID ' =>42));
Var_dump ($bool);
*/
/*
Delete
$bool = $this->db->delete (' Pergoods ', Array (' RecordID ' =>42));
Var_dump ($bool);
*/
Consistent operation
$res = $this->db->select (' Recordid,username,userid ')
->from (' Pergoods ')
->where (' RecordID >= ', ten)//recordid greater than or equal to 10
->limit (3,2)//Skip two query three article
->order_by (' RecordID desc ')
->get ();
Var_dump ($res->result ());
Displays a recently executed SQL
echo $this->db->last_query ();
/*
where operation
$res = $this->db->where (' UserName ', ' Liu Zheng ')->get (' Pergoods ');
$res = $this->db->where (' UserName! = ', ' Liu Zheng ')->get (' Pergoods ');
$res = $this->db->where (Array (' UserName ' = ' Liu Zheng '))->get (' Pergoods ');
$res = $this->db->where (Array (' UserName ' = ' Liu Zheng ', ' RecordID > ' = ') '->get (' pergoods ');
echo $this->db->last_query ();
*/
$this->load->view (' welcome_message ');
}
}
PHP CI Framework Implementation and modification