结果不能将mysql转换为mysqli

我正在转换我的旧mysql到mysqli,但遇到这个问题mysqli结果不起作用。在互联网上看到,我发现它的功能已经改变,对于mysqli的结果是有没有相当于这里?

谢谢

这里是我的错误

Fatal error: Call to undefined function mysqli_result() in C:xampphtdocsbear_mysqlifunctionsusers.php on line 153 
    function user_exists($con,$username)
    {
    $username = sanitize($con,$username);

    $query = mysqli_query($con,"SELECT COUNT(`user_id`)FROM `users` WHERE `username` = '$username'");

    return (mysqli_result ($query, 0)== 1) ? true : false;

    }


不,没有mysqli_result对应部分的mysql_result 。 如果你只是检查它是否存在,只需使用->num_rows

并使用准备好的语句。

function user_exists($con, $username) {

    $sql = 'SELECT * FROM `users` WHERE `username` = ?';
    $select = $con->prepare($sql);
    $select->bind_param('s', $username);
    $select->execute();
    $select->store_result();

    return ($select->num_rows > 0); // returns bool (true/false)
}

或者为您的COUNT()使用别名并获取它:

function user_exists($con, $username) {

    $sql = 'SELECT COUNT(`user_id`) AS `total` FROM `users` WHERE `username` = ?';
    $select = $con->prepare($sql);
    $select->bind_param('s', $username);
    $select->execute();
    $select->store_result();
    $select->bind_result($total);
    $select->fetch();

    return $total; // returns the result yielded by alias `total`
}

在php.ini中启用mysqli

搜索extension=php_mysqli.dll和取消注释在php.ini只是删除;extension=php_mysqli.dll之前extension=php_mysqli.dll

; Windows Extensions
; Note that ODBC support is built in, so no dll is needed for it.
; Note that many DLL files are located in the extensions/ (PHP 4) ext/ (PHP 5)
; extension folders as well as the separate PECL DLL download (PHP 5).
; Be sure to appropriately set the extension_dir directive.

extension=php_mysqli.dll

并在应用设置后重新启动您的xampp。


如果你想检查用户名是否存在,你可以这样做:

$urexist="SELECT * FROM persons WHERE Email = '$_POST[EMailTxt]'";
$res = mysqli_query($conect,$urexist);//you should add a connection paramenter 
$data = mysqli_fetch_array($res, MYSQLI_NUM);
if($data[0] > 1) {
echo "User Exists";
}
链接地址: http://www.djcxy.com/p/69533.html

上一篇: result not working converting mysql to mysqli

下一篇: PHP average calculator not displaying results properly