PHP and MySQL are reasonably and effectively combined

Source: Internet
Author: User
Tags mysql mysql in php and php and mysql
MySQL combines PHP and MySQL in a reasonable and efficient way to create a sophisticated database site. 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 free open source. Their combination can be developed in Windows and served in UNIX. PHP also supports some other databases including PostgreSQL.

Here's an example:
First of all, you have installed PHP and MySQL. This simple script example reads data from a database and then displays it.

<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>

function mysql_connect () refers to a MySQL server that is connected by a user name (or a specified password) on a specified host. Variable $db is used to submit this connection.

mysql_select_db () Specifies the query that the database uses later. The function mysql_query () is to send SQL queries to MySQL for execution, and the result is returned and stored in the variable $result.

The last mysql_result () function is the result.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.