微擎语法
微擎sql语句
1、pdo_update 更新指定的数据表记录
array | boolean pdo_update($tablename,$data = array(),$condition, $glue = 'AND');
//更新uid=2用户的用户名
$user_data = array(
'username'=> 'daxiong',
);
$result= pdo_update('users',$user_data,array('uid'=> 2));
if(!empty($result))
{
message('更新成功');
}
2、pdo_delete : 删除指定条件的数据
int | boolean pdo_delete($tablename,$condition = array(), $glue='AND');
//删除用户名为小明的的记录
$result = pdo_delete ('users',array('username'= > '小明'));
if(!empty($result))
{
message('删除成功');
}
3、运行sql
pdo_query : 运行一条sql语句
int | boolean pdo_query($sql,$params = array());
//更新uid = 2 的用户的用户名
$result = pdo_query("UPDATE".tablename('users')." SET username= :username,age = :age" , array(': username' => '小朋', ': age' => '18', ': uid' => 2));
4、删除用户名为qiuwen的记录
$result = pdo_query("DELETE FROM ".tablename('users') . "WHERE username = : username", array('username' => '小明'));
if(!empty($result))
{
message('删除成功');
}
5、变更
pdo_insert : 对指定数据表插入一条新记录
int | boolean pdo_insert($tablename,$data = array(),$replace = false);
//添加一条用户记录,并判断是否成功
$user_data = array(
'username' => '小花',
'age' => '18',
);
$result = pdo_insert('users',$user_data);
if(!empty($result))
{
message('用户添加成功');
}
6、查询
pdo_get : 根据条件(AND连接)到指定的表中获取一条记录
array | boolean pdo_get($tablename,$condition = array(), $fields = array());
//根据uid获取用户的用户名和用户Id信息
//生成的sql等同于; select username,uid from ims_users where uid = '1' limit 1
$user = pdo_get('users',array('uid' =>1),array('username','uid'));
//生成的sql等同于:select username from ims_users where username = 'qiuwen' AND status = '1' LIMIT 1
$user = pdo_get('users',array('username' = > 'qiuwen','status' => 1),array('username'));
pdo_getall 根据条件(AND连接)到指定的表中获取全部记录
array | boolean pdo_getall($tablename,$condition = array(),$fields = array(), $keyfiled = '');
//获取全部启用的用户
//生成的sql等同于:select * from ims_users where status = '1'
$user = pdo_getall('users', array('status' => 1));