f atal error: Uncaught Error: call to undefined mysql_real_escape_string(),
我正在使用sql构建一个登录但是不断有任何人可以帮我这个错误
答案 0 :(得分:-1)
使用MySQL扩展函数处理数据库的基本工作流程可以看作是一个分为5个步骤的过程:
Establish a connection to the database server and select the database you’ll be working with
Construct a query to send the server
Send the query
Iterate over the returned result rows
Free the resources used by the result and possibly the database connection
<?php
// Step 1: Establish a connection
$db = mysql_connect("localhost", "testusr", "secretpass");
mysql_select_db("testdb", $db);
// Step 2: Construct a query
$query = "SELECT * FROM foo WHERE bar = '" . mysql_real_escape_string($zip) . "'";
// Step 3: Send the query
$result = mysql_query($query, $db);
// Step 4: Iterate over the results
while($row = myql_fetch_assoc($result)) {
print_r($row);
}
// Step 5: Free used resources
mysql_free_result($result);
mysql_close($db);
使用PDO,可以遵循相同的过程,如下所示:
<?php
// Step 1: Establish a connection
$db = new PDO("mysql:host=localhost;dbname=testdb", "testusr", "secretpass");
// Step 2: Construct a query
$query = "SELECT * FROM foo WHERE bar = " . $db->quote($zip);
// Step 3: Send the query
$result = $db->query($query);
// Step 4: Iterate over the results
while($row = $result->fetch(PDO::FETCH_ASSOC)) {
print_r($row);
}
// Step 5: Free used resources
$result->closeCursor();
$db = null;