Results 1 to 4 of 4

Thread: connect to mysql

  1. #1
    Join Date
    Oct 2008
    Posts
    22
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default connect to mysql

    Hi there, I am new to mysql and PHP so hope I explain the problem ok. I am just teaching myself mysql and php.

    I want to connect to my database using PHP. I have installed mysql on my pc (using the free mysql download). run it and setup a username of root and no password.

    I have created a basic PHP page just to connect to the database:-

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>test</title>
    </head>
    
    <body>
    <?php
    $dbcnx = @mysql_connect('localhost', 'root', ''); 
    if (!$dbcnx) { 
     echo '<p>Unable to connect to the ' . 
         'database server at this time.</p>'; 
     exit();
    }
    ?>
    </body>
    </html>
    Password left blank as i have not set a password for the database.

    I am running this php file on a server that has PHP support. However the server doesn't have MySQL on so for the reason of learning i have the mysql running on my pc hard disk.

    How can i connect to the database on my pc from my php page running on a server?

    Any info needed just ask...

    thanx

  2. #2
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Ok, don't completely understand what you are saying. You cannot connect from a host to another host's sql host - you must connect from a host to its sql host.
    If you can't get php to work on your localhost - try downloading WAMP.

    Please rephrase your question.
    Jeremy | jfein.net

  3. #3
    Join Date
    Oct 2008
    Posts
    22
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    It was wampserver i needed to solve my problem. I couldn't do it the way i was trying to as database on different server to my php files.

    Thank you for you help. Im just learning sql and php so the wamp server is perfect for me.

  4. #4
    Join Date
    Oct 2008
    Posts
    22
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default resolved

    I dont have the option to resolve a post - not sure why!

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
  •