时间:2021-07-01 10:21:17 帮助过:20人阅读
? ? ? 1 连接MySQL
?
$db_server = mysql_connect($db_hostname, $db_username, $db_password);if(!$db_server) die('Unable to connect to MySQL: '. mysql_error());
?
?
? ? ? 2 选择相应的数据库
?
mysql_select_db($db_database) or die('Unable to select database: ' . mysql_error());
?
? ? ? 3 执行查询
$query = 'SELECT * FROM book';$result = mysql_query($query);if(!$result) die('Database access failed: ' . mysql_error());$rows = mysql_num_rows($result);for($j = 0; $j < $rows; ++$j){ $row = mysql_fetch_row($result); echo 'Author: ' . $row[0] . '
'; echo 'Title: ' . $row[1] . '
';}
?
? ? ? 4 关闭连接
mysql_close($db_server);
?
?