Left Quote    Nearly all men can stand adversity, but if you want to test a man's character, give him power.
- Abraham Lincoln    
Right Quote
[login] | [Register]

Database Connection

by: bs0d


This is the code you will use to connect to your database. You will need to connect to the database you will store information in (such as users online, ect.)

It is recommended that when coding in PHP, you have this code seperate from the rest and name it 'connect' or 'db-connect' or whatever.

Then, in your source code, your first line would look something like: require_once('db_connect.php');


$table ="table1";

$connect mysql_connect($database['dbserver'], $database['dbuser'], $database['dbpass']);




  Subject: "Purpose of red text" Date: Mar 01 2007 at 7:27 pm    
In the code, what is the purpose of using red text? What does it indicate?
  Subject: "red text" Date: Apr 20 2007 at 12:49 am    
I'm no pro, but I'm pretty sure his php editor highlights syntax.
  Subject: "colors" Date: Jun 12 2007 at 7:23 am    
Actually I believe that the red code signifies information that is dependent on your system configuration and naming structure as it is set up on your localhost or otherwise.

  Subject: "" Date: Oct 28 2007 at 9:48 pm    
The server is a website? I thought it would have been something like //servername/My SqldatabaseName / or what does .com mean ?? Am new in PHP anyway?
  Subject: "Your Website" Date: Oct 30 2007 at 6:48 pm    

Put in your domain name.
  Subject: "dbserver" Date: Feb 26 2008 at 2:54 pm    
To begin with, kudos, bs0d! I've read a couple of your articles, some of them several times, and have found them insightful. However, to the last question that was asked, about what dbserver ( entails, it was not my domain name, as you had suggested. Rather, it was the server name of my host. (In my case, sql1.bravehost. com). I literally spent about three hours trying different variants of the domain name (with and without "www&quo t; etc.) before I consulted my host's help forum section and discovered that I had to use the server name. Those of you who want to retain your sanity (I was on the verge of losing it!) should check your host's specific requirements -- since I assume it's different from host to host. Peace all.
  Subject: "CAN IT BE DONE LIKE THIS? IS IT POS..." Date: Feb 29 2008 at 7:30 pm    

$dbserver=&quo t; quot;;
$dbuser=" user";
$dbname=" database_1&quo t;;
$dbpass=" password" ;
$table ="table1 ";

$connect = mysql_connect( '$dbserver',' $dbuser','$db pass');

$select= mysql_select_db ('$dbname');< br /> ?>
  Subject: "connect to a database from LAN Serv..." Date: Jan 26 2009 at 11:06 am    
i am a beginner, can i ask how to connect to a database from a server..LAN. or from your own system..
  Subject: "No idea, lost" Date: Aug 01 2009 at 6:16 pm    
What do you put for the dbserver? i tried my domain, my db name, my db user nothing works!!!! help please
You Must be signed in or a member to comment.

Code Stats

Code Stats

9 Total Comments
0 Rating of 5 (1 Votes)


Code Options

· Login to Rate This Code
· Login to Post a Comment
· Read more by this author
Digg This Code! Bookmark This Code Reddit: Bookmark This Code! BlinkList: Blink This Code! YahooMyWeb BlogMarks: Add This Mark! Furl: Save This Code Spurl: Mark This Code!

Code Samples


· Users Online
· Pagination
· Comments Script
· IdealMySQL Class for PHP 5.0

"" Copyright © 2002-2021; All rights lefted, all lefts righted.
Privacy Policy