Combine PHP and MYSQL reasonably and effectively to create a sophisticated database website. MYSQL is a small, tight data server that supports standard SQL. It can be used in both UNIX and WINDOWS environments.
PHP and MYSQL are free open source code. Their combination can be developed in WINDOWS and serve in UNIX. PHP also supports other databases, including PostgreSQL.
The following is an example:
First, you have installed PHP and MYSQL. This simple script example reads data from the database and then 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> |
The mysql_connect () function is used to connect to a MYSQL server on the specified host using the user name (or password. The variable $ db is used to submit this connection ..
Mysql_select_db () specifies the question behind the database. The mysql_query () function sends an SQL question to MySQL for execution. The result is returned and stored in the variable $ result.
Finally, the mysql_result () function is used to obtain the result.