有人請轉換我的下面的php + mysql搜索腳本爲php + mysqli或php + Pdo聲明...我不知道如何做到這一點...請幫助我... Tnx提前...如何將下面的mysql腳本轉換爲mysqli或pdo?
我的形式腳本
<html>
<head>
<title>search engine</title>
</head>
<body>
<form action = 'ss.php' method ='GET'>
<input type = "text" name = "q">
<input type = "submit" name = "submit" value = "search"
</body>
</html>
而且我的搜索引擎腳本是
<?php
$k = $_GET["q"];
$con = mysql_connect("localhost", "root", "");
mysql_select_db("x");
$terms=explode(" ",$k);
$i=0;
$set_limit = ("9");
$subi = "";
foreach ($terms as $each)
{
$i++;
if ($i == 1)
$subi.= " title LIKE '%$each%' ";
else
$subi.= " AND title LIKE '%$each%' ";
}
$query = "select SQL_CALC_FOUND_ROWS * from table WHERE $subi order by rand() limit $set_limit";
$qry = mysql_query("$query");
$row_object = mysql_query("Select Found_Rows() as rowcount");
$row_object = mysql_fetch_object($row_object);
$actual_row_count = $row_object->rowcount;
$result = $actual_row_count;
?>
Diplaying結果
<?php
if ($result>0)
{
while ($row = mysql_fetch_array($qry)){
$title=$row['title'];
$href=$row['href'];
$img=$row['img'];
echo "<div class=\"col-sm-4\"><div class=\"product-image-wrapper\"><div class=\"single-products\"><div class=\"productinfo text-center\"><img src=\"$img\" alt=\"$title\"><h5>$title</h5><a href=\"$href\" target=_blank </a></div></div></div></div>\n";
}
}
else
{
echo "Sorry No Items Found For " .$k;
}
?>
你做了任何研究,甚至一個簡單的谷歌搜索?,你會發現很多關於這一主題的文章:)嘗試「防止MySQL的PHP注入」 –