gpt4 book ai didi

php - Mysql 到 mysqli php

转载 作者:行者123 更新时间:2023-11-29 04:54:49 26 4
gpt4 key购买 nike

我正在尝试将我当前的代码转换为 MySQLi 扩展......但我对这段代码有疑问......

    $sql = "SELECT COUNT(*) FROM users WHERE username='$username'";
$result = mysql_query($sql);
if (mysql_result($result, 0) > 0) {
$errors[] = 'The username is already taken.';
}

“mysql_result”的 mysqli 函数是什么?我无法让它工作。

我现在的MySqLi代码就是连接和

    $sql = "SELECT COUNT(*) FROM users WHERE username='$username'";
$result = $mysqli->query($sql);
if (mysql_result($result, 0) > 0) {
$errors[] = 'The username is already taken.';
}

但我需要更改mysql_result,但在MySQLi 中找不到相反的函数..

最佳答案

我通常使用 MySQLi 的 object-y 接口(interface):

<?php
$db = new mysqli($hostname, $username, $password, $database);
$result = $db->query('SQL HERE');

// OOP style
$row = $result->fetch_assoc();
$row = $result->fetch_array();

while($row = $result->fetch_row())
{
// do something with $row
}

// procedural style, if you prefer
$row = mysqli_fetch_assoc($result);
$row = mysqli_fetch_array($result);

while($row = mysqli_fetch_row($result))
{
// do something with $row
}
?>

完整的结果方法列表在这里:http://www.php.net/manual/en/class.mysqli-result.php

关于php - Mysql 到 mysqli php,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7551469/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com