A simple example _php example of PHP connecting to the LAN MySQL database

Source: Internet
Author: User

Copy Code code as follows:

$conn =mysql_connect (' 192.168.0.220 ', ' root ', ' 123 ');
if (! $conn) echo "Failed!";
else echo "Success!";

An SQL statement that extracts information from a table
$sql = "SELECT * from user where username= ' $user _name '";
Execute SQL query
$result =mysql_db_query (' info ', $sql, $conn);
Get query Results
$row =mysql_fetch_row ($result);
Mysql_close ();

The first line of IP corresponding LAN a host, about the local area network MySQL connection can refer to my excerpt.

Line $user_name is the foreground pass parameter, the composition condition query, here uses the double quotation mark variable conversion.

From JSP to PHP, either way, the steps associated with a database connection are roughly:

"Host, username, password" gets connected, "database, SQL, connection" Gets the result, and finally is the result of the processing display. Of course, the database connection is the extension library for us to do, we can only do is to deal with the results.

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.