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 7 of 7
  1. #1
    Regular Coder
    Join Date
    Mar 2004
    Posts
    130
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Arrow php mysql_connect

    Client has 2 username/pws.

    I can connect via mysql monitor just fine. I can connect via mysql_connect in PHP. I cannot use the db with the link/connection returned from mysql_connect for mysql_select_db. It's weird, see:

    username 1 - used for ftp
    username 2 - used for mysql monitor and mysql_connect

    pass 1 - ftp password, works for mysql_connect pass
    pass 2 - mysql monitor pass


    I can get a mysql_connect connection (link), but I can't connect to the db with mysql_select_db. I think mysql_select_db fails because it requires pass 2, not pass 1, but mysql_connect requires pass 1.

    What is wrong?

  • #2
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    Can you show your code? I'm confused to what you're saying

  • #3
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: php mysql_connect

    Originally posted by DHTML Kitchen
    What is wrong?
    Probably your code.

    Your connectonstrings should look like
    PHP Code:
    $link = @mysql_pconnect("localhost""[i]yourusername[/i]""[i]yourpassword[/i]")
                or die(
    "Could not connect to the databaseserver. Please go back and try again or try again later.");
    @
    mysql_select_db("[i]yourdbname[/i]",$link)
                   or die (
    "Could not select database. Please go back and try again or try again later."); 
    You need to replace the italis by tour user, pwd and dbname.
    If you connect from a remote server, the localhost needs to be replaced by the mysql-servers IP or name, but you'll probaly connect from the same machine.
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

  • #4
    Regular Coder
    Join Date
    Mar 2004
    Posts
    130
    Thanks
    0
    Thanked 0 Times in 0 Posts
    PHP Code:
    $link mysql_connect('localhost''ehousebo''--deleted-pw--');
    if (!
    $link) {
       die(
    'Not connected : ' mysql_error());
    }

    // make ehousebo the current db
    $db_selected mysql_select_db('w3webde_launch'$link);
    if (!
    $db_selected) {
       die (
    'Can\'t use w3webde_launch : ' mysql_error());

    output:

    Can't use w3webde_launch : Access denied for user: 'ehousebo@localhost' to database 'w3webde_launch'

    http://www.ehouseboatsite.com/brochure/

  • #5
    Regular Coder
    Join Date
    Mar 2004
    Posts
    130
    Thanks
    0
    Thanked 0 Times in 0 Posts
    mutherfudge!

    I just reallized that you used a pconnect function. Well, that WFM. Didn't see that in the manual but I'm off to take a nother look at it.


    Thanks bro.

  • #6
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    you can use mysql_connect --> probably better for your app.

    You should get an error on
    'Can't use
    (just look at the colourcoding and you'll see it should hae been either
    "Can't use...:"
    or
    'Can\\'t use...:'

    as you could have seen where you copied it
    http://www.php.net/function.mysql-select-db

    Although this is code from the manual, it's not good. It is unefficent and not safe since it discloses to much info about your db account and the db-name. The most effient code would be
    PHP Code:
    $link = @mysql_connect('localhost''yourusername''yourpassword'
               or die(
    'Could not connect to the databaseserver. Please go back and try again or try again later.'); 
    @
    mysql_select_db('yourdbname',$link
                   or die (
    'Could not select database. Please go back and try again or try again later.'); 
    --> using mysql_connect (which in most case is to be prefered over pconnect) and single quotes (which is supposed to be slightly faster since the parser then doesn't expect enclosed variables)

    <edit> the backslash in the second alternative got parsedaway</edit>
    Last edited by raf; 03-15-2004 at 07:28 AM.
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

  • #7
    Regular Coder
    Join Date
    Mar 2004
    Posts
    130
    Thanks
    0
    Thanked 0 Times in 0 Posts
    good advice. Thanks.


  •  

    Posting Permissions

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