Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    New Coder
    Join Date
    Nov 2005
    Location
    Louisville, Kentucky
    Posts
    94
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Connecting to a mySQL DB

    When I try to connect to my database (myhomepageUsers) i get this error:

    Warning: mysql_connect() [function.mysql-connect]: Unknown MySQL server host 'myhomepageUsers' (11001) in c:\program files\e-novative\WAMP\www\mySQL\index.php on line 5

    with this code:
    PHP Code:
    mysql_connect("myhomepageUsers"); 
    I don't understand why this happens because the database exists. Can anybody please help me?



    EDIT:
    Also, how would i retreive data from a table in a database?
    Last edited by Ramesiv; 01-03-2006 at 09:39 PM.
    What was I thinking?
    Email Me

  • #2
    Senior Coder
    Join Date
    Apr 2005
    Location
    Colorado, United States
    Posts
    1,208
    Thanks
    0
    Thanked 0 Times in 0 Posts
    "$question = ( to() ) ? be() : ~be();"

  • #3
    New Coder
    Join Date
    Dec 2005
    Posts
    33
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Your connection should look something like this:

    PHP Code:
    $connection mysql_connect('localhost here','username here','password here');
    if (!
    $connection) {
    die( 
    '<p>Access denied! Database Connection Error: ' mysql_error() . '</p>');


  • #4
    Senior Coder
    Join Date
    Apr 2005
    Location
    Colorado, United States
    Posts
    1,208
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You can simplify that a lot with a simple or.

    PHP Code:
    <?php
    $connection 
    mysql_connect('localhost','username','password') or die('Error connecting to database: ' mysql_error());

    // Also have to select the database.
    mysql_select_db('database');
    ?>
    "$question = ( to() ) ? be() : ~be();"

  • #5
    New Coder
    Join Date
    Nov 2005
    Location
    Louisville, Kentucky
    Posts
    94
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yes i know, i reframed my code to something similar to that, I can connect to the server, but I cannot connect to the db, this i do not understand, do i need to export it or somthing?
    Last edited by Ramesiv; 01-03-2006 at 09:37 PM.
    What was I thinking?
    Email Me

  • #6
    New Coder
    Join Date
    Oct 2005
    Posts
    58
    Thanks
    0
    Thanked 0 Times in 0 Posts
    post your connection code (without your u/p, or other personal data)

  • #7
    New Coder
    Join Date
    Nov 2005
    Location
    Louisville, Kentucky
    Posts
    94
    Thanks
    0
    Thanked 0 Times in 0 Posts

    DB Connection Code

    PHP Code:
    $user "username";
    $pass "password";
    $db "homepage_users";
    $link mysql_connect "localhost"$user$pass );
    if ( ! 
    $link ) {
        die ( 
    "Cound not connect ".mysql_error() );
    }
    print 
    "<h2>Successful Connection to server</h2>";
    mysql_select_db$db$link )
        or die ( 
    "Cound not connect to database." );
    print 
    "<h2>Successful Connection to database</h2>";
    mysql_close$link ); 
    What was I thinking?
    Email Me

  • #8
    New Coder
    Join Date
    Dec 2005
    Posts
    36
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Try this way:
    PHP Code:
    <?

    $host 
    'localhost';
    $user 'user';
    $pass 'password';
    $db 'db';

    $m_connect = @mysql_connect($host,$user,$pass) or die ("Error while trying to connect to mysql: " mysql_error());

    $select_my_db = @mysql_select_db($db,$m_connect) or die ("Error selecting database: " mysql_error());

    ?>
    Last edited by Prikid; 01-03-2006 at 09:09 PM.

  • #9
    New Coder
    Join Date
    Nov 2005
    Location
    Louisville, Kentucky
    Posts
    94
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ~ Never mind, I've got it sorted, thank you all very much for your help ~
    What was I thinking?
    Email Me


  •  

    Posting Permissions

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