Results 1 to 8 of 8
  1. #1
    Join Date
    Apr 2008
    Posts
    5

    Unanswered: mysqli runs OK mysql doesn't

    Hello,

    I have been banging my head on this for several days nad have not been able to find a solution anywhere.

    I am running Apache 2.2, PHP 5.0.27, Mysql 5.0.45 on Vista.

    I have configured php.ini for both the mysql and mysqli extension, the 4 files php_mysql.dll, php_mysqli.dll libmysql.dll and libmysqli.dll are in the /php/ext directory and the path is correctly set. phpinfo() shows both mysql and mysqli as configured, loaded and driver version is same as mysql version (5.0.45).

    When I try to connect with mysqli_connect, I am successful, when I try with mysql_connect it fails. I have tried reloading php with only mysql and that hasn't worked either. I have a lot of legacy pages I am hoping to not have to rewrite.

    This works:
    $link = mysqli_connect("$dbServer", "$dbUser", "$dbPass") or die("Could not connect");

    This doesn't:
    $link = mysql_connect("$dbServer", "$dbUser", "$dbPass") or die("Could not connect");

    Thanks for any advice.

  2. #2
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    and what is the error message you get from the one that fails?
    either the PHP or preferably the MySQL error message.....

    the or dies construct can be usefull, especailly in the live code to handle an error gracefully, but it doens't give much help on debugging

  3. #3
    Join Date
    Apr 2008
    Posts
    5
    The error message is:

    Access denied for user 'SYSTEM'@'localhost' (using password: NO)

    When I search on this message, it usually comes back saying you are using a root account without a password and I am not using root, I do have a password on the account and I can login with either the Mysql CLI or mysqli_connect with the same values.

    Thanks

  4. #4
    Join Date
    Apr 2006
    Location
    Denver, Co. USA
    Posts
    242
    Have you verified (echoed) what "$dbServer", "$dbUser", and "$dbPass" contain? The error message is indicating that at least the user and password were empty.

  5. #5
    Join Date
    Apr 2008
    Posts
    5
    Just did that, the variables echo with the correct host, user and password

    Thanks

  6. #6
    Join Date
    Apr 2008
    Posts
    5
    I am sure its just something minor I have overlooked.

  7. #7
    Join Date
    Apr 2006
    Location
    Denver, Co. USA
    Posts
    242
    Since you have not really posted any of your code (the one line does not count as it does not show the context it is being used in), we cannot really tell you what you might or might not have overlooked.

    Unless you have -

    $dbServer = "localhost";
    $dbUser = "SYSTEM";
    $dbPass = "";

    The posted line of code did not generate the posted error message. To get specific help with what your code is doing, you need to post your actual code (xxxxx out any sensitive information but don't change any of the syntax or punctuation.)

    Also, add the following two lines after your first opening <?php tag -

    PHP Code:
    ini_set ("display_errors""1");
    error_reporting(E_ALL); 
    Edit: I am going to take a wild educated guess and say the problem is that your mysql_connect() statement is not being executed at all (probably because it is contained in a block of code using a short open php tag <? or in an include file that is not being included) and the error message you posted actually refers to the line number of a mysql_query() statement (or perhaps a mysql_select_db() statement) that is attempting to open a connection to the mysql server using all default values.
    Last edited by dbmab; 04-16-08 at 03:08.

  8. #8
    Join Date
    Apr 2008
    Posts
    5
    Thank you!

    Got the following message after inserting the two lines above:
    Notice: mysql_connect() [function.mysql-connect]: SQL safe mode in effect - ignoring host/user/password information in C:\Program Files\Apache\Apache2.2\htdocs\test1.php on line 15

    Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'SYSTEM'@'localhost' (using password: NO) in C:\Program Files\Apache\Apache2.2\htdocs\test1.php on line 15
    Could not connect

    So I disabled SQL.safe_mode in php.ini, restarted Apache and now mysql_connect is working.

    I am in a test environment at this time, so turning it off is no big deal for now.

    Will read up on safe mode to see what my options are.

    Thank you again!

Posting Permissions

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