Thursday 2 February 2017

Mysql Database connection in php

 Before you can get content out of your MySQL database, you must know how to establish a connection to MySQL from inside a PHP script. To perform basic queries from within MySQL is very easy. This article will show you how to get up and running.

Let's get started. The first thing to do is connect to the database.The function to connect to MySQL is called mysql_connect. This function returns a resource which is a pointer to the database connection. It's also called a database handle, and we'll use it in later functions. Don't forget to replace your connection details.

 Example:
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "studentList";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}
//
?>

3 comments:

  1. I would like to appreciate you for making it very simple and easy
    Regards,
    PHP Training in Chennai | PHP Course in Chennai

    ReplyDelete
  2. I would like to appreciate you for making it very simple and easy
    Regards,
    Java Full Stack in KPHB

    ReplyDelete