MySQL原生PHP操作-天龙八步

<?php
//1、第一步【建立连接】 $conn = mysqli_connect('localhost','root','123456') or die('数据库连接失败!'); //2、第二步【选择数据库】 mysqli_select_db($conn,'new_kt'); //3、第三步【设置字符集】 mysqli_set_charset($conn,'utf8'); //4、第四步【准备sql语句】 $sql = 'select * from `user` limit 10'; //5、第五步【执行sql语句】 $result = mysqli_query($conn,$sql); $new_result = [];//数组结果集 //while($row = mysqli_fetch_array($result)){ //$new_result[]=$row; //} //6、第六步【获取结果集】 //或者如下方式 $new_result = mysqli_fetch_all($result,MYSQLI_ASSOC); $nums = mysqli_num_rows($result);//数据条数 //7、第七步【释放临时数据】 mysqli_free_result($result); //8、第八步【关闭连接】 mysqli_close($conn); ?>
原文地址:https://www.cnblogs.com/guliang/p/11872246.html