php - How to correctly query MySQL database -


i'm doing mysql query below , works have add lot of '@' wondering how correctly?

$query="select * `facebook` order 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 pieced 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 using php. use pdo lot here do.

//pdo connection $connection = new pdo("mysql:host=localhost; dbname=mydb","username","password");  //query $stmt = $connection->prepare("select * mytable id = ?"); //execute query passing in parameter id $stmt->execute(array(5)); //get result $result = $stmt->fetchall(pdo::fetch_assoc); 

i used use msqli have enjoyed working pdo of late.


Comments