如何從MYSQL切換到MYSQLI?因爲我嘗試過,但返回一個空值。謝謝你提前!Mysqli的Mysql
MySQL代碼:
if(isset($_POST["username"])&& isset($_POST["password"])){
$manager = preg_replace('#[^A-Za-z0-9]#i','',$_POST["username"]);
$password = preg_replace('#[^A-Za-z0-9]#i','',$_POST["password"]);
include "includes/connect_db.php";
$sql = mysql_query("SELECT id FROM admin WHERE username='$manager'
AND password=$password' LIMIT 1");
$existCount = mysql_num_rows($sql);//count the row nums
if($existCount == 1){//evaluate the count
while($row=mysql_fetch_array($sql)){
$id=$row["id"];
}
$_SESSION["id"] = $id;
$_SESSION["manager"]=$manager;
$_SESSION["password"]=$password;
header("location:index.php");
exit();
}else{
echo 'That information is incorrect, try again <a href="index.php">Click Here</a>';
exit();
}
這是我以前試過,但告訴我一個消息,mysqli_num_rows有布爾結果。
的mysqli代碼:
if(isset($_POST["username"])&& isset($_POST["password"])){
$manager = preg_replace('#[^A-Za-z0-9]#i','',$_POST["username"]);
$password = preg_replace('#[^A-Za-z0-9]#i','',$_POST["password"]);
include("includes/insert_db.php"); // i change the database connection
$sql = "SELECT * FROM admin WHERE username='$manager'
AND password=$password'";
$result = mysqli_query($con, $sql);
$existCount = mysql_num_rows($result);//count the row nums
if($existCount == 1){//evaluate the count
while($row=mysqli_fetch_array($result)){
$id=$row["id"];
}
$_SESSION["id"] = $id;
$_SESSION["manager"]=$manager;
$_SESSION["password"]=$password;
header("location:index.php");
exit();
}else{
echo 'That information is incorrect, try again <a href="index.php">Click Here</a>';
exit();
}
}
我們不知道你有connect_db.php ... – fico7489
告訴我們,你試圖寫的MySQLi代碼。這是MySQL代碼。 –
http://stackoverflow.com/questions/31178092/switching-on-mysqli-over-mysql –