Gray Hat World - Internet Marketing Forum
    home search help facebook twitter

Gray Hat World - Internet Marketing Forum » General Computer Discussion » Graphics And Design » Website Construction » [php]Database connexion function
Current time: 05-23-2013, 03:27 PM Hello There, Guest! (Login — Register)

Register for full access and no ads



Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Threaded Mode | Linear Mode
[php]Database connexion function
08-28-2009, 09:47 AM
Post: #1
sasuke
Unregistered
 
[php]Database connexion function
Hello!!
in this tuto I'm gonna explain how to make connection to your database using PHP

1-connexion script
to start open your text editor
copy and past this code:
Code:
<?

$hostname = "localhost";
$database = "database_name";
$username = "your_username";
$password = "your_password";

// Open a connection to the server
$connection = mysql_connect($hostname, $username, $password) or die ("Unable to connect to the DB Server!");


// Select the database
mysql_select_db($database) or die ("Can't select database!");
?>
the first part of the code
$hostname = "localhost"; --->leave "localhost" or put your local ip 192.168.x.x if you're using your computer as a host
$database = "database_name";--->enter the name of db you are going to use
$username = "your_username";--->enter your username (root is the default username of mysql"
$password = "your_password";--->enter your mysql password (leave it blank if you didn't edit it before)
the second part of the code
Code:
$connection = mysql_connect($hostname, $username, $password) or die ("Unable to connect to the DB Server!");
it's a mysql query wich make the connexion to MYSQL server
the third part
Code:
mysql_select_db($database) or die ("Can't select database!");

it will select the dabatase.

Note!!: you can use this code also for MSSQL server by replacing "mysql" with "mssql"
2-the include form
after pasting the code into your text editor save it as con.php
now if you wanna use this code for a php page,all you have to do is to add this code at the begining of the page
Code:
<?php
include "con.php";

?>
Quote this message in a reply
08-28-2009, 01:24 PM
Post: #2
Papercut Offline
N00B
*
Posts: 206
Joined: Aug 2009
Reputation: 0
Experience: 2583
RE: [php]Database connexion function
this might come in-handy someday (for me)^^
Find all posts by this user
Quote this message in a reply
09-12-2009, 07:33 AM
Post: #3
Zubair Ali
Unregistered
 
RE: [php]Database connexion function
Hi,
Mr. sasuke

Good work keep tech it...
Quote this message in a reply
10-17-2009, 11:32 PM
Post: #4
Sora Offline
h4x0r
Posts: 65
Joined: Oct 2009
Reputation: 0
Experience: 180
RE: [php]Database connexion function
Thank you.

Keep on working!

[Image: soradnj.jpg]
Visit this user's website Find all posts by this user
Quote this message in a reply
11-26-2009, 07:46 PM
Post: #5
evilalex Offline
I <3 Money
*****
VIP
Posts: 46
Joined: Aug 2009
Reputation: 2
Experience: 379
RE: [php]Database connexion function
thanks for this

[Image: 2ugh0gp.png]
Selling many, many steams. PM me.
Find all posts by this user
Quote this message in a reply
12-20-2009, 02:25 AM
Post: #6
DesperateSoul Offline
Subscriber
*****
VIP
Posts: 335
Joined: Nov 2009
Reputation: 2
Experience: 1841
RE: [php]Database connexion function
this is great

[Image: my%20banner.jpg]
Find all posts by this user
Quote this message in a reply
01-02-2010, 04:23 PM
Post: #7
Dustyclaws Offline
Litte Baby
Posts: 54
Joined: Jan 2010
Reputation: 0
Experience: 505
RE: [php]Database connexion function
i dont get it o.0
Find all posts by this user
Quote this message in a reply
03-01-2012, 02:48 AM
Post: #8
Column Offline
Litte Baby
Posts: 3
Joined: Mar 2012
Reputation: 0
Experience: 40
RE: [php]Database connexion function
Life
  --- By Allan Houston
  Life can be good,
  Life can be bad,
  Life is mostly cheerful,
  But sometimes sad.
  Life can be dreams,
  Life can be great thoughts;
  Life can mean a person,
  Sitting in court.
  Life can be dirty,
  Life can even be painful;
  But life is what you make it,
  So try to make it beautiful.
Dream
  --- By Allan Houston

  Hold fast to dreams,
  For if dreams die
  life is a broken-winged bird
  That cannot fly.

  Hold fast to dreams,
  For when dreams go
  life is a barren field
  Forzen with snow.
Flower Girl DressesEmpire Wedding DressesNew Style Wedding DressesColumn Wedding Dresses
Find all posts by this user
Quote this message in a reply
« Next Oldest | Next Newest »
Post Reply 


  • View a Printable Version
  • Send this Thread to a Friend
  • Subscribe to this thread
Forum Jump:


User(s) browsing this thread: 1 Guest(s)

Contact Us | Gray Hat World - Internet Marketing Forum | Return to Top | Return to Content | Lite (Archive) Mode | RSS Syndication

Powered By MyBB, © 2002-2013 MyBB Group.
Theme By GFX Palace.