我在mysqli中更改了PDO的连接类型。
PDO_连接
<?php
try {
$pdo = new PDO('mysql:host=localhost;dbname=exercise', 'root', 'root');
} catch (PDOException $e){
exit('Datebase error.');
}
?>
mysqli_connection
<?php
$host = "localhost";
$username = "root";
$password = "root";
$dbname = "exercise";
$mysqli = new mysqli($host, $username, $password, $dbname);
if(mysqli_connect_errno()) {
echo "Error: Could not connect to database.";
exit;
}
?>
而现在正试图在mysqli 中更改PDO 中写的一段代码。
PDO_code
$query = $pdo->prepare("SELECT * FROM users WHERE user_name=? AND user_password=? LIMIT 1");
$query->bindValue(1, $username, PDO::PARAM_STR);
$query->bindValue(2, $password, PDO::PARAM_STR);
$query->execute();
$num = $query->rowCount();
$row = $query->fetch(PDO::FETCH_ASSOC);
这是我在 mysqli 中改变它的尝试
mysqli_code
$query = $mysqli->prepare("SELECT * FROM users WHERE user_name=? AND user_password=? LIMIT 1");
$query->bind_result($username, $password);
$query->execute();
$num = $query->num_rows;
$row = $query->fetch_assoc();
我哪里错了?