MySQL Connection- Describe MySQL Connection using PHP Script.

Describe MySQL Connection using PHP Script.

Establishing connection to MySQL database using PHP can be done by using
mysql_connect(server,user,passwd,new_link,client_flag).
Here, server specifies the host name where the databae is present.

User and password is the user name and password to connect.

New_link if specified will not require a connection again.

Client_flag can take a number of values like MySQL_CLIENT_SSL, MYSQL_CLIENT_COMPRESS, MYSQL_CLIENT_IGNORE_SPACE, MYSQL_CLIENT_INTERACTIVE.

It is a good practice to close the connection using mysql_close()

Explain the purpose of max_user_connections.

max_user_connections in MySql is used to limit the resources it limits only the number of simultaneous connections made using a single account. A value of 0 means no limit to the number of connections.

Describe MySQL Connection using PHP Script.

The function mysql_connect() establishes the connection to MySQL. To establish the connection, the host name, database user and password is needed. The host is usually a localhost. The ip address 127.0.0.1 can also be specified as the host. The priority depends on the demand.

The following code snippet in PHP describes the connection.
<?php
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = 'password';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
mysql_select_db($dbname);
?>
After establishing the connection, the database needs to be specified. The last statement in the code snippet performs the selection of the database.
MySQL - What is MySQL?
MySQL defined- MySQL can be considered as a relational database management system.
MySQL SELECT Statement
MySQL SELECT Statement - Retrieving Individual Columns, Retrieving multiple Columns, Retrieving ALL Columns, Retrieving Distinct Rows
MySQL sorting data
Sort data: The ORDER BY clause in MySQL can be used to sort the specified column.
Post your comment