PHP CRUD OPERATIONS (FIRST PAGE : connection.php)

 PHP CRUD OPERATIONS (FIRST PAGE : connection.php)

Hi All,
          Good Evening to all of you. Welcome back to my blog after a long span of time.
                             So, today firstly I am going to discuss about CRUD Operation in PHP.
                                          So, what is CRUD Operation in PHP?
                                                                                                 CRUD Operation in PHP is Create, Read, Update And Delete. So, in CRUD Operation I will make many pages separately for Create, Read, Update And Delete. But, today I will just show and discuss about the connection page of CRUD Operation and other pages I will show and discuss in my upcoming blogs.
                                                                         Here, in CRUD Operations I will work in procedural way and for working in procedural way I need to have some driver functions.
                                                                                          So, here the driver function which I will use is mysqli and it's the improved version of MYSQL.

                              So, now lets discuss about our connection page i.e. connection.php. Basically connection page is to connect between SQL Server Database and PHP.

                                                                 Now you can ask me what is Database and PHP.

                                  So, Database is the SQL Server and PHP is the backend language. So basically in connection.php page we need to connect between SQL Server Database and PHP Backend Language.

                So, let's get started with the connection page(connection.php).

connection.php:

<?php

$servername="localhost"; // So, here $servername is the variable name and localhost is the server name and the IP Address of localhost is 127.0.0.1.

$username="root"; // So, here $username is the variable name and root is the username, as shown in the image below of SQL Server Database.


$password=""; // Here, $password is the variable name and here in case for windows we don't have any password so the password field is blank in case of windows.
$db="php web development batch"; // This field of Database is variable as because whathever database name we will create in MY SQL database, that name only we need to provide in connection page.


Now suppose 4 employees were going to office in Sector V TCS by car, one employee has seated in front beside driver seat and the other 3 employees were seated at back. So, the 4 employees can't reach to Sector V TCS office without driver and for reaching to Sector V TCS Office the 4 employees need a driver.
                                                                                   Similarly, here also 4 variables need a driver functions to connect with MY SQL Server Database. So, here the driver function is mysqli_connect().

mysqli_connect($servername,$username,$password,$db);

So, now here we need to put this mysqli_connect($servername,$username,$password,$db) inside one variable that is $conn.
                                           Now you can ask me why I have taken $conn variable only why not other variable name because, we need to take the variable name which is user-friendly and easy to access.

$conn=mysqli_connect($servername,$username,$password,$db);

Now, we need to check the condition of $conn by using if else statement

if($conn)
{
     echo "Connection Successfully";
}
else
{
     echo "Connection Failure";
}
?>

Here it is not necessary to write the else part, but it's totally depending up to you. But here I have written the else part.
                                                                                               So here if the $conn condition matches it will print Connection Successfully otherwise it will print Connection Failure.

CODE:

<?php
$servername="localhost";
$username="root";
$password="";
$db="php web development batch";
$conn=mysqli_connect($servername,$username,$password,$db);
if ($conn) {
echo "Connection Successfully";
}
else{
echo "Connection Failure";
}
?>


Output Page:


NOTE: Suppose here in username we have provided rootmhfgrhehvb instead of root it will show me that the user name does not exists and it will throw me the error. Means in the first 4 lines of variable declaration whatever mistake we will do it will show us the exact error along with the name.

 






 
                                                                                                          






Comments

Popular posts from this blog

Programmings Based On Array And String Functions To Merge The 2 Arrays, Then After Merge Convert Into String And Then Find Out The 1st And Last Word From The Reverse String

PHP WEB DEVELOPMENT INTERVIEW QUESTIONS ASKED IN APOLLO HOSPITAL ALONG WITH MY OWN CONCEPTS AND MY OWN EXPLANATION ANSWERS(PART - 1) REST OF THE QUESTIONS AND ANSWERS WILL BE PREPARED BY ME IN MY NEXT BLOG

Mini Project On Multi User CRUD Operations(Create, Read, Update & Delete) Of Donar Details Of Indian Nationals Who Donate To Ramkrishna Math, Belur Math Using PDO (PHP Data Objects) With Proper Explanation Of Each And Every Individual Line Of The Code Of connection.php Page, form.php Page, formaction.php Page, admin_display.php Page, client_display.php Page, edit.php Page, editaction.php Page And delet.php Page (Here You Will Find The Image Of Sayang Sri Ramkrishna Dev, Sayang Sri Ma Sarada Devi & Sayang Sri Swami Vivekananda) In My CRUD Operation