将mysql_result转换为mysqli_result

时间:2015-07-22 16:55:51

标签: php mysql mysqli

我需要帮助。我想将mysql_result转换为mysqli_result。

    function user_exists($username) {
      $username = sanitize($username); 
      return (mysql_result(mysql_query("SELECT COUNT(`user_id`) FROM `users` WHERE `username` = '$username'"), 0) == 1) ? true : false;
    }

    function user_exists($username) {
      $username = sanitize($username); 
      return (mysqli_result(mysqli_query($con7,"SELECT COUNT(`user_id`) FROM `users` WHERE `username` = '$username'"), 0) == 1) ? true : false;
    }

我尝试添加此代码。但它仍无效。

    function mysqli_result($res, $row, $field=0) { 
      $res->data_seek($row); 
      $datarow = $res->fetch_array(); 
      return $datarow[$field]; 
    }

编辑。 $ con7就是这样

    $con7 = mysqli_connect('localhost','root', '', 'database') or exit($connect_error);

0 个答案:

没有答案