Advertisement
Guest User

Untitled

a guest
May 15th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.94 KB | None | 0 0
  1. In a file called dbconnection.php or anyother fiting name:
  2.  
  3. <?php
  4.     //Set strings for host, user, password and database name for access to
  5.     //the database.
  6.     $dbHost='localhost'; //The host name - for the time being localhost will do the job.
  7.     $dbUser ='root'; //The name of user accessing the database - root normally has no restrictions.
  8.     $dbPassword='password'; //Use '' if no password is set. Must be the matching user password.
  9.     $dbName='database_name'; //Can not be NULL - you must enter a valid database name.
  10.    
  11.     //Connect to the database server.
  12.     $dbCon = @mysql_connect($dbHost, $dbUser, $dbPassword);
  13.         if(!$dbCon){
  14.             echo("<p>Cannot conect to the database server.</p>");
  15.             exit();
  16.         }
  17.    
  18.     //Connect to the database.
  19.     mysql_select_db($dbName, $dbCon);
  20.     if(!@mysql_select_db($dbName)){
  21.         echo("Cannot locate ".$dbName." database.</p>");
  22.         exit();
  23.     }
  24. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement