Location: PHPKode > projects > gframe > gframe/mysql.php
<?PHP

function foreign_sql_query($string, $debug, $host, $username, $password, $database)
{

	// open a new link to the foreign database:
	
	$link = mysql_pconnect($host, $username, $password);

	// select the database which is to be used, inside the new mysql_link
	
	mysql_select_db($database, $link);
	
	// send out the query, would work without the link stuff, but this makes it just more transparent
	
	$result = sql_query($string, $debug, $link);
	
	return $result;
}

function sql_query($string, $debug=0, $link=null)
{
	if($debug)
		{	
			echo "$string";
			//die();
		}
	else
		{
			if($link)
				$result = mysql_query("$string", $link);
			else
				$result = mysql_query("$string");
		}
		
	return $result;
}


function db_connect($host, $username, $password, $database, $mode = 1)
{
	if ( $mode )
		$conn_id = mysql_pconnect($host,$username,$password);
	else
		$conn_id = mysql_connect($host,$username,$password);
	
	if ( isset($database) )
		@mysql_select_db($database);
	
	if(!$conn_id)
		return false;
	else
		return $conn_id;
}

function get_array_from_db ($table_name, $fields, $order_param)
{
	if(is_array($fields))
	{
	 foreach($fields as $field)
	  $field_query .= $field .", ";	
	 $field_query = substr($field_query, 0, -2);
	}
	else 
	 $fields_query = $fields;
	 
	$result = sql_query("SELECT $field_query FROM $table_name ORDER BY $order_param");
	while ($row = mysql_fetch_assoc($result)) {$result_array[]=$row;}
	return $result_array;
}

?>
Return current item: gframe