cearlp Posted July 17 Share Posted July 17 After years of working, the call to mysql_connect does nothing. Software installed is: Server: Localhost via UNIX socket Server type: MariaDB Server version: 10.6.18-MAriaDB-0ubuntu0.22.04.1 Protocol version: 10 Apache/2.4.52 (Ubuntu) Database client version: libmysql - mysqlind 8.1.2-1ubuntu2.18 PHP extension: mysqli curl mbstring PHP version: 8.1.2-1ubuntu2.18 What have I missed, some update or could the database be corrupted? Quote Link to comment https://forums.phpfreaks.com/topic/322416-mysqli_connect-suddenly-not-working/ Share on other sites More sharing options...
mac_gyver Posted July 17 Share Posted July 17 what symptom or error are you getting? Quote Link to comment https://forums.phpfreaks.com/topic/322416-mysqli_connect-suddenly-not-working/#findComment-1630279 Share on other sites More sharing options...
cearlp Posted July 17 Author Share Posted July 17 (edited) No error or any message. The program seems to finish normally except nothing was available to be displayed from the database. The code: if (!($conn=mysqli_connect($host, $user, $psss, &db))) { printf("error connecting to DB by user = $user"); exit; } Edited July 17 by cearlp update with more info Quote Link to comment https://forums.phpfreaks.com/topic/322416-mysqli_connect-suddenly-not-working/#findComment-1630285 Share on other sites More sharing options...
mac_gyver Posted July 17 Share Posted July 17 the default setting now in php8+ is to use exceptions for errors for both the mysqli and PDO extensions. assuming you haven't turned this off or caught the mysqli exception yourself, but aren't handling it correctly, a database connection or query error wouldn't allow the code to finish. it would halt at the point of the database error. so, it's more likely that a query just isn't matching any data or is being skipped over. is your code testing if there is not any data from a query and outputting a message stating so? beyond this, there are just too many possible reasons your code might appear to being displaying nothing from a query. you would need to post all the code necessary to reproduce the problem, less the database connection credentials. Quote Link to comment https://forums.phpfreaks.com/topic/322416-mysqli_connect-suddenly-not-working/#findComment-1630287 Share on other sites More sharing options...
cearlp Posted July 18 Author Share Posted July 18 I tried the following after researching mysqli exceptions and the result was the same,,,first two echos are displayed, no error printout but the echo "after conn" was not displayed. function conn($sql) { $host = "localhost"; $user = "root"; $pass = "xxx"; valid root password for database $db = "xxx"; looking at database with PHPMYADMIN seems okay echo "in conn--- "; echo "HOST $host, USER $user, PASS $pass, DB $db"; $con = new mysqli($host, $user, $pass, $db); if ($con->connect_errno) { printf("connect failed: %s\n" , $con->connect_error()); exit(); } echo "after conn"; } Quote Link to comment https://forums.phpfreaks.com/topic/322416-mysqli_connect-suddenly-not-working/#findComment-1630305 Share on other sites More sharing options...
Solution mac_gyver Posted July 18 Solution Share Posted July 18 one of the great points of using exceptions for errors is that your main code will only 'see' error free execution. no discrete error checking logic will ever get executed upon an error and should be removed, simplifying the code. php's error_reporting should always be set to E_ALL. temporarily set display_errors to ON so that php will display all the reported errors, which will now include any uncaught database exceptions. Quote Link to comment https://forums.phpfreaks.com/topic/322416-mysqli_connect-suddenly-not-working/#findComment-1630309 Share on other sites More sharing options...
cearlp Posted July 19 Author Share Posted July 19 Thank you mac_gyver... Finding out the errors showed me that it was a connection to the database that failed due to a password change that was not accounted for in the code. Quote Link to comment https://forums.phpfreaks.com/topic/322416-mysqli_connect-suddenly-not-working/#findComment-1630462 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.