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.