Results 1 to 2 of 2

Thread: connecting to mysql database

  1. #1
    Join Date
    Sep 2008
    Location
    harare,zimbabwe
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default connecting to mysql database

    hie i'm a newbie and am having a problem connecting to my database..
    the name of my database is wilsoft and it does not have a password..here is my code:
    <html><?php
    mysql_connect("localhost", "root", "") or die(mysql_error());
    echo "Connected to MySQL";
    ?>

    </html>


  2. #2
    Join Date
    Sep 2008
    Posts
    56
    Thanks
    0
    Thanked 6 Times in 6 Posts

    Default Re: - connecting to mysql database

    Hi,

    If executing this code you are getting output as "Connected to MySQL" means you are connected to the MySQL server, now the next step is selecting the database.

    To select the database ythe function provided by PHP is mysql_select_db("name of the database"). Thus after add this line

    mysql_select_db("") or die ("could not select database");

    Once this is done you can then use PHP function mysql_query() to fire a query on the selected database and may use mysql_fetch_array() to fetch the result if you are firing a select query.

    Hope this is helpful.

    Cheers,

    ~Maneet
    LeXolution IT Services (P) Ltd.
    Web Development Company

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •