DaemonForums  

Go Back   DaemonForums > Miscellaneous > Programming

Programming C, bash, Python, Perl, PHP, Java, you name it.

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1   (View Single Post)  
Old 10th September 2008
TerryP's Avatar
TerryP TerryP is offline
Arp Constable
 
Join Date: May 2008
Location: USofA
Posts: 1,547
Default PHP database interfaces

Is there any standard set of classes or perhaps module of functions that provides a wrapper-interface around PHP's various dbtype_functions, and chucks exceptions on error, insane usage, or just plane stupidity? That can be quickly installed into a web hosts webroot/includes/ ?


For something I'm planning on doing, I'd really rather not have to hunt down and debate, "Is it worth making this handle errors now or wait until it breaks later" when trying to clean up some old code. So I figure, make new work use exceptions and refactor as necessary when fixing stuff. I however, don't really know a lot of PHP lol. I ended up helping out, using my knowledge of C++/Perl to work on PHP scripts, and eventually the PHP Reference Manual to learn more specifics -- but beyond that, I don't know what to look for.

I'm not spending any more hours dealing with other peoples failure to check errors. But I also don't want to write a module myself, if it's already been written and used everywhere else but by my predecessors.


Code:
/**
 * just groaning out loud, if anyone cares for more details
 */
I'm stuck maintaining code, that frankly I would rather work in octal then look at... Since the crap is prone to breaking in occasionally subtle ways, when ever someone so much as farts! I'm thinking of making use of Exceptions now that PHP4 is EOL (and we've been on PHP5 for ages). One of the things I think it would do most help in, is dealing with database operations:


A lot of the code using the database looks like this:


Code:
// very close to some real code on the site, but made to look nicer
global $dbi, $cmsOrSiteSpeicificThingdepreciatedLongTimeAgoAndRemovedNowWithoutMention, $alotofGlobals;
$dontworknomore=$cmsOrSiteSpeicificThingdepreciatedLongTimeAgoAndRemovedNowWithoutMention;
... 

$query4 = sql_query("SELECT foo,bar from table_name inner join four times on $dontworkanymore = $xyz where blah blah blah", $dbi);
if ($query4) {
?></td></tr></table><?
while($foo = sql_fetch_array($query4, $dbi)) {
?>
<table width="53%" border="1" align="left" cellpadding="1" cellspacing="1">
  <tr>
    <td width="74%" height="100"><?
if ($something){
	do_something_he_wrote_in_20_other_modules_wihout_an_inc("header message");

	echo "<center><table><tr><td width=80><b>some text</b></td><td><b>some more
    text</b></td></tr>";
	
    echo "<tr><td>".$foo['foo']."</td><td>".$foo['bar']." [ <a href='cmsstuff.php?x=Whatever&y=whatever&alot=ofthis&something=".$foo['bar']."&important=anulllvalue'>link text</a> ]</td></tr>"; }
    else {
  ?> <div>don't even get me started</div> <?
}
}
  }
// never handles $query4 failing, the array fetch failing, or returning bad values, et cetera.

So, since I'm the one that actually brought the idea of a "library" and defining constants to the websites custom modules.... As I am stuck fixing things time after time after time and again, whenever something breaks or most be changed. I think it would be better if things change to using exceptions, since there are lots of things that can blow up, but are assumed to remain as unchanging as my hatred for the original programmer.


I spent 3 hours Saturday night, trying to prove that a section of code that by every possible reading, should be valid, yet didn't do what it was supposed to, until I finally gave up and went to sleep. Today, when I had to edit things in the DB manually, I got a punch in the face. It was working exactly as it should, only it was getting garbage in and putting garbage out without looking, but wouldn't display said garbage -- appearing as if nothing happened at all.


When in fact the DB was full of crap, thanks to something that got dropped without anyone knowing about it.
__________________
My Journal

Thou shalt check the array bounds of all strings (indeed, all arrays), for surely where thou typest ``foo'' someone someday shall type ``supercalifragilisticexpialidocious''.
Reply With Quote
 

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PPTP Server, no internet connectivity (routing between interfaces?) godfrank FreeBSD Ports and Packages 5 15th April 2009 04:44 PM
Roundcube Mail Can't Connect to MYSQL Database jrs665 OpenBSD Packages and Ports 1 17th November 2008 03:54 PM
Slocate database coverage ivanatora FreeBSD General 2 4th August 2008 08:51 AM
Changing encoding of text in MySQL database stukov Programming 5 15th July 2008 09:48 PM
WARNING: Vulnerability database out of date, checking anyway mfaridi FreeBSD Security 9 8th May 2008 06:13 AM


All times are GMT. The time now is 05:39 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Content copyright © 2007-2010, the authors
Daemon image copyright ©1988, Marshall Kirk McKusick