我正在做一個像下面的MySql查詢,它的工作原理,但我不得不添加很多'@'我想知道如何正確地做到這一點?如何正確查詢MySQL數據庫
$query="SELECT * FROM `facebook` ORDER by rand() LIMIT 1";
$result=mysql_query(@$query) or die(mysql_error());
$topic = htmlentities(mysql_result(@$result,@$i,"topic"));
$name = htmlentities(mysql_result(@$result,@$i,"name"));
$file = htmlentities(mysql_result(@$result,@$i,"file"));
$description = htmlentities(mysql_result(@$result,@$i,"description"));
以下是我拼湊起來的輸出:
$params = array(
"message" => ("". $topic .""),
"link" => "http://www.example.com",
"picture" => ("http://www.example.com/facebook/file-uploading/uploads/". $file .""),
"name" => ("". $name .""),
"caption" => "WWW.EXAMPLE.COM",
"description" => ("". $description ."")
);
謝謝
如果你正在尋找「正確」的方式,那麼忘記你正在做的一切,並使用正確的api。 'mysql_ *'函數不推薦使用,不安全。 –
爲什麼你要添加'@'s如果它工作? – chris85
使用PDO或MySQLi! –