CodeCharge Studio
search Register Login  

Visual PHP Web Development

Visually Create Internationalized Web Applications, Web Reports, Calendars, and more.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> PHP

 Database Error Handling

Print topic Send  topic

Author Message
materix

Posts: 161
Posted: 06/07/2008, 11:29 AM

If the database is not running for some reason, then the page does show, but instead shows the ugly message:

Database error: cannot connect to Database Can't connect to MySQL server on 'localhost' (10061)

Is there some way to implement a more "beautiful" error handling in CCS? With some kind of decent message box for instance stating that "the site is down at the moment, please check again later".

View profile  Send private message
jjrjr1


Posts: 942
Posted: 06/07/2008, 1:13 PM

Hi

Yes there is...

It seems this is an overlooked bug that has not been fixed as of CCS 4.0.0.15

What needs to be done is you must edit db_mysql.php. Since this is CCS generated for every project and the fix is not in the template you will have to make this change every time you start a new project.

Load db_mysql.php

Locate both functions connect() and try_connect()

place a @ before the mysql connect calls

eg:

if($this->Persistent)
$this->Link_ID=@mysql_pconnect($DBHost, $DBUser, $DBPassword);
else
$this->Link_ID=@mysql_connect($DBHost, $DBUser, $DBPassword);

Now your error will be handled by the function in db_mysql.php

halt($msg)

with what ever message you want (or the one CCS has).

You could also cause a page of your own design to display by modifying halt($msg) like so

/* private: error handling */
function halt($msg) {
header("HTTP/1.1 302 Found");
header("Location: mysqlfail.php?error=".$msg);
exit;

// printf("</td></tr></table><b>JR Database error:</b> %s<br>\n", $msg);
// printf("<b>MySQL Error</b><br>\n");
// die("Session halted.");
}

You could do some different stuff in your custom page to display your own error message based on the error pased in the URL. (That way you do not have to change all the CCS error messages in db_mysql.php)

This will cause your page to display with whatever you want on it and display the message if your page does a CCGetFromGet("error",""); and puts it into a control.

If your page is executing from a script that is any folder under the root, you will need this fail page in each directory or modify the redirect to always be in the root.

An obvious note is the error page can have no database forms or objects or you will get into an infinite loop.

Anyway, the possiblities are many.

Let me know if that helps.


_________________
John Real - More CodeCharge Studio Support at - http://CCSElite.com
View profile  Send private message
jjrjr1


Posts: 942
Posted: 06/07/2008, 1:55 PM

Additional Notes

If you put a / infront of the filename redirect like so

header("Location: /mysqlfail.php?error=".$msg);

On a live server it should always point to the fail page in the root. (Depends on your server)

For example in my case on my local xammp server having the / causes object not found when run locally (seems the / causes apache to look one directory up from httdocs creating the error)

However on my live linux server the / causes no problem.. Thought I would make you aware of that inconsistency betwwen windows XP local servers and production linus servers. You could tear your hair out.

I just tried the / on my live server and it works just fine.

Have fun.


_________________
John Real - More CodeCharge Studio Support at - http://CCSElite.com
View profile  Send private message
materix

Posts: 161
Posted: 06/07/2008, 1:56 PM

Hi John!

Thx for the fantastic reply. I am already well on the way implementing your suggestion :-)
View profile  Send private message
jjrjr1


Posts: 942
Posted: 06/07/2008, 2:06 PM

Great!!

Let me know how it comes out.

Take Care

_________________
John Real - More CodeCharge Studio Support at - http://CCSElite.com
View profile  Send private message

Add new topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

PHP Reports

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.