Copy the codeThe code is as follows:
$conn=mysql_connect('192.168.0.220','root','123');
if(!$conn) echo "Failed!";
else echo "Success!";
// SQL statements that extract information from 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 IP corresponds to a host on the LAN. For my LAN connection, please refer to my excerpt.
The sixth line $user_name is a parameter passed by the foreground, which constitutes a conditional query, and a double quote variable conversion is used here.
From jsp to php, no matter which one, the steps related to database connection are roughly:
"Host, username, password" gets the connection, "Database, sql, connection" gets the results, and finally the result is displayed. Of course, database connections are done by the extension library for us, and all we can do is to process the results.