Tryibg to connect from php script to mysql server

Discussion in 'PHP' started by progfrog, Dec 7, 2008.

  1. #1
    Hi!
    I want to connect to mysql server that is installed on my pc and works from php script.


    I use the wampserver and all the severs works . but from some reasom when i write this script:


    <?php
     $mysql_link= mysql _connect('local','','') or die("ERROR:cannot connect");
    echo "connected successfully to MySQL server.";
     mysql_close($mysql_link);  
    ?>
    PHP:
    it keep sys access is denid. i do not have user name or password to the server and everything works through the consol than what can be wrong?

    need your help
    progfrog
     
    progfrog, Dec 7, 2008 IP
  2. mac83

    mac83 Active Member

    Messages:
    237
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    58
    #2
    mysql _connect('local','','') change it to mysql _connect('local','root','')


    root is the default user with no password. It's ok to use it on local test servers. But always create different users with passwords in live environment!
     
    mac83, Dec 7, 2008 IP
  3. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,999
    Best Answers:
    253
    Trophy Points:
    515
    #3
    Uhm... there shouldn't be a space between 'mysql' and the underscore. mysql_connect not mysql _connect...
     
    deathshadow, Dec 7, 2008 IP
  4. rene7705

    rene7705 Peon

    Messages:
    233
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #4
    might i recommend adodb.sourceforge.net before you start writing large applications?
    if you ever need to move to something else than mysql you'll be very happy if u use adodb..
     
    rene7705, Dec 7, 2008 IP
  5. Colbyt

    Colbyt Notable Member

    Messages:
    3,224
    Likes Received:
    185
    Best Answers:
    0
    Trophy Points:
    210
    #5
    I think you need to make it look like this to get it working:

    It is localhost and user root with no password in your case though I do suggest you assign a password to root even on your local machine.
     
    Colbyt, Dec 8, 2008 IP