TechMynd, Fresh Downloads and Latest Technology News, Stuff That Works | Downloads, Tips & Tricks, Softwares, Programming, Resources, IT, Computer, Resources, Freewares

PHP Easy Most Database Connection



Setting up a database connection can be a difficult task if you google through different codes present online.
Here is the easy most method to create a dbconnection for PHP and mysql.

<?php
/* Online settings

$db = mysql_connect(”localhost”, “root”, “password”);
mysql_select_db(”dbname”,$db);
$siteurl =
http://javedkhalil.com/;
*/
/* Local settings */
$siteurl =
http://javedkhalil.com;
$db = mysql_connect(”localhost”, “root”, “”);
mysql_select_db(”dbname”,$db);
?>

Always write code both for Online and Local usage. Comment the code which is not being used. Also use siteurl variable and store website root path in it. It comes very very handy in times. We have to use many times website name inside the pages.
Now you can save this code in a file named like dbcon.php or whatever you like and include this file in php pages where you want to use dbconnection by this.

<?php Include (”dbcon.php”); ?> Here you are done.Another very simple code for dbconnection if you like, I am writing it here.

<?
$con=mysql_connect(”localhost”,”root”,”")or die(”Unable to connect”);
mysql_select_db(”dbname”,$con)or die(”Unable to open database”);
?>

This easy way to connect from mysql database through PHP will give a message if the connetion is not established.

Tags: ,
Posted in: PHP, mySQL
Post's RSS » RSS 2.0
Post's Comments RSS » RSS 2.0

Related Posts


One Response to “PHP Easy Most Database Connection”

  1. Apr 20, 2008
    Alexander Says: Reply to this comment

    This is one of the best sites I have ever found. Thanks!!! Very nice and informal. I enjoy being here.

Post a Comment

Comment will appear here after approval, Thanks for patience

  Subscribe Via RSS
  Subscribe Via Email

Add to Technorati Favorites

Donate towards TechMynd web hosting Bill!