Saturday, March 30, 2019

How to make Database connectivity with PHP ??

What is PHP?

  • PHP is an acronym for "PHP: Hypertext Preprocessor"
  • PHP is a widely-used, open source scripting language
  • PHP scripts are executed on the server
  • PHP is free to download and use

What Can PHP Do?

  • PHP can generate dynamic page content
  • PHP can create, open, read, write, delete, and close files on the server
  • PHP can collect form data
  • PHP can send and receive cookies
  • PHP can add, delete, modify data in your database
  • PHP can be used to control user-access
  • PHP can encrypt data

Steps to create connectivity.

1.Make a database in php my admin.

2.In the text editor create a config.php file and code this 

     <?php

          $SERVER="localhost";
          $USER_NAME="root";
          $PASSWORD="";
          $DATABASE="test_database";

         $conn=mysqli_connect($SERVER,$USER_NAME,$PASSWORD,$DATABASE);

         if(!$conn)
           {
     echo "Could not connect to the database ".mysqli_connect_errno();
           }

      ?>

3.You have successfully created a connection with the database.

Explanation
  
  1. $SERVER="localhost"==>In this the local server ip address is being assigned to 
                                            variable named $SERVER.

  2.$USER_NAME="root"==>In this the username of the  PhpMyAdmin will always be 
                                          root if you are working on the local server.

  3.$PASSWORD=""==>Default password will be null.
  
  4.$DATABASE="test_database"==>Name of the database which you have specified 
                                                      in the phpMyAdmin.

  All these four parameters must be passes inside the mysqli_connect() function            which will return a status object which is stored in $conn variable.

  


                                          
    
  

         
         




How to create Database in PhpMyAdmin ??

 Database connection is a facility in computer science that allows client software to talk to databaseserver software, whether on the same machine or not. A connection is required to send commands and receive answers, usually in the form of a result set. Connections are a key concept in data-centric programming.

For Example 

In PhpMyAdmin database You have to create a database named 'TestDatabase' in PhpMyAdmin. 
Creating a database