Re: 'Code Snippets' you couldn't live without

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Murray @ PlanetThoughtful wrote:
Hi All,

I'm curious to know what other members of the list think of as the code
snippets they couldn't live without when working on a PHP project. IE, the
kind of re-usable bits and pieces that make your life a lot easier.

For myself, I have an include file in which I define 'shorthand' functions
for functions etc I use on a regular basis.

Eg:

function asl($val){
	return addslashes($val);
}

function mfr(&$rset){
	mysql_free_result($rset);
}

...and so on.

Just thought it would be interesting to see what others do to make
programming more bearable.

Probably the custom one I use the most is for getting data...

function selectData ( $sql ) {
	if ( ! $_SESSION['mysql']['status'] ) {
		dbconn();
	}
	if ( $result = @mysql_query ( $sql ) ) {
		$return = array();
		while ( $row = @mysql_fetch_array ( $result ) ) {
			array_push ( $return, $row );
		}
		@mysql_free_result ( $result );
		return $return;
	} else {
		$msg = "The query could not be executed.";
		raiseError ( $msg, 0, 1 );
		return false;
	}
}

--
John C. Nichel
ÜberGeek
KegWorks.com
716.856.9675
john@xxxxxxxxxxxx

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux