1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

php and database

Discussion in 'PHP' started by hardik soni, Jul 30, 2010.

  1. hardik soni

    hardik soni New Member

    Joined:
    Jun 26, 2010
    Messages:
    73
    Likes Received:
    1
    Trophy Points:
    0
    Occupation:
    Writer, SEO
    Location:
    Rajkot,India
    Hello everyone,

    I am new in PHP. I want to know how to establish connection between PHP and any database, Please guide me if you can...

    In Anticipation....
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,293
    Likes Received:
    365
    Trophy Points:
    83
  3. hardik soni

    hardik soni New Member

    Joined:
    Jun 26, 2010
    Messages:
    73
    Likes Received:
    1
    Trophy Points:
    0
    Occupation:
    Writer, SEO
    Location:
    Rajkot,India
    All right nice info from that site
    but can anybody let me know something in your own language for the same topic ?

    Thanks.
     
  4. johnny.dacu

    johnny.dacu New Member

    Joined:
    Jul 6, 2010
    Messages:
    88
    Likes Received:
    4
    Trophy Points:
    0
    well... is simple. to estabish a mysql connection use:
    PHP:
    mysql_connect("server","username","password")
    to select a database:
    PHP:
    mysql_select_db("db_name");
    to perform a mysql query:
    PHP:
    mysql_query("query string");
     
  5. ManzZup

    ManzZup New Member

    Joined:
    May 9, 2009
    Messages:
    278
    Likes Received:
    43
    Trophy Points:
    0
    Occupation:
    Production Manager:Software @ ZONTEK
    Location:
    Sri Lanka
    Home Page:
    First you need to make a database from your admin panel. (hope you know to do that)

    Then the following script would give the basic concept of connecting:

    PHP:
    <?php

    $username 
    "your_db_username";
    $password "your_db_password";
    $database "your_database_name";
    $host "your_host_address";

    $db_handle mysql_connect($host$username$password);
    $db_found mysql_select_db($database$db_handle);

    if(
    $db_found){
         print 
    "Auuraah You sucessfully connected!";
         
    mysql_close($db_handle);
    }else{
         print 
    "ahh Try Again!!";
    }
    ?>
     

Share This Page