I was so surprised when I knew that one of my web applications that generated with PHPMaker was displaying the complete ConnectionString that contains database login information in the error message when failed to connect to SQL Server database. This is the message I got:
Failed to connect to at Provider=SQLNCLI;Persist Security Info=False;Data Source=myipserverlocation;Initial Catalog=mydatabasename;User Id=myuserid;Password=mypassword;DataTypeCompatibility=80. Error: No connection established.
So, here is the trick how to avoid displaying the database ConnectionString information if error occurred when trying to connect to your database. Instead of displaying the complete ConnectiongString, then we will display the general message that informs users about failed to connect to database, just like the following:
Failed to connect to database. Error: No connection established. Please check either your database setting or the database server!
This trick is very useful if you want to avoid displaying the database login information to your user as this is the top-secret information for you as the developer. In other words, do not ever try to display the database login information to your users!
Updated on September 5, 2012: This customization has been implemented in PHPMaker version 9.0.4, it matches to each other, and as a result, it works properly.
Updated on November 29, 2012: This customization has been implemented in PHPMaker version 9.1.0, it matches to each other, and as a result, it works properly.
Updated on February 9, 2013: This customization has been implemented in PHPMaker version 9.2.0, it matches to each other, and as a result, it works properly.
Updated on July 18, 2013: The customization has been handled by using MasinoFixedWidthSite extension. You don’t need to implement the customization below if you use my extensions together with the original PHPMaker Template and Extension files.
[hidepost]
-
Open your \Script\phpfn.php file, and find this code:
$msg = "Failed to connect to $Param2 at $Param1. Error: " . $ErrorMsg;
then replace it with the following code:
$msg = "Failed to connect to database. Error: " . $ErrorMsg .". Please check either your database setting or the database server!";
- Finally, re-generate your script files using PHPMaker as always.
[/hidepost]
Leave a Reply
You must be logged in to post a comment.