原生php操作mysqli

原生php操作mysqli ,老年人记忆系列,记不住就copy一下提高效率

index.php

<?php
$mysql_conf = array(
           'host' => 'localhost',
           'db'   => 'hw',
           'user' => 'root',
           'pwd'  => 'root123',
        );
 
$mysqli = @new mysqli($mysql_conf['host'], $mysql_conf['user'], $mysql_conf['pwd']);
 
$mysqli -> query("set names 'utf8';");//编码转化
 
$select_db = $mysqli -> select_db($mysql_conf['db']);
 
$sql = "select * from user limit 2";
 
$res = $mysqli -> query($sql);
 
$data = array();
 
while ($row = $res->fetch_assoc()) {
 
	$data[] = $row;
}
 
echo "<pre>";
print_r($data);




//如果数据操作语句到->query()这一步就行
0 评论
内联反馈
查看所有评论