March 22, 201412 yr Hi I know I can control the level of warning within my php.ini but I thought the following code would mean that I would generate my own error messaging and prevent the warnings from appearing. Where am I in error in my thinking? Class db_functions { public function __construct() { DEFINE ('DB_HOSTNAME', 'localhost'); DEFINE ('DB_DATABASE', 'db_running'); DEFINE ('DB_USERNAME', 'root'); DEFINE ('DB_PASSWORD', ''); echo "Database definitions implemented"; } function connect_db() { $connect = mysqli_connect(DB_HOSTNAME, DB_USERNAME, DB_PASSWORD, DB_DATABASE) or die("ERROR: " . mysqli_error($connect)); return $connect; } } I would have expected to have "ERROR: [some message]" echoed to the screen and yet I actually get: Database definitions implementedWarning: mysqli_connect(): (HY000/1049): Unknown database 'db_running' in C:\xampp\htdocs\private_data\running_includes\db.inc.php on line 16Warning: mysqli_error() expects parameter 1 to be mysqli, boolean given in C:\xampp\htdocs\private_data\running_includes\db.inc.php on line 16ERROR:
March 22, 201412 yr Author I would have assumed that the mysqli_error would have come after the ERROR: and not prior to? In fact, when I remove ". mysqli_error($connect)" from my code I still get: Database definitions implementedWarning: mysqli_connect(): (HY000/1049): Unknown database 'db_running' in C:\xampp\htdocs\private_data\running_includes\db.inc.php on line 16ERROR: So, the second line is the ". mysqli_error($connect)" but the first? Edited March 22, 201412 yr by Gary Newport
March 22, 201412 yr If you look at the second line it is different to the first, the message is telling you more about the error that was raised. That is what your mysqli_error($connect) is fetching for you. Err correction, it is actually telling you that your passing a Boolean ( '$connect' is true or false when used like this. ) to the mysqli_error function. Edited March 22, 201412 yr by Weedy101
March 23, 201412 yr Author Thanks Weedy, I was aware of what the errors were telling me. I'm not looking to solve the fault (I hadn't, by this time, even constructed the database) but wanted to find a method that would prevent any and all error messages being sent to the browser window. I recognise that I am using a developmental environment and as such my php.ini is set to show warnings but was wondering if there was a way of preventing even this. The concept was that any stray messages that may appear in the live system could be prevented using this desired methodology. However, I have already spent far too long on something that was an aside from the main task so will move on to what I should be working on. )
March 23, 201412 yr to hide errors put these two functions at the top of the page error_reporting(0); ini_set('display_errors', 0);or if you have access to your php.ini file change display_errors = On to display_errors = Off
Create an account or sign in to comment