您好,欢迎访问一九零五行业门户网

php mysql_real_escape_string()函数_PHP教程

mysql教程_real_escape_string() 函数转义 sql 语句中使用的字符串中的特殊字符。
下列字符受影响:
x00
n
r
'
x1a
如果成功,则该函数返回被转义的字符串。如果失败,则返回 false。
语法
mysql_real_escape_string(string,connection)参数 描述
string 必需。规定要转义的字符串。
connection 可选。规定 mysql 连接。如果未规定,则使用上一个连接。
实例
getmessage ();
    }
  }
function selectdb ($whichdb, $db){
    try {
      if (!mysql_select_db ($whichdb,$db)){
        throw new exception (sorry, database could not be opened.);
      }
    } catch (exception $e) {
      echo $e->getmessage();
    }
  }
  function closedatabase ($db){
    mysql_close ($db);
  }
  $db = opendatabase (localhost,root,);
  selectdb (mydatabase,$db);
  $_post['user'] = myname;
  $_post['pass'] = mypassword;
function validatelogin ($user,$pass){
    mysql_real_escape_string ($user);
    mysql_real_escape_string ($pass);
    $thequery = select * from userlogin where username='$user' and password='$pass';
    if ($aquery = mysql_query ($thequery)){
      if (mysql_num_rows ($aquery) > 0){
        return true;
      } else {
        return false;
      }
    } else {
      echo mysql_error();
    }
  }
if (validatelogin ($_post['user'],$_post['pass'])){
    echo you have successfully logged in.;
  } else {
    echo sorry, you have an incorrect username and/or password.;
  }
closedatabase ($db);
?>
http://www.bkjia.com/phpjc/630752.htmlwww.bkjia.comtruehttp://www.bkjia.com/phpjc/630752.htmltecharticlemysql教程_real_escape_string() 函数转义 sql 语句中使用的字符串中的特殊字符。 下列字符受影响: x00 n r ' x1a 如果成功,则该函数返回被转义的...
其它类似信息

推荐信息