473,395 Members | 1,856 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

How to suppress db and file info on connection error?

Claus Mygind
571 512MB
When I force a failure on the connection to my MySQL server in php, I get this error message.

"<br />
<b>Warning</b>: mysqli::mysqli() [<a href='mysqli.mysqli'>mysqli.mysqli</a>]: (28000/1045): Access denied for user '<myUser>'@'<myServer>' (using password: YES) in <b><myApp>.php</b> on line <b>100</b><br />
An error occured : Connection failed:
"

I only want the last line to appear in my returned message "An error occured : Connection failed:
".

No matter what I have tried I cannot stop the first portion of the message from being suppressed.

Here is my code
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. /*-- my calling app --*/
  3.  
  4. try 
  5. {
  6.     //open connection to database
  7.     include("db.php");
  8.  
  9.     $fieldList = $db->getFieldList("<myTable>");
  10. } //end try
  11.  
  12. catch (exception $e) 
  13. {
  14.     echo 'An error occured : ' .$e->getMessage();
  15. }
  16.  
  17. ?>
  18.  
  19.  
  20.  
  21. <?php
  22. /*-- this is my db.php app included above --*/
  23.  
  24. class dbcnx extends mysqli
  25. {
  26.  
  27.     function getFieldList($t1)
  28.     {
  29.         ....some code here....
  30.         return $aFieldList;
  31.     }    
  32.  
  33. }
  34.  
  35. /* Connect to database */
  36. $db = new dbcnx("localhost", "User", "Wrong Password", "dataBase");
  37.  
  38. /* check connection */
  39. if (mysqli_connect_errno()) {
  40.    throw new Exception("Connection failed: ");
  41.    exit();
  42. }
  43. ?>
  44.  
The calling app listed above is called from the browser via an ajax call. I have a procedure for handling other errors in the ajax callback. I would like to be able to channel this error into my other routine.

help!!! please
Jan 21 '11 #1

✓ answered by Claus Mygind

Thank you very much for that tip. I am using php 5.3 and there are two .ini files

php.ini-development
php.ini-production

with your tip I started looking in the file and found this line.

Expand|Select|Wrap|Line Numbers
  1. display_errors = On
  2.  
I switched over to the production (I renamed it php.ini)
it is set to "Off" and it solved my problem.

5 1716
stepterr
157 100+
You could use the "@" for error suppression and then use die() to display the message that you'd like to be shown instead. There are some negatives to this though so you may want to read up on that. You should probably also look into changing display_errors to off in your php.ini.
Jan 21 '11 #2
Claus Mygind
571 512MB
I tried something like that and it worked fine but I did not know how to write the code when creating an object.

Could you tell me where I would put the @ in this line of code?
Expand|Select|Wrap|Line Numbers
  1. $db = new dbcnx("localhost", "User", "Wrong Password", "dataBase");
  2.  
Also note whether I have a valid response or an error all is returned to my ajax call back, so I am not sure where and what I would do with the "die()" text?

Currently I feed all my response into a variable $response in the form of an array which is what I return to the calling page. Then I simply look for my indicator in cell one of the array to see it was a valid response so the page can be updated or if an error occurred in which case I display an alert on the users web page
Jan 22 '11 #3
Samishii23
246 100+
If this is in your ajax script, then I believe there are two options. I believe. I've seen the 2nd example used in MySQLi querys, so this may also work here.
Expand|Select|Wrap|Line Numbers
  1. $db = new dbcnx("localhost", "User", "Wrong Password", "dataBase") or die('Fatal Error: Could not connect to database.');
  2.  
  3. // or maybe this...
  4. if ( $db = new dbcnx("localhost", "User", "Wrong Password", "dataBase") )
  5. { /*continuation code*/ }
  6. else
  7. echo 'fatal error';
Jan 22 '11 #4
mfaisalwarraich
194 100+
u can turn on/off error reporting using:

Expand|Select|Wrap|Line Numbers
  1. error_reporting(0); //error reporting off
  2. error_reporting(-1); //error reporting on
  3.  
Jan 22 '11 #5
Claus Mygind
571 512MB
Thank you very much for that tip. I am using php 5.3 and there are two .ini files

php.ini-development
php.ini-production

with your tip I started looking in the file and found this line.

Expand|Select|Wrap|Line Numbers
  1. display_errors = On
  2.  
I switched over to the production (I renamed it php.ini)
it is set to "Off" and it solved my problem.
Jan 24 '11 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Mark Day | last post by:
Hi All, I have an application that links tables to an ODBC source. The DSN parameters are obtained from a custom .ini file. An incorrect DSN string gives the user a 'friendly' connection error...
1
by: PJ | last post by:
I'm getting an error message when posting information from my asp page to the database. This is the error message: DODB.Connection error '800a0e7c' Parameter object is improperly defined....
1
by: sck10 | last post by:
Hello, I have custom errors turned on, and am able to catch errors and send the user to a friendly page. I have one site with "authentication" turned on. I would like to send a person who...
2
by: LitelWang | last post by:
I need catch the error when my insert clause violate the primary key .How to write in the server function ? Thanks for any advice . ---------------------------(end of...
2
by: Fernando Chilvarguer | last post by:
I have a very simple test page that the only thing it does is render a control. This control generates and throws an error. I need to catch the error on my ASPX page but I can't figure out...
5
by: icegray | last post by:
Hi, I am new about C# and MS SQL. I have done a new program which use MS SQL Database and I've install it to a new computer. But program doesn't run on new computer. I give SQL Server Connection...
0
by: =?Utf-8?B?UmljaGFyZCBC?= | last post by:
We have been receiving a connection error at one of our sites, our application works elsewhere. The error occurs when our application written in vb.net 2.0 running as a Windows Service under the...
2
sonu5588
by: sonu5588 | last post by:
I am facing problem in connection. This code is OK , when i Deploy or Create a EXE of this project and install it on other system then the connection error generates, whats the solution to create a...
3
by: mvjohn100 | last post by:
When I found " Too many connection error" may occur because of mysql default allowed maximum connection of 100. I changed it to a big value. but even my fedora shows the same error what are the...
0
by: cwinay | last post by:
Hi, I'm using hibernate, mysql 5.0.22 and struts 2 in my application. In struts2, I'm using REST plugin and classes that extends ActionSupport and implements ModelDriven interface (webservice...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.