将PDO更改为Mysqli

问题描述 投票:0回答:1

我想将PDO代码转换为mysqli并遇到一些问题。我在这方面还很陌生,我真的不完全了解PDO。

     $query = "INSERT INTO gender(gender) VALUES (:gender)";
     $statement = $conn->prepare($query);
     $statement->execute(array('gender' => $_POST["gender"])
     );
     $count = $statement->rowCount();

我到现在为止。

    $statement = $db->prepare ($query);;
    $statement = array('gender' => $_POST["gender"]);
    $count=mysqli_num_rows($query);
    $statement = mysqli_fetch_array ($query);
php mysqli pdo
1个回答
1
投票

尝试此版本:

$query = "INSERT INTO gender(gender) VALUES (?)";
$stmt = $mysqli->prepare($query);
$stmt->bind_param("s", $_POST["gender"]);
$stmt->execute();
// fetch result set here
$stmt->close();
© www.soinside.com 2019 - 2024. All rights reserved.