Connecting MySQL with PHP




Connection to a MySQL database can be attempted in PHP with a standard piece of script that describes four connection parameters of host , user name , password and database name . Upon failure the script provides a descriptive message , whereas on success it specifies the character set to be used when sending data to and from the database server 
       
      Query
                $connection = mysqli_connect ('localhost','username','password','database');
                   
You need not understand in details how the script works at this stage but recognize that it contains sensitive information . For this reason it should not be placed
in the web server WWW directory like all others PHP script , where its contents may be accessible but placed instead safely in /WWW parent directory .
 
For Example
          in the App Server directory rather than in the 
                   "C:/AppServer/WWW" directory .
 Any PHP script can incorporate another PHP Script by using a required statement to specify the other script path . This feature can be used to good effect to incorporate the connection script without revealing its sensitive information .


    Launch plain text editor and create a connection script describing the parameters from the previous pages 
         
        <?php
                     $connection = mysqli_connect('localhost','root','admin@123','site_db');
                      if($connection)
                          {
                                  echo Connection Successful
                          }
                     else
                            {
                                  echo Connection Failed
                             }
          ?>

                                           

        Connection Successful MySQL With PHP 
                 




Comments

Post a Comment

Popular posts from this blog

Switching Branches