Thursday, October 18, 2012

Mysql Database Connection in PHP

10/18/2012

This is a simple example of how you could create a database connection from PHP to MySQL. It is good to save the MySQL Database Connection in a seperate php file in a secure part of the website. Then the file can be referenced in any page that requires a connection to the database file or This will save you from having to retype the details on every page and makes code reusable.
<?php
/* 
Online PHP Examples with Source Code
website: http://4evertutorials.blogspot.in/
*/

//MySQL database hostname (i.e.: Localhost)
$db_host='';
 
//MySQL database name (i.e. database)
$db_name='';
 
//MySQL database username (i.e. user)
$db_user='';
 
//MySQL database password for the user above
$db_pass='';
 
//Initialize connection
$connection = mysql_connect($db_host, $db_user, $db_pass) or die ('Error');
mysql_select_db($db_name);


?>

helpful? Share this

The Editorial Team of 4everTutorials consists of a group of PHP Professionals.

0 comments:

 

© 2014 4everTutorials. All rights resevered.

Back To Top