$db = &db(); // 第一步赋值数据库类库, $db->query(sql); // 第二步执行mysql 语句;
常用的数据库函数:
$user=$db->getrow("select * from ecm_member where user_id=111"); print_r($user);
$user=$db->getcol("select user_id from ecm_member "); print_r($user);
$user=$db->getall("select user_id from ecm_member "); foreach ( $user as $row) { print_r($row); }
$user=$db->getone("select count(*) from ecm_member "); echo $user;
$db->query("update ecm_member set user_name='aaa' ");
$db->query("insert ecm_member set user_name='aaa' "); $user_id = $db->insert_id(); echo $user_id;
详细的例子:
function userlist() { $db = &db(); $user=$db->getall("select user_id from ecm_member "); foreach ( $user as $row) { echo "用户姓名=".$row['user_name']." 用户电话=".$row['tel']; } }