For connection with MySQL, mysqli_connect() function is used in PHP.
Syntax:
mysqli_connect(server, username, password, databasename);
Parameters Details:
server: The host name running database server. If not specified then default value is localhost:3306.
username: The username accessing the database.
password: The password accessing the database.
databasename: Mention your Database name.
It returns a MySQL link identifier on success, or FALSE on failure.
For Closing Database connection, mysql_close() function is used in PHP.
Syntax:
mysql_close ( resource $link_identifier );
It returns TRUE on success and FALSE on failure.
Following code describes the opening and closing connection of MySQL with php.
<?php
define('DB_SERVER', 'localhost:3306');
define('DB_USERNAME', 'root');
define('DB_PASSWORD', '');
define('DB_DATABASE', 'db_doctor_appointment');
$con = mysqli_connect(DB_SERVER,DB_USERNAME,DB_PASSWORD,DB_DATABASE);
if(! $con ) {
die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_close($conn);
?>
Syntax:
mysqli_connect(server, username, password, databasename);
Parameters Details:
server: The host name running database server. If not specified then default value is localhost:3306.
username: The username accessing the database.
password: The password accessing the database.
databasename: Mention your Database name.
It returns a MySQL link identifier on success, or FALSE on failure.
For Closing Database connection, mysql_close() function is used in PHP.
Syntax:
mysql_close ( resource $link_identifier );
It returns TRUE on success and FALSE on failure.
Following code describes the opening and closing connection of MySQL with php.
<?php
define('DB_SERVER', 'localhost:3306');
define('DB_USERNAME', 'root');
define('DB_PASSWORD', '');
define('DB_DATABASE', 'db_doctor_appointment');
$con = mysqli_connect(DB_SERVER,DB_USERNAME,DB_PASSWORD,DB_DATABASE);
if(! $con ) {
die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_close($conn);
?>
0 Comments