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

PHP基础知识(2)

WBOY
Release: 2016-06-13 12:03:32
Original
832 people have browsed it

PHP基础知识(二)

? ? ? 1 连接MySQL

?

$db_server = mysql_connect($db_hostname, $db_username, $db_password);if(!$db_server) die('Unable to connect to MySQL: '. mysql_error());
Copy after login

?

?

? ? ? 2 选择相应的数据库

?

mysql_select_db($db_database) or die('Unable to select database: ' . mysql_error());
Copy after login

?

? ? ? 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>';}
Copy after login

?

? ? ? 4 关闭连接

mysql_close($db_server);
Copy after login

?

?

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template