Search
Left Quote    Wise men speak because they have something to say; Fools because they have to say something.
- Plato (427-347 B.C.)    
Right Quote
 
[login] | [Register]
 

Database Connection

by: bs0d
 

Description:


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');

Code:
<?php

$database
[dbserver]="website.com";
$database[dbuser]="user";
$database[dbname]="database_1";
$database[dbpass]="password";
$table ="table1";

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

$select= mysql_select_db($database['dbname']);
?>


 


Comments:

  Stodgrgg
  Subject: "Purpose of red text" Date: Mar 01 2007 at 12:27 pm    
In the code, what is the purpose of using red text? What does it indicate?
  jcpatella
  Subject: "red text" Date: Apr 19 2007 at 5:49 pm    
I'm no pro, but I'm pretty sure his php editor highlights syntax.
  duece
  Subject: "colors" Date: Jun 12 2007 at 12: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.


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

Put in your domain name.
  dvbernard
  Subject: "dbserver" Date: Feb 26 2008 at 7:54 am    
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 (website.com) 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" 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.
  moonshadow
  Subject: "CAN IT BE DONE LIKE THIS? IS IT POS..." Date: Feb 29 2008 at 12:30 pm    
<?php

$dbserver="website.com";
$dbuser="user";
$dbname="database_1";
$dbpass="password";
$table ="table1";

$connect = mysql_connect('$dbserver','$dbuser','$dbpass');

$select= mysql_select_db('$dbname');
?>
You Must be signed in or a member to comment.


Code Stats

Code Stats

18,075 Views
7 Total Comments
0 Rating of 5 (1 Votes)

Options

Code Options

· Login to Rate This Code
· Login to Post a Comment
· Read more by this author
Digg This Code! Del.icio.us: 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

Related    

· Myspace Phishing System
· pear database connection implmentation
· IdealMySQL Class for PHP 5.0
· CAPTCHA Image
· view php source




Personal Loans - Loans - Internet Marketing - Credit Card Consolidation

"AllSyntax.com" Copyright © 2002-2007; All rights lefted, all lefts righted.
Privacy Policy  |  Internet Rank