• Archives

  • AddThis Social Bookmark Button

    Add to Technorati Favorites

  • Upcoming Conferences

    • no upcoming events
  • Connecting to a database

    By krates | December 18, 2007

    Connecting to a database through php is not a tough task.

    First off all create a new sql database in phpmyadmin and see the privileges section in it for the user/pass by default it is

    Username == “root”

    Password == “”

    In php you need this and your host name it is always localhost

    Syntax:


    $host = "localhost"; //Host name
    $username = "root"; // Username
    $pass = ""; //Password
    $dbname = "useless"; //Database Name

    $connect = mysqli_connect ($host,$username,$pass,$dbname);
    if(! $connect)
    {
    echo “unable to connect to the database”;
    }
    else{
    echo “Connected to database”;
    }
    ?>
    The above script will connect you to the database note you must php 5
    because it uses mysqli functions

    Thanks
    krates

    Share and Enjoy:
    • Digg
    • del.icio.us
    • Facebook
    • NewsVine
    • Reddit
    • StumbleUpon
    • YahooMyWeb
    • Google Bookmarks
    • Yahoo! Buzz
    • TwitThis
    • Live
    • LinkedIn
    • Pownce
    • MySpace

    Topics: PHP | Comments Off

    Related Links:

    Comments are closed.