php/mysql question

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • alex79
    Confirmed User
    • Jun 2002
    • 996

    #1

    php/mysql question

    i try connect to a mysql database using the function mysql_connect("localhost","username","userpass") but i get this error: Access denied for user: 'root@localhost' (Using password: NO)

    why the php is trying to connect with the user "root" and without password since username is other than root and i specify a password (for username) ?
  • Jakke PNG
    ex-TeenGodFather
    • Nov 2001
    • 20306

    #2
    No idea, this works for me.

    $link = mysql_connect("localhost", "root", "password")
    or die("w00t w00t, error error");
    mysql_select_db("database", $link)
    or die("can't open db");
    ..and I'm off.

    Comment

    • Doc911
      Confirmed User
      • Feb 2004
      • 3695

      #3
      try putting the real mysql ip in the localhost space


      For PHP/MySQL scripts ICQ 161480555 or email [email protected]

      Comment

      • alex79
        Confirmed User
        • Jun 2002
        • 996

        #4
        Originally posted by Doc911
        try putting the real mysql ip in the localhost space
        still not working

        Comment

        • blazin
          Confirmed User
          • Aug 2002
          • 2781

          #5
          not familiar with PHP myself but it looks to me like your not passing the name of the database. Shouldn't you be connecting to a particular db?
          I don't endorse a god damn thing......

          Comment

          • alex79
            Confirmed User
            • Jun 2002
            • 996

            #6
            Originally posted by blazin
            not familiar with PHP myself but it looks to me like your not passing the name of the database. Shouldn't you be connecting to a particular db?

            mysql_select_db($dbname) will come after mysql_connect() function... but why i'm geting that mysql error? why is trying to connect as root when i specify a username?

            Comment

            • Doc911
              Confirmed User
              • Feb 2004
              • 3695

              #7
              try assigning the user and password to a variable and putting the string in place
              $host = "127.0.0.1:4321";
              $user = blah;
              $pass = blahblah;

              mysql_connect($host, $user, $pass) ;
              Last edited by Doc911; 03-20-2005, 02:49 PM.


              For PHP/MySQL scripts ICQ 161480555 or email [email protected]

              Comment

              • grumpy
                Too lazy to set a custom title
                • Jan 2002
                • 9870

                #8
                wrong password or dbname.
                Don't let greediness blur your vision | You gotta let some shit slide
                icq - 441-456-888

                Comment

                • teksonline
                  So Fucking Banned
                  • Jan 2005
                  • 2904

                  #9
                  your file is not in the proper format

                  convert it to proper ascii format with proper line feeds

                  Comment

                  • Dynamix
                    G F Y not
                    • Jan 2004
                    • 2910

                    #10
                    Code:
                    $link = @mysql_connect("$DB_HOST", "$DB_USER", "$DB_PASS");
                    $db_selected = mysql_select_db($DB_DB, $link);
                    always works for me. set the variables above the connect line and you're good to go. check with your server admin, perhaps your databases aren't properly setup. It has nothing to do with the host IP as you're at least getting a reply.

                    TGPFactory Full TGP Design & Installation Services
                    ICQ 250 142 484 · AIM TGPDynamix · Email: patrick (at) tgpfactory (dot) com
                    See who I am at AdultWhosWho.com!

                    Comment

                    • mike503
                      Confirmed User
                      • May 2002
                      • 2243

                      #11
                      the quotes shouldn't be needed.
                      php/mysql guru. hosting, coding, all that jazz.

                      Comment

                      • Pete-KT
                        Workin With The Devil
                        • Oct 2004
                        • 51532

                        #12
                        mysql_connect("localhost","username","userpass") but i get this error: Access denied for user: 'root@localhost' (Using password: NO)

                        THAT WILL NOT WORK try replacing it with this.


                        $_SESSION['dbhost'] = "localhost"; //
                        $_SESSION['dbusr'] = "xxxxx"; //
                        $_SESSION['dbpwd'] = "xxxxx"; //
                        $_SESSION['dbdb'] = "xxxxx"; //
                        $_SESSION['password'] = "xxxxx"; //
                        If that doesnt work contact me on icq i have another form also
                        Last edited by Pete-KT; 03-20-2005, 06:38 PM.

                        Comment

                        • Pete-KT
                          Workin With The Devil
                          • Oct 2004
                          • 51532

                          #13
                          This one works the best for me i just found it

                          // MySQL configuration
                          $CONFIG['dbserver'] = 'localhost'; // Your database server
                          $CONFIG['dbuser'] = 'xxxxxx'; // Your mysql username
                          $CONFIG['dbpass'] = 'xxxxxx'; // Your mysql password
                          $CONFIG['dbname'] = 'xxxxxx'; // Your mysql database name

                          Comment

                          • mike503
                            Confirmed User
                            • May 2002
                            • 2243

                            #14
                            the fuck are you storing db parameters in the session for?

                            jesus people, learn how to code.

                            your last example will work, if he uses mysql_connect and mysql_select_db with the appropriate parameters. it won't just work like magic otherwise. of course, unless there's some database abstraction library or related script being loaded that reads those variables like that (highly unlikely with that setup.)
                            php/mysql guru. hosting, coding, all that jazz.

                            Comment

                            • broke
                              Confirmed User
                              • Aug 2003
                              • 4501

                              #15
                              1. User/PWD not set up in MySQL.
                              2. Mistyped user name.
                              3. Mistyped password.

                              No other reason you would get an "Access denied" message.
                              Perfect Gonzo

                              Comment

                              • Pete-KT
                                Workin With The Devil
                                • Oct 2004
                                • 51532

                                #16
                                there in the session for the script thats being used by that coder, that wasnt one of my codes thats why i posted the second one for him .

                                Comment

                                Working...