PHP MySQL Connect Database Script

Today, We want to share with you PHP MySQL Connect Database Script.In this post we will show you how to connect to phpmyadmin database in php, hear for how to connect html form to mysql database using php we will give you demo and example for implement.In this post, we will learn about php database connection example program with an example.

PHP MySQL Connect Database Script

There are the Following The simple About How to Connect MySQL Database with PHP Website Full Information With Example and source code.

As I will cover this Post with live Working example to develop How to Connect to MySQL Database Using PHP, so the Create a Simple CRUD Database App: Connecting to MySQL with PHP is used for this example is following below.

Read Also:  laravel join Multiple Tables using Model Example

MySQL Connection Using (MySQLi Object Oriented)

PHP Connect to MySQL Database

<?php
$db_host_name = "localhost";
$db_user_name = "applae123";
$db_pass_secure = "applae123$#$%$57854d";

// Create MySQLi connection
$conn = new mysqli($db_host_name, $db_user_name, $db_pass_secure);

// Check MySQLi Database connection
if ($conn->connect_error) {
    die("Sorry Dear, Connection failed: " . $conn->connect_error);
}
echo "Good Luck Connected successfully";
?> 

Note on the object-oriented example above:

//Your MySQL Check connection
if (mysqli_connect_error()) {
    die("Sorry Dear, Database connection failed: " . mysqli_connect_error());
}

MySQL Connection Using (MySQLi Procedural)

<?php
$db_host_name = "localhost";
$db_user_name = "applae123";
$db_pass_secure = "applae123$#$%$57854d";

$conn = mysqli_connect($db_host_name, $db_user_name, $db_pass_secure);

if (!$conn) {
    die("Sorry Dear, Connection failed: " . mysqli_connect_error());
}
echo "Your Dabase Connected successfully";

MySQL Connection Using PDO

<?php
$db_host_name = "localhost";
$db_user_name = "applae123";
$db_pass_secure = "applae123$#$%$57854d";

try {
    $conn = new PDO("mysql:host=$db_host_name;dbname=myDB", $db_user_name, $db_pass_secure);
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    echo "Your Dabase Connected successfully";
    }
catch(PDOException $e)
    {
    echo "Sorry Dear, Connection failed: " . $e->getMessage();
    }

Web Programming Tutorials Example with Demo

Read :

Read Also:  What are OTP Frauds?

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.


I hope you get an idea about Create a Simple CRUD Database App: Connecting to MySQL with PHP.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.