mysql返回错误

时间:2017-10-24 21:08:52

标签: php

我需要从表用户中检索用户名,但我使用的是mysql_real_escape_string但是它给了我错误:

( ! ) Fatal error: Uncaught Error: Call to undefined function mysql_real_escape_string() in C:\wamp64\www\final-project\profile.php on line 4
( ! ) Error: Call to undefined function mysql_real_escape_string() in C:\wamp64\www\final-project\profile.php on line 4
Call Stack
#   Time    Memory  Function    Location
1   0.0014  368024  {main}( )   ...\profile.php:0

代码是:

<?php include("./inc/header.inc.php");?>
<?php
if(isset($_GET['u'])) {
    $username = mysql_real_escape_string($_GET['u']);
    if(ctype_alnum($username)){
        //check if user exist
        $check = DB::query("SELECT username FROM users WHERE username='$username'");
        if(mysql_num_rows($check)==1){
        $get = mysql_fetch_assoc($check);
        $username = $get['username'];
        }else{
            echo "<meta http-equiv=\"refresh\"0; url=http://localhost/final-project/index.php\">";
            exit();
        }
    }
}
?>

<h2>Profile page for : <?php echo "$username";?></h2>

if(isset($ _ GET ['u']))返回用户名

1 个答案:

答案 0 :(得分:-1)

它已在PHP7中删除。

根据文件:

http://php.net/manual/en/function.mysql-real-escape-string.php

  

此扩展在PHP 5.5.0中已弃用,并已在PHP 7.0.0中删除。相反,应该使用MySQLi或PDO_MySQL扩展。另请参阅MySQL:选择API指南和相关常见问题解答以获取更多信息。