<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>JJ Is Me &#187; database</title>
	<atom:link href="http://jjis.me/a/tag/database/feed" rel="self" type="application/rss+xml" />
	<link>http://jjis.me</link>
	<description>Me And My Code</description>
	<lastBuildDate>Mon, 30 Apr 2012 17:58:52 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Database PHP Class</title>
		<link>http://jjis.me/a/253</link>
		<comments>http://jjis.me/a/253#comments</comments>
		<pubDate>Tue, 15 Jun 2010 17:38:25 +0000</pubDate>
		<dc:creator>jj_jiles</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://jjis.me/?p=253</guid>
		<description><![CDATA[I&#8217;m back with another chunk of code. This time, it&#8217;s my database class. I got sick of coming across classes that didn&#8217;t have everything I needed, or didn&#8217;t do it correctly. One of my biggest problems was an inability to nest query calls within another query result&#8217;s output. Example: With this class, that is not [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m back with another chunk of code.  This time, it&#8217;s my database class.</p>
<p>I got sick of coming across classes that didn&#8217;t have everything I needed, or didn&#8217;t do it correctly.  One of my biggest problems was an inability to nest query calls within another query result&#8217;s output.</p>
<p><span id="more-253"></span></p>
<h2>Example:</h2>
<pre class="brush: php; title: ; wrap-lines: false; notranslate">
&lt;?php

// main query
// gets a list of companies from the companies table
$a = &quot;SELECT id, company_name FROM companies&quot;;
$a = $db-&gt;query($a);

while  ($aa = $db-&gt;fetch_object($a) ) :

     echo '&lt;div class=&quot;company_name&quot;&gt;' . $aa-&gt;company_name . '&lt;/div&gt;';

     // get the contacts for each company
     $b = &quot;SELECT contact_name, phone1 FROM contacts WHERE company_id = $aa-&gt;id&quot;; // because we've already used $a, we can't use it again during $a's output
     $b = $db-&gt;query($b);

     // output all contacts for the each company
     while ( $bb = $db-&gt;fetch_object($b) ) : // the same thing as $a, we can not use $aa again during its output
          echo '&lt;div class=&quot;contact_name&quot;&gt;' . $bb-&gt;contact_name . '&lt;/div&gt;';
          echo '&lt;div class=&quot;contact_phone&quot;&gt;' . $bb-&gt;phone1 . '&lt;/div&gt;';
     endwhile;

endwhile;

?&gt;
</pre>
<p>With this class, that is not a problem. The only requirement is that you can&#8217;t name your $sql and $results ($row) variables the same (noted in the code above). Other than that, there&#8217;s nothing to it. It&#8217;s just a way to provide clean, and efficient database interaction.</p>
<h2>Database Class Code</h2>
<ul>
<li>
<p><strong>Updated 02-10-2012: </strong></p>
<ul>
<li>Renamed database class to Framework_Database to signify this class is a framework level class.</li>
<li>Most everything was re-written to tighten up the code.</li>
<li>Moved the database connection settings to a $config object. Allows for a single configuration file of your choosing.</li>
<li>Got rid of error_backtracing() and show_mysql_error() since it didn&#8217;t really work. It will now print the error to screen, via $db->error() (called automatically), if $config->errors['display'] is set to true. If false, it will email the error to $config->errors['email_to'].</li>
</ul>
</li>
</ul>
<p>Despite the re-write, your $db->query(), $db->fetch_object(), etc. methods are still there and still work the same.</p>
<pre class="brush: php; title: ; wrap-lines: false; notranslate">
&lt;?php
if ( !isset($config) ) :
	# ###
	#
	$config = (object) array();
		#
		# database connection settings
		$config-&gt;db = array(
			'host'                =&gt; '',
			'user'                =&gt; '',
			'password'            =&gt; '',
			'db_name'             =&gt; ''
		);

		#
		# error display settings
		$config-&gt;errors = array(
			'display'     =&gt; true,
			'redirect_to' =&gt; '/error',
			'email_to'    =&gt; 'email@yourdomain.com',
			'email_from'  =&gt; 'email@yourdomain.com',
			'style_sheet' =&gt; 'css/error-reports.css',
			'suppressed_error_message' =&gt; '&lt;div align=&quot;center&quot;&gt;&lt;b style=&quot;font-size: 150%;&quot;&gt;an error has occurred and email has been sent the administrator&lt;/b&gt;&lt;/div&gt;'
		);
	#
endif;

/* **********************************************************************
*	Framework_Database is a class created to manage database functions
*
*
*	The class manages all database interraction for the purpose of allowing certain things to be
*	turned on and off, as well as making development easier and more uniform.
*   An example would be Error Reporting.  Once the application is on the live
*	server, we can set $config-&gt;errors['display'] to false. Error reporting for database erros will not be shown.
*
*	This is real simple to use
*
*
*
*
******************************
**
**
**
**
**	Configuration ***
**		Scroll to the __construct method if you need to change which object
**		the database class uses for $config-&gt;connection and $config-&gt;errors
**
**
**
**
******************************
*
*	Examples:
*
********************
*
*		Get number of rows returned in a query (you can also nest this:
*			$sql = &quot;SELECT fieldA, fieldB FROM tableA&quot;; // would return 4 rows
*			$sql = $db-&gt;query($sql);
*			$rows = $db-&gt;num_rows();
*			echo $rows; // 4
*
*		Nested num_rows();
*			$a = &quot;SELECT fieldA FROM tableA&quot;; // would return 2 rows
*			$a = $db-&gt;query($a);
*			$a = $db-&gt;fetch_object($a);
*			$a_rows = $db-&gt;num_rows();
*			echo $a_rows; // 2
*
*			while ($a_row = $db-&gt;fetch_object($a) ) :
*				$b = &quot;SELECT fieldA FROM tableA WHERE fieldA = {$a_row-&gt;fieldA}&quot;; // would return 6 rows
*				$b = $db-&gt;fetch_object($b);
*				$b_rows = $db-&gt;num_rows();
*					echo $b_rows; // 6
*				while ( $b_row = $db-&gt;fetch_object($b)) :
*					echo $b_row-&gt;fieldA;
*				endwhile;
*			endwhile;
*
*
********************
*
*
*		Results as Object:
*			$sql = &quot;SELECT fieldA, fieldB FROM tableA&quot;;
*			$sql = $db-&gt;query($sql);
*
*			while ($row = $db-&gt;fetch_object($sql) ) :
*				echo $row-&gt;fieldA . ': ' . $row-&gt;fieldB;
*			endwhile;
*
*
********************
*
*
*		Results as Array:
*			$sql = &quot;SELECT fieldA, fieldB FROM tableA&quot;;
*			$sql = $db-&gt;query($sql);
*
*			while ($row = $db-&gt;fetch_array($sql) ) :
*				echo $row['fieldA'] . ': ' . $row['fieldB'];
*			endwhile;
*
*
********************
*
*
*		Return value of a row or field in a row
*		( uses the mysql_result() method rather than the more inefficient mysql_fetch_row() )
*
*		Specify the field's position in the Result Set
*			$sql = &quot;SELECT fieldA, fieldB FROM tableA&quot;;
*			$val = $db-&gt;fetch_row(1);        // would return fieldB's value
*
*		Specify the field name specifically
*			$val = $db-&gt;fetch_row('fieldA'); // would obviously return fieldA's value
*
*
********************
*
*
*		Return value of a query more efficiently (avoids the inefficient mysql_fetch_row() function)
*			$sql = &quot;SELECT fieldA FROM tableA&quot;;
*			$fieldA = $db-&gt;fetch_value($sql); // would return fieldA's value
*
*
********************
*
*
*		 Return the query result set as an array:
*			$sql = &quot;SELECT fieldA, fieldB FROM tableA&quot;; // returns 4 rows
*			$results = $db-&gt;to_array($sql);
*
*			$results[0]['fieldA'] = 'valueA 1';
*			$results[0]['fieldB'] = 'valueB 1';
*
*			$results[1]['fieldA'] = 'valueA 2';
*			$results[1]['fieldB'] = 'valueB 2';
*
*			$results[2]['fieldA'] = 'valueA 3';
*			$results[2]['fieldB'] = 'valueB 3';
*
*			$results[3]['fieldA'] = 'valueA 4';
*			$results[3]['fieldB'] = 'valueB 4';
*
* 		Example with foreach loop:
*			foreach ($results as $key=&gt;$result) :
*				echo $result['fieldA'].'&lt;br /&gt;'.$results['fieldB'];
*			endforeach;
*
*
********************************************************************** */

class Framework_Database {

	# set whether errors should be displayed or not
	# probably want to turn off once site is live
	var $connect_type  = 'mysql';
	var $sql_txt       = '';
	var $config;

	/* ****************************************************************
	*
	* __construct
	*
	**************************************************************** */
	function __construct() {
		$this-&gt;config = (object) array();

		# ####
		#
		# $config object:
		# 	To make it easier to change which object is used for
		# 	connection and error configuration, we'll set it here
		#
		# Change $config to whatever is used for configuration settings
		#
			global $config;
			$this-&gt;config-&gt;errors = $config-&gt;errors;
			$this-&gt;config-&gt;db     = $config-&gt;db;
		# END
		#
		# ####
	}
	/* ****************************************************************
	* end :::
	**************************************************************** */

	/* ****************************************************************
	*
	* Establish connection to the database
	* Be sure to set the connection info above
	*
	**************************************************************** */
	function connect() {
		global $config,$db;

			if ( !empty($config-&gt;db['db_name']) ) :

				#
				# try the connection
				$this-&gt;db_link = mysql_connect($config-&gt;db['host'], $config-&gt;db['user'], $config-&gt;db['password']);

				# The connection failed for some reason
				if ( !$this-&gt;db_link ) :
					die(&quot;Error connecting to the server&quot;);

				# The connection is good so lets get the Application Config Settings
				# and create the $config object
				else :
					$db_selected = mysql_select_db($config-&gt;db['db_name']);

				endif;

			endif;
	}
	/* ****************************************************************
	* end :::
	**************************************************************** */

	/* ****************************************************************
	*
	* Generates a random ID for the $sql object.
	* This allows nested query output
	*
	**************************************************************** */
	function sqlId() {
		$id = rand();
		$uniqueId[] = 'sql' . $id;
		$uniqueId[] = 'row' . $id;
		return $uniqueId;
	}
	/* ****************************************************************
	* end :::
	**************************************************************** */

	/* ****************************************************************
	*
	* Error
	* If @$config-&gt;errors['display'], print errors to screen
	* Else, we format the SQL and SQL error and email to
	*	$config-&gt;errors['email_to']
	*
	**************************************************************** */
	function error() {
		global $config, $__email;

		$display_error    = (bool) ( isset($config-&gt;errors['display']) &amp;&amp; @$config-&gt;errors['display'] );
		$has_error        = (bool) ( isset($this-&gt;error) &amp;&amp; !empty($this-&gt;error) );

		if ( @$display_error &amp;&amp; @$has_error ) :
			echo $this-&gt;error;

		else :

			# ####
			#
			# Error has occurred
			# Send an email if Display errors is turned off
			#
			if ( @$has_error ) :

				$site_domain = preg_replace(&quot;/^(.*\.)?([^.]*\..*)$/&quot;, &quot;$2&quot;, $_SERVER['HTTP_HOST']);
				# ####
				#
				# An error has occurred
				# Format the error email message so we can send it
				$vars['to']['email']   = $config-&gt;errors['email_to'];
				$vars['from']['email'] = 'no-reply@'.$site_domain;

				$vars['subject'] = 'Database Error Occurred ' . date('m-d-Y H:i:s');

				$sql_txt = nl2br($this-&gt;format_sql($this-&gt;sql_txt));
				$sql_txt = str_replace(&quot;\t&quot;,'&amp;nbsp;&amp;nbsp;', $sql_txt);

				$sql_err = nl2br($this-&gt;format_sql($this-&gt;error));
				$sql_err = str_replace(&quot;\t&quot;,'&amp;nbsp;&amp;nbsp;', $sql_err);

				$vars['message'] = &quot;&lt;p&gt;&lt;strong&gt;SQL Statement:&lt;/strong&gt;&lt;br /&gt;&quot;
								 . $sql_txt
								 . &quot;&lt;/p&gt;&quot;
								 . &quot;&lt;p&gt;&lt;strong&gt;Error Text:&lt;/strong&gt;&lt;br /&gt;&quot;
								 . $sql_err
								 . &quot;&lt;/p&gt;&quot;;
				# END
				#
				# ####

				# ####
				#
				# Put together the email and send it
				$boundary = md5( uniqid ( rand() ) );

				$to_name    = (isset($vars['to']['name'])) ? $vars['to']['name'] : $vars['to']['email'];
				$to_email   = $vars['to']['email'];
				$from_name  = (isset($vars['from']['name'])) ? $vars['from']['name'] : $vars['from']['email'];
				$from_email = $vars['from']['email'];
				$replyto    = isset($vars['replyto']) ? $vars['replyto'] : $vars['from']['email'];
				$subject    = $vars['subject'];
				$message    = $vars['message'];

				$headers  = &quot;From: &quot;.$from_email.&quot;\n&quot;;
				if (!empty($replyto)) :
					$headers  .= &quot;Reply-To: &quot;.$replyto.&quot;\n&quot;;
				endif;
				$headers .= &quot;Received: \&quot;&quot;.$to_name.&quot;\&quot; &lt;&quot;.$to_email.&quot;&gt;\n&quot;;
				$headers .= &quot;MIME-Version: 1.0\n&quot;;
				$headers .= &quot;Subject: &quot;.$subject.&quot;\n&quot;;
				$headers .= &quot;Content-Type: multipart/related;&quot;;
				$headers .= &quot;boundary=\&quot;------------&quot;.$boundary.&quot;\&quot;\n&quot;;
				$headers .= &quot;This is a multi-part message in MIME format.\n&quot;;
				$headers .= &quot;--------------&quot;.$boundary.&quot;\n&quot;;
				$headers .= &quot;Content-Type: text/html; charset=ISO-8859-1\n&quot;;
				$headers .= &quot;Content-Transfer-Encoding: 7bit&quot;;

				mail($to_email, $subject, $message, $headers);
				# END
				#
				# ####
			endif;

		endif;
		$this-&gt;error='';
	}
	/* ****************************************************************
	* end :::
	**************************************************************** */

	/* ****************************************************************
	*
	* Formats the SQL Statement. Hand for screen print
	* Mainly used for the error email, to make it more readable
	*
	**************************************************************** */
	function format_sql( $sql ) {

		$reserved_words = array(
			&quot;/SELECT/&quot;,
			&quot;/FROM/&quot;,
			&quot;/WHERE/&quot;,
			&quot;/CONCAT/&quot;,
			&quot;/INNER /&quot;,
			&quot;/ JOIN/&quot;,
			&quot;/LEFT /&quot;,
			&quot;/RIGHT /&quot;,
			&quot;/MATCH/&quot;,
			&quot;/AGAINST/&quot;,
			&quot;/AND/&quot;,
			&quot;/ORDER BY/&quot;,
			&quot;/ OR /&quot;,
			&quot;/ASC/&quot;,
			&quot;/DESC/&quot;,
			&quot;/LIMIT/&quot;,
			&quot;/ IN /&quot;,
			&quot;/SUM/&quot;,
			&quot;/GROUP BY/&quot;,
			&quot;/GROUP_/&quot;,
			&quot;/SEPARATOR/&quot;
		);

		$sql_err = '';
		$sql_txt = $sql;
		if ( strstr($sql, 'Query: ') ) :
			$sql = explode('Query: ', $sql);
			$sql_err = $sql[0];
			$sql_txt = $sql[1];
		endif;

		$sql_txt = preg_replace($reserved_words, &quot;&lt;span class=\&quot;reserved_word\&quot; style=\&quot;color: #3f97c6!important; font-weight: bold!important;\&quot;&gt;$0&lt;/span&gt;&quot;, $sql_txt);
		return $sql_err.$sql_txt;
	}
	/* ****************************************************************
	* end :::
	**************************************************************** */

	/* ****************************************************************
	*
	* Run the query
	*
	**************************************************************** */
	function query( $sql='' ) {

		## keep the string value of the SQL statement in case of error
		$this-&gt;sql_txt = $sql;

		if ( $this-&gt;connect_type == 'mysql' ) :
			$this-&gt;result=mysql_query( $sql );

			if ( !$this-&gt;result ) :
				$this-&gt;error = mysql_error() . '&lt;br /&gt;Query: '.$sql;
				$this-&gt;error();
				$this-&gt;result = false;
			endif;

		else :
			$result = mysqli_query( $this-&gt;db_link, $sql );
			$this-&gt;result = $result;

			if ( !$this-&gt;result ) :
				$this-&gt;error = mysqli_error($this-&gt;db_link) . '&lt;br /&gt;Query: '.$sql;
				$this-&gt;error();
				$this-&gt;result = false;
			endif;

		endif;

		return $this-&gt;result;
	}
	/* ****************************************************************
	* end :::
	**************************************************************** */

	/* ****************************************************************
	*
	* Connect to the server using the mysqli extension
	* This is used automatically during multi_query()
	*
	**************************************************************** */
	function mySqliConnect() {
		global $config;
		$this-&gt;mySqli = new mysqli($config-&gt;db['host'], $config-&gt;db['user'], $config-&gt;db['password'], $config-&gt;db['db_name']);
		return $this-&gt;mySqli;
	}
	/* ****************************************************************
	* end :::
	**************************************************************** */

	/* ****************************************************************
	*
	* Close the mysqli connection once we have finished
	* using the multi_query() method
	*
	**************************************************************** */
	function mySqliClose() {
		mysqli_close($this-&gt;mySqli);
	}
	/* ****************************************************************
	* end :::
	**************************************************************** */

	/* ****************************************************************
	*
	* Execture the multi-query
	*
	**************************************************************** */
	function multi_query( $sql='' ) {

		## keep the string value of the SQL statement in case of error
		$this-&gt;sql_txt = $sql;

		$mysqli = $this-&gt;mySqliConnect();

		$this-&gt;result = mysqli_multi_query( $mysqli, $sql );

		if ( !$this-&gt;result ) :
			$this-&gt;error = mysql_error() . '&lt;br /&gt;Query: '.$sql;
			$this-&gt;error();
		else :
			$this-&gt;mySqliClose();
			return $this-&gt;result;
		endif;
	}
	/* ****************************************************************
	* end :::
	**************************************************************** */

	/* ****************************************************************
	*
	* Returns the results of the query as an object
	*
	* Example:
	*	$sql = &quot;SELECT fieldA, fieldB FROM tableA&quot;;
	*	$sql = $db-&gt;query($sql);
	*
	*	while ($row = $db-&gt;fetch_object($sql) ) :
	*		echo $row-&gt;fieldA . ': ' . $row-&gt;fieldB;
	*	endwhile;
	*
	**************************************************************** */
	function fetch_object( $sql ) {
		if ( @$this-&gt;result ) :
			$uniqueIdentifier=rand();
			if ( $this-&gt;connect_type == 'mysql' ) :
				$$uniqueIdentifier=mysql_fetch_object( $sql );
			else :
				$$uniqueIdentifier=mysql_fetch_object( $sql );
			endif;
			return $$uniqueIdentifier;
			unset( $$uniqueIdentifier );
		endif;
	}
	/* ****************************************************************
	* end :::
	**************************************************************** */

	/* ****************************************************************
	*
	* Returns the results of the query as an array
	*
	* Example:
	*	$sql = &quot;SELECT fieldA, fieldB FROM tableA&quot;;
	*	$sql = $db-&gt;query($sql);
	*
	*	while ($row = $db-&gt;fetch_object($sql) ) :
	*		echo $row['fieldA'] . ': ' . $row['fieldB'];
	*	endwhile;
	*
	**************************************************************** */
	function fetch_array( $sql ) {
		if ( @$this-&gt;result ) :
			$uniqueIdentifier=rand();
			$$uniqueIdentifier=mysql_fetch_array( $sql );
			return $$uniqueIdentifier;
			unset( $$uniqueIdentifier );
		endif;
	}
	/* ****************************************************************
	* end :::
	**************************************************************** */

	/* ****************************************************************
	*
	* Returns the number of rows returned in a query
	*
	**************************************************************** */
	function num_rows($result='') {
		if ( @$this-&gt;result ) :
			$uniqueIdentifier=rand();
			if (empty($result)) $result = $this-&gt;result;
			$$uniqueIdentifier=mysql_num_rows( $result );
			return $$uniqueIdentifier;
			unset( $$uniqueIdentifier );
		else :
			return 0;
		endif;
	}
	/* ****************************************************************
	* end :::
	**************************************************************** */

	/* ****************************************************************
	*
	* Returns the number of rows affected by a query
	*
	**************************************************************** */
	function rows_affected($result='') {
		if ( @$this-&gt;result ) :
			$uniqueIdentifier=rand();
			if (empty($result)) $result = $this-&gt;result;
			$$uniqueIdentifier = mysql_rows_affected( $result );
			return $$uniqueIdentifier;
			unset( $$uniqueIdentifier );
		else :
			return 0;
		endif;
	}
	/* ****************************************************************
	* end :::
	**************************************************************** */

	/* ****************************************************************
	*
	* Runs the mysql_result() function, but a little differently
	*
	* if $this-&gt;fetch_row(1), it will return the second field
	* of the first row
	*
	* if $this-&gt;fetch_row('field_name'), it will return the value
	* for 'field_name' in the first row
	*
	**************************************************************** */
	function fetch_row ( $fieldName ) {
		if (is_numeric( $fieldName )) {
			$fieldValue=mysql_result( $this-&gt;result, $fieldName );
		} else {
			$fieldValue=mysql_result( $this-&gt;result, 0, $fieldName );
		}
		return $fieldValue;
	}
	/* ****************************************************************
	* end :::
	**************************************************************** */

	/* ****************************************************************
	*
	* Returns the value of the specified field, in the specified
	* row.
	*
	* If no field or row is specified, it will default to first
	* row, first field
	*
	**************************************************************** */
	function fetch_value ( $sql='', $fieldName='', $row='' ) {
		$i=0;
		$fieldValue = false;

		if (empty($fieldName)) { $fieldName = 0; }
		if (empty($row)) { $row = 0; }
		$ret = array();
		$sql = $this-&gt;query($sql);
		if ($this-&gt;num_rows() &gt; 0) {
			while ($rec = mysql_fetch_array( $sql )) {
				for ($a=0; $a &lt; count($rec); $a++) {
					$ret[$i] = $rec;
				}
				$i++;
			}

			$fieldValue=$ret[$row][$fieldName];
		}

		return ($fieldValue);
	}
	/* ****************************************************************
	* end :::
	**************************************************************** */

	/* ****************************************************************
	*
	* Returns the results of the query as an array
	*
	* Example:
	*	$sql = &quot;SELECT fieldA, fieldB FROM tableA&quot;; // returns 4 rows
	*	$results = $db-&gt;to_array($sql);
	*
	*	$results[0]['fieldA'] = 'valueA 1';
	*	$results[0]['fieldB'] = 'valueB 1';
	*
	*	$results[1]['fieldA'] = 'valueA 2';
	*	$results[1]['fieldB'] = 'valueB 2';
	*
	*	$results[2]['fieldA'] = 'valueA 3';
	*	$results[2]['fieldB'] = 'valueB 3';
	*
	*	$results[3]['fieldA'] = 'valueA 4';
	*	$results[3]['fieldB'] = 'valueB 4';
	*
	* Example with foreach loop:
	*	foreach ($results as $key=&gt;$result) :
	*		echo $result['fieldA'].'&lt;br /&gt;'.$results['fieldB'];
	*	endforeach;
	*
	**************************************************************** */
	function to_array ( $sql='' ) {

		## keep the string value of the SQL statement in case of error
		$this-&gt;sql_txt = $sql;

		$i=0;
		$ret = array();
		$sql = $this-&gt;query($sql);
		if ( $this-&gt;connect_type == 'mysql' ) :
			if ( $sql ) :
				while ($row = mysql_fetch_assoc( $sql )) :
					for ($a=0; $a &lt; count($row); $a++) :
						$ret[$i] = $row;
					endfor;
					$i++;
				endwhile;
			endif;
		else :
			if ( $sql ) :
				while ($row = mysqli_fetch_assoc( $sql )) :
					for ($a=0; $a &lt; count($row); $a++) :
						$ret[$i] = $row;
					endfor;
					$i++;
				endwhile;
			endif;
		endif;
		return ($ret);
	}
	/* ****************************************************************
	* end :::
	**************************************************************** */

	/* ****************************************************************
	*
	* closes the database connection
	*
	* PHP nowadays does a really good job of trashing these connection
	* automatically. However, just to be safe, I typically call this
	* method in an include that is loaded after everything else
	*
	**************************************************************** */
	function close_db() {
		if ($this-&gt;db_link) :
			mysql_close($this-&gt;db_link);
		endif;
	}
	/* ****************************************************************
	* end :::
	**************************************************************** */

}
/* *********************************************************************************
* END :::
********************************************************************************* */
$db = new Framework_Database;
$db-&gt;connect();
?&gt;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://jjis.me/a/253/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

