PHP的CI框架实现增删查改
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PHP的CI框架实现增删查改相关的知识,希望对你有一定的参考价值。
<?php
defined(‘BASEPATH‘) OR exit(‘No direct script access allowed‘);
class Welcome extends MY_Controller {
/**
* Index Page for 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 is 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 will
* map to /index.php/welcome/<method_name>
* @see https://codeigniter.com/user_guide/general/urls.html
*/
public function index()
{
/*
//查询表
$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>‘;
}*/
/*
//增加表数据
$data=array(
‘UserName‘=>‘张三‘,
‘UserID‘=>‘123‘,
);
$bool=$this->db->insert(‘pergoods‘,$data);
var_dump($bool);
*/
/*
//修改
$data=array(
‘UserName‘=>‘李四‘,
‘UserID‘=>‘456‘,
);
$bool=$this->db->update(‘pergoods‘,$data,array(‘RecordID‘=>42));
var_dump($bool);
*/
/*
//删除
$bool=$this->db->delete(‘pergoods‘,array(‘RecordID‘=>42));
var_dump($bool);
*/
//连贯操作
$res=$this->db->select(‘RecordID,UserName,UserID‘)
->from(‘pergoods‘)
->where(‘RecordID >=‘,10) //RecordID大于等于10
->limit(3,2) //跳过俩条查询三条
->order_by(‘RecordID desc‘)
->get();
var_dump($res->result());
//显示最近执行的一条sql
echo $this->db->last_query();
/*
//where操作
$res=$this->db->where(‘UserName‘,‘刘政‘)->get(‘pergoods‘);
$res=$this->db->where(‘UserName !=‘,‘刘政‘)->get(‘pergoods‘);
$res=$this->db->where(array(‘UserName‘=>‘刘政‘))->get(‘pergoods‘);
$res=$this->db->where(array(‘UserName‘=>‘刘政‘,‘RecordID >‘=>‘10‘))->get(‘pergoods‘);
echo $this->db->last_query();
*/
//$this->load->view(‘welcome_message‘);
}
}
以上是关于PHP的CI框架实现增删查改的主要内容,如果未能解决你的问题,请参考以下文章