PHP基础知识(二)
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] . '<br>'; echo 'Title: ' . $row[1] . '<br>'; }
4 关闭连接
mysql_close($db_server);
相关推荐
yifangs 2020-10-13
zyyjay 2020-11-09
xuebingnan 2020-11-05
samtrue 2020-11-22
stefan0 2020-11-22
songshijiazuaa 2020-09-24
hebiwtc 2020-09-18
天步 2020-09-17
83911535 2020-11-13
whatsyourname 2020-11-13
zhouyuqi 2020-11-10
Noneyes 2020-11-10
mathchao 2020-10-28
王志龙 2020-10-28
wwwsurfphpseocom 2020-10-28
diskingchuan 2020-10-23
savorTheFlavor 2020-10-23