$host = 'localhost';
$user_name = 'root';
$password = 'admin';
$id = $_get['id'];
$conn = mysql教程_connect($host,$user_name,$password);
if(!$conn)
{
die('数据库连接失败:'.mysql_error());
}
mysql_select_db('test');
$sql = 'select id,name,city from users where id='.$id;
$result = mysql_query($sql) or die(" error: ".mysql_error()." 产生问题的sql:".$sql);
if($num = mysql_num_rows($result))
{
echo ' ';
while($row = mysql_fetch_array($result,mysql_assoc))
{
print_r($row);
}
}
else
{
echo '你要查询的数据己经学存在了';
}
mysql_close($conn);
?>
查询id=2的记录
|