Home > Backend Development > PHP Tutorial > Reasonable and effective combination of PHP and MYSQL database_PHP tutorial

Reasonable and effective combination of PHP and MYSQL database_PHP tutorial

WBOY
Release: 2016-07-15 13:24:34
Original
874 people have browsed it

By combining PHP and MYSQL reasonably and effectively, you can create an exquisite database website. MYSQL is a small, compact data server that supports standard SQL. It can be used in both UNIX and WINDOWS environments.

PHP and MYSQL are both free and open source. Their combination can be developed in WINDOWS and provided services in UNIX. PHP also supports some other databases including PostgreSQL.

Here is an example:

First you have installed PHP and MYSQL. This simple script example reads data from the database and displays it. .

<html><body><?php $db = mysql_connect("localhost", "root"); mysql_select_db("mydb", $db); $result = mysql_query("SELECT * FROM books",$db); echo "Title: ".mysql_result($result,0,"title")."<br>n"; echo "Author: ".mysql_result($result,0,"author")."<br>n"; echo "Price: ".mysql_result($result,0,"price")."<br>n"; ?></body></html>
Copy after login

The function mysql_connect() refers to connecting to a MYSQL server through the user name (or the specified password) on the specified host. The variable $db is used to submit this connection. .

mysql_select_db() specifies the database to be used for subsequent questions. The function mysql_query() is to send a SQL query to MySQL for execution, and the result is returned and stored in the variable $result.

Finally, the mysql_result() function is to get the result.


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/446752.htmlTechArticleThe reasonable and effective combination of PHP and MYSQL can create an exquisite database website. MYSQL is a small, compact data server that supports standard SQL. It works in UNIX and WINDOWS environments...
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