Home · PHP Scripts · connect to a mysql database

cms-zen dot com

online web development :: art and design :: fun stuff
best-budd
sNews Development cms road trip PHP Scripts Photoshop Guides Css Guides Music and video clips Art Gallery Low Light Photography Impression Photography

connect to a mysql database

This php script will add function to connect to a mysql database.

 
<?php

/**
 * Edit the database settings to your own.
 * To use, just include the function and 
 * call it using <?php db_connect(); ?>
 *
 * You can then do your database queries
 */

    // Edit your database settings
    
$db_host "localhost";
    
$db_user "username";
    
$db_pass "password";
    
$db_name "databasename";

    function 
db_connect() {
        global 
$db_host;
        global 
$db_user;
        global 
$db_pass;
        global 
$db_name;
        
$connection mysql_connect($db_host,$db_user,$db_pass);
        if (!(
mysql_select_db($db_name,$connection))) {
            echo 
"Could not connect to the database";
        }
        return 
$connection;
    }

?>

30.12.2006. 11:26