时间:2021-07-01 10:21:17 帮助过:17人阅读
query("SELECT * FROM `dh_member_control` WHERE `id`=1");$site = mysqli_fetch_array($site_data);?>
function marrbase(){if(isset($_COOKIE["uname"]) && isset($_COOKIE["uid"])){global $mbase;global $conn;$mql = "select * from dh_member where `id`=" . $_COOKIE["uid"] . " and `mck`=1";$mbase_data = mysqli_query($conn, $mql);$mbase = mysqli_fetch_array($mbase_data);}else{exit();}}function login_log($muid){if (empty($muid)){exit();}else {global $conn;$lql = "INSERT INTO `dh_mllog` (`uid`,`ltime`,`lip`,`lptxt`) VALUES (". $muid .",'". date("Y-m-d H:i:s") ."','". getIPaddress() ."','". getIPS138(getIPaddress()) ."')" ;if (!mysqli_query($conn, $lql)){die(mysqli_error());exit();}}}function memberislogin($back = NULL){if(!isset($_COOKIE["uname"]) || !isset($_COOKIE["uid"])){echo ""; exit();}else {global $conn;$login_check = mysqli_query ("SELECT * FROM `dh_member` WHERE `id`=". $_COOKIE["uid"] ." AND `mck`=1");if(!mysqli_num_rows($login_check)){echo ""; exit();}}}.....等等自定义函数
从 mysqli 继承一个 db 类
提供:
count 属性,用于返回影响的条数
fetch 方法,传入查询指令,返回一维数组
fetchall 方法,传入查询指令,返回二维数组
exec 方法,用于执行非查询类指令
基本就够了
学会封装代码,将mysql模块封装,其它需要用的地方,引用这个文件,直接调用封装的接口。
从 mysqli 继承一个 db 类
提供:
count 属性,用于返回影响的条数
fetch 方法,传入查询指令,返回一维数组
fetchall 方法,传入查询指令,返回二维数组
exec 方法,用于执行非查询类指令
基本就够了
学会封装代码,将mysql模块封装,其它需要用的地方,引用这个文件,直接调用封装的接口。
你总是有查询出多条记录的情况吧?比如文章列表
最简单的写法
class db extends mysqli { function __construct() { parent::__construct('localhost', '用户名', '口令', '数据库'); $this->query('set names utf8'); } function fetch($sql) { $rs = $this->query($sql); return $rs->fetch_assoc(); } function fetchall($sql) { $rs = $this->query($sql); while($row = $rs->fetch_assoc()) { $res[] = $row; } return $res; } funetion exec($sql) { return $this->query($sql); }}
$p = new db;print_r($p->fetch("select * from a"));print_r($p->fetchall("select * from a"));
你的 INSERT INTO `dh_mllog`.... 不就是非查询类的指令吗
你的 INSERT INTO `dh_mllog`.... 不就是非查询类的指令吗
你总是有查询出多条记录的情况吧?比如文章列表
最简单的写法
class db extends mysqli { function __construct() { parent::__construct('localhost', '用户名', '口令', '数据库'); $this->query('set names utf8'); } function fetch($sql) { $rs = $this->query($sql); return $rs->fetch_assoc(); } function fetchall($sql) { $rs = $this->query($sql); while($row = $rs->fetch_assoc()) { $res[] = $row; } return $res; } funetion exec($sql) { return $this->query($sql); }}
$p = new db;print_r($p->fetch("select * from a"));print_r($p->fetchall("select * from a"));
你的 INSERT INTO `dh_mllog`.... 不就是非查询类的指令吗
你总是有查询出多条记录的情况吧?比如文章列表
最简单的写法
class db extends mysqli { function __construct() { parent::__construct('localhost', '用户名', '口令', '数据库'); $this->query('set names utf8'); } function fetch($sql) { $rs = $this->query($sql); return $rs->fetch_assoc(); } function fetchall($sql) { $rs = $this->query($sql); while($row = $rs->fetch_assoc()) { $res[] = $row; } return $res; } funetion exec($sql) { return $this->query($sql); }}
$p = new db;print_r($p->fetch("select * from a"));print_r($p->fetchall("select * from a"));
$hot_vip_data = $conn->query("SELECT * FROM dh_member WHERE `mck`=1 AND `photo`<>'/images/nan.png' AND `photo`<>'/images/nv.png' ORDER BY `mpower` DESC,`cktime` DESC LIMIT 1,12");$i=1;while ($hot_vip = mysqli_fetch_array($hot_vip_data)){if ($i % 6 == 0){$last=" class=\"last\"";}else{$last="";}$i++;?>
这样改写么?
$hvip = new db;$hvip_data = $hvip->fetchall("SELECT * FROM dh_member WHERE `mck`=1 AND `photo`<>'/images/nan.png' AND `photo`<>'/images/nv.png' ORDER BY `mpower` DESC,`cktime` DESC LIMIT 1,12");$i=1;while ($hvip_data){if ($i % 6 == 0){$last = " class=\"last\"";}else{$last = "";}$i++;?>
$hvip = new db;$sql = $hvip->fetchall("SELECT * FROM dh_member WHERE `mck`=1 AND `photo`<>'/images/nan.png' AND `photo`<>'/images/nv.png' ORDER BY `mpower` DESC,`cktime` DESC LIMIT 1,12";foreach($hvip->fetchall($sql) as $i=>$hvip_data) { if (($i+1) % 6 == 0) $last = " class=\"last\""; else $last = "";?>
$hvip = new db;$sql = $hvip->fetchall("SELECT * FROM dh_member WHERE `mck`=1 AND `photo`<>'/images/nan.png' AND `photo`<>'/images/nv.png' ORDER BY `mpower` DESC,`cktime` DESC LIMIT 1,12";foreach($hvip->fetchall($sql) as $i=>$hvip_data) { if (($i+1) % 6 == 0) $last = " class=\"last\""; else $last = "";?>