PHP Snippets

Name:MySQL Connect
Description: Here's an easy example of MySQL database connection.

Code below...
> <?php

   
//Save the file as db_connect.php

   //Username
   
$db_user 'username';
   
//Username password
   
$db_pass 'password';
   
//Database host
   
$db_host 'localhost';
   
//Database name
   
$db_name 'database_name';

   
//Connect to database
   
$db mysql_connect($db_host,$db_user,$db_pass); 
  
//Select the database
   
mysql_select_db($db_name) or die("Cannot connect to database");

  
//Now to include this to your file(s) all you have to do is to use php include function: include("db_connect.php"); 

?>

« Back to PHP Snippets

Home | Site Map | Privacy Policy | Advertising | Contact Us
Copyright © 2006-2014 r2xDesign.net - All Rights Reserved.
eXTReMe Tracker