MySQL PHP Connection. Code example open

MySQL PHP Connection. Code example

Approved. Code works!
This is exactly the working code that is verified by the moderator or site administrators
Tested: PHP 5.6 +

To connect procedurally, the mysqli_connect function is used, which takes the server address, username and password:

Lets connect to DB:

$conn = mysqli_connect("localhost", "root", "password");

Let’s check if we have connected to the Database:

if (!$conn) {
  die("Connection failed: " . mysqli_connect_error());
} 

mysqli_connect_error() – returns error information
mysqli_close() – function to close the connection

Full Code for connection

<?php
$conn = mysqli_connect("localhost", "root", "mypassword");
if ($conn === false) {
  die("Error" . mysqli_connect_error());
} 
echo "Connected";
mysqli_close($conn);
?>
0

More

Leave a Reply

Your email address will not be published. Required fields are marked *

How many?: 22 + 22

lil-code© | 2022 - 2024
Go Top
Authorization
*
*
Registration
*
*
*
*
Password generation