//連接數據庫 $mysqli = new mysqli("localhost", "root", "root", "mobilemoms"); //分為別:主機、數據庫賬戶、密碼、數據庫名 !$mysqli->connect_error or die("CONNECT SQL ERROR".$mysqli->connect_error); $mysqli->query("set names utf8"); //sql預編譯 $sql = "select tally_name,machine_no from device_member where mobile_no=? and mobile_pwd=? limit 1"; $mysqli_stmt = $mysqli->prepare($sql); //這里的?表示預留參數,將在后面填入,防止sql注入 //綁定參數
$mysqli_stmt->bind_param("ss",$mobileno,$pwd);//綁定查詢參數 ,ss表示string string類型,后面的為將上面的兩個參數填充 $mysqli_stmt->bind_result($tally_name,$machine_no);//綁定結果參數 也就是將查詢結果直接給某參數
//執行並處理查詢結果 $mysqli_stmt->execute(); if(!$mysqli_stmt->fetch()){ //沒有內容 wrong("No User"); }else{//有內容 echo "success";
//echo($tally_name);
//echo($machine_no);
}