فرض کنیم درخواست کاربر به این صورت است:
//## http://domain.com/index.php?id=11
$id = (int) $_GET['id'];
//connect to database
$db = mysqli_connect('localhost','username','password',' database_name');
if (!$db) {
echo "Error: Unable to connect to MySQL." . PHP_EOL;
echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL;
echo "Debugging error: " . mysqli_connect_error() . PHP_EOL;
exit;
}
$db->set_charset("utf8");
//execute your query
$query = 'select * from table_name where id = "' . $id .'" limit 1;';
$result = $db->query($query);
$result = $result->fetch_array();
if($result){
print_r($result);
}else{
echo 'not found';
}