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.

Read Also:  vue js Shorthand If/Else Using Ternary Operators (?:)

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.

MySQL Connection Using (MySQLi Object Oriented)

PHP Connect to MySQL Database

$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)

$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

$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);
    echo "Your Dabase Connected successfully";
catch(PDOException $e)
    echo "Sorry Dear, Connection failed: " . $e->getMessage();

Web Programming Tutorials Example with Demo

Read :

Read Also:  PHP MySQL Database Connectivity Examples


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 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.

Related FAQ

Here are some more FAQ related to this Article:

  1. Read Also:  PHP Laravel 7 Inner Join Query Example (join query in laravel)
  2. Read Also:  insert delete image from folder in php with jQuery
  3. Read Also:  Custom Helper Functions in Laravel 6 Example
  4. Read Also:  PHP MySQLi Database Connection
  5. Read Also:  Jquery Count Child Elements with class
  6. Read Also:  Laravel 6 Allow CORS All requests Middleware Tutorial
  7. Read Also:  Eloquent Order By Relation Column in Laravel
  8. Read Also:  laravel clear cache using Terminal/Command Prompt
  9. Read Also:  pagination code in php with next and previous demo
  10. Read Also:  Laravel get multiple checkbox value From View to Controller