Connect PHP Code with DataBase
Advertisements
Connect PHP Code with DataBase
mysqli_connect() function is used to connect php code with MySQL database. It returns resource if connection is established otherwise null.
Syntax
resource mysqli_connect (server, username, password)
PHP mysqli_close()
mysqli_close() function is used to disconnect php code with MySQL database. It returns true if connection is closed otherwise false.
Syntax
bool mysqli_close(resource $resource_link)
Connect php code with MySQL Database
Example to connect php code with MySQL Database
<?php $servername = "localhost"; $username = "username"; $password = "password"; // Create connection $conn = mysqli_connect($servername, $username, $password); // Check connection if (!$conn) { die("Connection failed: " . mysqli_connect_error()); } echo "Connected successfully"; mysqli_close($conn); ?>
Google Advertisment