MySQL OOP PHP Connection. Code example open

MySQL OOP 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 +

The MySQLi library provides way to connect to a MySQL database. You can use two approaches: procedural and object-oriented.

PHP OOP connection:

$conn = new mysqli("localhost", "root", "password");

Let’s check if the connection is made:

if ($conn->connect_error) {
  die("Connection failed: " . $conn->connect_error);
} 

Now let’s put it all together and connect to the local MySQL server:

<?php
$conn = new mysqli("localhost", "root", "password");
if($conn->connect_error){
    die("Error: " . $conn->connect_error);
}
echo "Connected";
$conn->close();//closes the connection
?>
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