MySQL connection

use mysql binary connection

The following is a simple example of connecting to a mysql server from the command line:
After a successful login, the mysql> command prompt window will appear, and you can execute any SQL statement on it.
In the above example, we used the root user to log in to the mysql server, of course, you can also use other mysql users to log in.
If the user privileges are sufficient, any user can perform SQL operations in the mysql command prompt window.
To exit the mysql> command prompt window you can use the exit command.
 
Connect to MySQL using a PHP script
PHP's mysql_connect() function to connect to the database.
The function has 5 parameters, returns the connection ID after a successful connection to MySQL, and returns false on failure.
grammar:
connection mysql_connect(server,user,passwd,new_link,client_flag);
PHP's mysql_close() function to disconnect the MySQL database.
This function has only one parameter, the MySQL connection identifier returned by the mysql_connect() function after the connection is successfully created.
grammar:
bool mysql_close ( resource $link_identifier );
This function closes the non-persistent connection to the MySQL server associated with the specified connection ID. If no link_identifier is specified, the last open connection is closed.
Tip: Using mysql_close() is usually not necessary because open non-persistent connections are automatically closed after the script finishes executing.
Note: mysql_close() does not close persistent connections established by mysql_pconnect().
 
Mysql connection application for php
<html>
<head>
<meta charset="utf-8">
<title>Connecting MySQL Server</title>
</head>
<body>
<?php
   $dbhost = 'localhost:3306'; //mysql server host address
   $dbuser = 'guest'; //mysql username
   $dbpass = 'guest123';//mysql username and password
   $conn = mysql_connect($dbhost, $dbuser, $dbpass);
   if(! $conn )
   {
     die('Could not connect: ' . mysql_error());
   }
   echo 'Connected successfully';
   mysql_close($conn);
?>
</body>
</html>
operation result:


 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326570441&siteId=291194637