如何正确查询MySQL数据库

I'm doing a MySql query like below and it works but I have to add a lot of '@' I was wondering how to do this correctly?

$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"));

Here's how I pieced together the output:

$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 ."")
);

Thank you

I'm assuming you are using PHP. I use PDO a lot here is what I usually do.

//PDO Connection
$connection = new PDO("MYSQL:host=localhost; dbname=mydb","userName","password");

//Query
$stmt = $connection->prepare("SELECT * FROM myTable WHERE id = ?");
//Execute query passing in parameter for id
$stmt->execute(array(5));
//Get Result
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);

I used to use msqli but have really enjoyed working with PDO as of late.