Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Connection Warning Showing

Featured Replies

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 implemented

Warning: mysqli_connect(): (HY000/1049): Unknown database 'db_running' in C:\xampp\htdocs\private_data\running_includes\db.inc.php on line 16



Warning: mysqli_error() expects parameter 1 to be mysqli, boolean given in C:\xampp\htdocs\private_data\running_includes\db.inc.php on line 16

ERROR:

 

  • 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 implemented

Warning: mysqli_connect(): (HY000/1049): Unknown database 'db_running' in C:\xampp\htdocs\private_data\running_includes\db.inc.php on line 16

ERROR:

 

So, the second line is the ". mysqli_error($connect)" but the first?

Edited by Gary Newport

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 by Weedy101

  • 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. :o)

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

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.