Web Design Forums

Welcome! Please register or log in: Forgot your password? Why register?
You are here: Web Design Forums » Programming Help » PHP » How to Connect Databse With PHP RSS

How to Connect Databse With PHP

This thread was started by Smith and has been viewed 649 times, and contains 5 replies, with the last reply made by smoseley.
Post Reply
1
View Smith's reputation
Posted June 23 '09 at 07:59 AM
      Posts: 2
Hi all this is Smith,
Can any one tell me how to connect a database with PHP. I need basic steps and program code to connect database in PHP.
Last edited June 23 '09 at 08:16 AM by Smith. Reply

Advertisement Register for free to hide these ads and participate in discussions!

2
1,251 points at 99% Moderator Repute
mlseim, WDF Moderator Private message  
Posted June 23 '09 at 03:39 PM
      Posts: 3,100
Are you talking about MySQL specifically?
If it's zero degrees outside today, and it's supposed to be twice as cold tomorrow, how cold is it going to be?

3
32 points at 100%
Posted June 23 '09 at 06:05 PM
      Posts: 76
PHP I'm assuming MySQL...

<?php
$host 
''//Hostname prob localhost
$user ''//Username for database
$pass ''//Password for database
$db ''//The Database Name...

// This will determine if the DB conection was successful....
if(connectMySQL($host,$user,$pass,$db) != FALSE)
    { 
// If its successful....
    
echo('Good to go!');
    } else { 
// If not, then halt the script but not before we let the user know.
    
echo('We got some problems!');
    die();
    }
////////
//
//
//
//
// Put your content here!
//
//
//
//
////////

// Put your functions at the bottom.
function conntectMySQL($host,$user,$pass,$db)
    { 
// This function combines the MySQL connect and DB select functions built-into php.
    
$link mysql_connect($host$user$pass);
    if(isset(
$link))
        {
        
$db_sel mysql_select_db($db);
        if(isset(
$db_sel))
            {
            return 
$db_sel;
            } else {
            return 
FALSE;
            }
        } else {
        return 
FALSE;
        }
    }

mysql_close(); // ALWYAS ALWAYS ALWAYS RUN THIS AT THE END OF THE SCRIPT.
?>
Lead Web Designer
MLW & Associates, LLP.
W3C Standards Complaint and SEO Friendly
Admin of Vraul
Last edited June 23 '09 at 06:08 PM by Danny[MLWA]. Reply

4
View Smith's reputation
Posted June 23 '09 at 11:31 PM
      Posts: 2
i asked about MySql only. Thank you

5
1,251 points at 99% Moderator Repute
mlseim, WDF Moderator Private message  
Posted June 24 '09 at 03:40 PM
      Posts: 3,100
Smith ...
Danny has the correct answer to your question.
If that's not what you wanted, let us know.
If it's zero degrees outside today, and it's supposed to be twice as cold tomorrow, how cold is it going to be?

6
1,325 points at 100% Repute WDFplus Member
Posted June 24 '09 at 10:39 PM
      Posts: 8,437
Research PEAR MDB2 - it's the best database connection component available for PHP. It's equivalent to Perl DBI.
Steven Moseley
President, Transio

Post Reply

Similar Threads
Thread Thread Starter Forum Replies Last Post
Top 21 PHP Programming mistakes thexchord PHP 18 March 10 '10 08:52 AM
PHP Jobs Opportunity in Delhi, India Value One Request a Service 0 August 16 '04 06:30 AM
php vs. cfm gar598 PHP 1 April 2 '04 11:49 AM
PHP & Multiple databases Samibouni PHP 1 December 9 '03 05:37 PM
Basic PHP Uploads Tutorial thexchord Coding Articles & Tutorials 2 May 2 '02 08:28 PM