阅读完SQL注入攻击后,我只是在编辑搜索脚本。我正在尝试使用PDO而不是常规的mysql连接从脚本中获得相同的功能。因此,我一直在阅读有关PDO的其他文章,但不确定。这两个脚本会提供相同的功能吗?
使用PDO:
$pdo = new PDO('mysql:host=$host; dbname=$database;', $user, $pass);
$stmt = $pdo->prepare('SELECT * FROM auction WHERE name = :name');
$stmt->bindParam(':name', $_GET['searchdivebay']);
$stmt->execute(array(':name' => $name);
使用常规mysql:
$dbhost = @mysql_connect($host, $user, $pass) or die('Unable to connect to server');
@mysql_select_db('divebay') or die('Unable to select database');
$search = $_GET['searchdivebay'];
$query = trim($search);
$sql = "SELECT * FROM auction WHERE name LIKE '%" . $query . "%'";
if(!isset($query)){
echo 'Your search was invalid';
exit;
} //line 18
$result = mysql_query($trim);
$numrows = mysql_num_rows($result);
mysql_close($dbhost);
我继续使用常规示例
while($i < $numrows){
$row = mysql_fetch_array($result);
从数据库创建匹配结果数组。我该如何使用PDO?