Cannot connect to Mysql

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts

  • Shawn Wilson
    Guest replied
    Re: Cannot connect to Mysql

    Krista wrote:[color=blue]
    >
    > Hi, I hope you guys can help me out~~~
    > when I run it localhost/config.php, it cannot display any message such
    > as connect successfully or failed. Do u guys have any idea?
    >
    > config.php
    > <html>
    > <head><title>Cr eate Database and table</title></head>
    > <body>
    >
    > <?php
    >
    > $linkID = mysql_connect(" localhost",""," ");
    > print ("hello"); <---can print
    > Hello
    >
    > if($linkID != "FALSE") <--i think
    > fail here
    > {
    > print("The connection to the server was made successfully.)" ;
    > }
    > else
    > {
    > print("The connection to the server failed");
    > }
    >
    > mysql_close($li nkID);
    >
    > ?>
    > </body>
    > </html>
    >
    > am I right? do i need to put username and password in
    > mysql_connect(" localhost",""," ")? i dont know where i can find it, or
    > how can I find it in mysql. Hope you guys can help me out~~ Thanks.[/color]

    Yes, you need to put in a username and password, which you should get from your
    host. Also, you might want to use the "or die" syntax Tom suggested.
    [color=blue]
    > if($linkID != "FALSE")[/color]
    ^^^^^^^^^^ This can be better written as if (!$linkID)

    or you could combine your IF and mysql_connect() statements:
    [color=blue]
    > if (!mysql_connect ("localhost","u sername","pw"))
    > echo "Did not connect to DB";[/color]


    And this line will produce an error if the connection didn't open correctly:[color=blue]
    > mysql_close($li nkID);[/color]
    You can get around that by using the mysql_connect() or die syntax or by
    executing the mysql_close only if $linkID is valid. Or, if you're lazy, you
    could just code it as @mysql_close($l inkID). The "@" keeps any errors from
    being written.

    Regards,
    Shawn
    --
    Shawn Wilson
    shawn@glassgian t.com

    Leave a comment:


  • Tom
    Guest replied
    Re: Cannot connect to Mysql

    Krista,

    If you're using the default installation of MySQL (i.e. you haven't run a
    grant statement to create a user), then you're script should have run. You
    might want to try augmenting your connection statement with an error output
    such as:

    $linkID = mysql_connect(" localhost",""," ") or die ('I cannot connect to the
    database because: ' . mysql_error());

    Tom

    "Krista" <ywan_ip@hotmai l.com> wrote in message
    news:eb97c972.0 312161407.221fe a5d@posting.goo gle.com...[color=blue]
    > Hi, I hope you guys can help me out~~~
    > when I run it localhost/config.php, it cannot display any message such
    > as connect successfully or failed. Do u guys have any idea?
    >
    > config.php
    > <html>
    > <head><title>Cr eate Database and table</title></head>
    > <body>
    >
    > <?php
    >
    > $linkID = mysql_connect(" localhost",""," ");
    > print ("hello"); <---can print
    > Hello
    >
    > if($linkID != "FALSE") <--i think
    > fail here
    > {
    > print("The connection to the server was made successfully.)" ;
    > }
    > else
    > {
    > print("The connection to the server failed");
    > }
    >
    > mysql_close($li nkID);
    >
    > ?>
    > </body>
    > </html>
    >
    > am I right? do i need to put username and password in
    > mysql_connect(" localhost",""," ")? i dont know where i can find it, or
    > how can I find it in mysql. Hope you guys can help me out~~ Thanks.
    >
    >
    > Krista[/color]


    Leave a comment:


  • Krista
    Guest started a topic Cannot connect to Mysql

    Cannot connect to Mysql

    Hi, I hope you guys can help me out~~~
    when I run it localhost/config.php, it cannot display any message such
    as connect successfully or failed. Do u guys have any idea?

    config.php
    <html>
    <head><title>Cr eate Database and table</title></head>
    <body>

    <?php

    $linkID = mysql_connect(" localhost",""," ");
    print ("hello"); <---can print
    Hello

    if($linkID != "FALSE") <--i think
    fail here
    {
    print("The connection to the server was made successfully.)" ;
    }
    else
    {
    print("The connection to the server failed");
    }

    mysql_close($li nkID);

    ?>
    </body>
    </html>

    am I right? do i need to put username and password in
    mysql_connect(" localhost",""," ")? i dont know where i can find it, or
    how can I find it in mysql. Hope you guys can help me out~~ Thanks.


    Krista
Working...