Home >Backend Development >PHP Tutorial >PHP基础知识(2)

PHP基础知识(2)

WBOY
WBOYOriginal
2016-06-13 12:03:32815browse

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 ';    echo 'Title: ' . $row[1] . '<br>';}

?

? ? ? 4 关闭连接

mysql_close($db_server);

?

?

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn