Results 1 to 5 of 5

Thread: mysql_connect works, but mysqli_connect doesn't...

  1. #1
    Join Date
    Sep 2007
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default mysql_connect works, but mysqli_connect doesn't...

    When I use this code:
    Code:
    $link = mysql_connect($hostname_SalesRepository, '*user*', $password_SalesRepository, 'salesrepository');
    /* check connection */
    if (!$link) {
        printf("Connect failed: %s\n", mysqli_connect_error());
        exit();
    }
    
    printf("Host information: %s\n", mysql_get_host_info($link));
    Everything works and I get the following message:

    Host information: Localhost via UNIX socket

    But when I use THIS code:
    Code:
    $link = mysqli_connect($hostname_SalesRepository, '*user*', $password_SalesRepository, 'salesrepository');
    /* check connection */
    if (!$link) {
        printf("Connect failed: %s\n", mysqli_connect_error());
        exit();
    }
    
    printf("Host information: %s\n", mysqli_get_host_info($link));
    Nothing works, and I get THIS message:

    Connect failed: Access denied for user '*user*'@'localhost' to database 'salesrepository'

    Can anyone help me out with this??? Thanks!...


    MOD EDIT: Replaced username with *user* for security. Two pieces to the puzzle are better for stopping a potential hacker. Don't give out the username either.
    Last edited by djr33; 09-28-2007 at 09:35 PM.

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Nothing jumps out at me.

    First, are you sure you have mysqli included with PHP and your MySQL db is 4.1.3 or higher?
    Quote Originally Posted by php.net
    Requirements
    In order to have these functions available, you must compile PHP with support for the mysqli extension.
    Note: The mysqli extension is designed to work with the version 4.1.3 or above of MySQL.
    PHP Code:
    <?php echo function_exists('mysqli_connect')?'yes':'no'?>
    That will output yes/no if the function mysqli_connect exists in your PHP configuration.
    And a few more things--
    Note that in the first block of code you are using mysqli_connect_error() rather than as I suspect you'd want to mysql_connect_error(). That isn't the reason it's not working, though.

    I don't understand why you're using printf() for that. Just using echo 'message: '.function()."\n"; would be much easier. Again, not the problem.

    I doubt this is really the reason it isn't working, but it's a good idea to check if there is a value of a function, not if it's value equates to true due to type conversion.
    if (!link) should be if (!isset($link)) and it will also not give an error running running the E_ALL error mode if it isn't set. You could also use empty() instead of !isset().
    If you're lucky, that might actually fix it, but unlikely.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. #3
    Join Date
    Sep 2007
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I actually realized that it was a careless error on my part. I was typing the wrong database name. I still don't understand why there was no error generated with the mysql_connect, though. But oh well - I guess it doesn't matter if everything is working now!...

    ...thanks!!!

  4. #4
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Ah, ok. I just added some more info by editing the post. It explains why there was no error.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  5. #5
    Join Date
    Sep 2007
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Awesome - thanks for all the good info. Much appreciated!

Bookmarks

Posting Permissions

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