Return to Snippet

Revision: 9542
at January 19, 2010 04:47 by ginoplusio


Updated Code
function execute_scalar($sql,$def="") {
	$rs = mysql_query($sql) or die(mysql_error().$sql);
	if (mysql_num_rows($rs)) {
		$r = mysql_fetch_row($rs);
		mysql_free_result($rs);
		return $r[0];
		}
	return $def;
}

Revision: 9541
at November 11, 2008 11:21 by ginoplusio


Initial Code
function execute_scalar($sql,$def="") {
	$rs = mysql_query($sql) or die(mysql_error().$sql);
	if (mysql_num_rows($rs)) {
		$r = mysql_fetch_row($rs);
		mysql_free_result($rs);
		return $r[0];
		mysql_free_result($rs); }
	return $def;
}

Initial URL
http://www.barattalo.it/

Initial Description
retrieve only one value from the query

Initial Title
execute scalar for php

Initial Tags
mysql

Initial Language
PHP