1.过滤数据
$search = addslashes(trim($_POST['search']));
2.建立数据库连接
对象风格:
@ $db = new mysqli('localhost','root','root','bookrama');
过程风格:
@$db = mysqli_connect('localhost','root','root','bookrama' );
3.检查连接情况
if($db->connect_errno){//if(mysqli_connect_errno($db)){}
echo "Error:Could not connect to data"
}
4.对数据库进行SQL操作
$query = “SQL语句”;
$result = $db->query($query); //$result = mysqli_query($db,$query);
5.返回查询结果
$num_results = $result->num_rows; // $num_results =mysqli_num_rows($result);
//返回结果的行数;
for($i =0;$i<$num_result;$i++){
$row = $result->fetch_assoc(); //将结果装载到一个关联数组;</