Location: PHPKode > scripts > My One Line SQL > my-one-line-sql/READ_ME.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>READ_ME</title>
	<style type="text/css">
<!--
body {background-color:#CCCCCC; color:#000000; font-family:arial;font-size:12px;}
-->
</style>
</head>
<body>
<p>This document provides info and examples for the <code>MyOneLineSQL</code> package</p>
<p>The following list of queries are supported by the <code>MyOneLineSQL</code> class:</p>
<ul>
<li><code>SELECT what FROM tablename</code></li>
<li><code>SELECT what FROM tablename WHERE where_expression</code></li>
<li><code>SELECT what FROM tablename ORDER BY order_expression ASC/DESC</code></li>
<li><code>SELECT what FROM tablename WHERE where_expression ORDER BY order_text ASC/DESC</code></li>
<li><code>SELECT what FROM tablename WHERE where_expression ORDER BY order_text ASC/DESC LIMIT query_limits</code></li>
<li><code>UPDATE tablename SET which_set WHERE where_expression</code></li>
<li><code>INSERT INTO tablename (fields) VALUES (which_VALUES)</code></li>
<li><code>CREATE TABLE table_structure</code></li>
<li><code>ALTER TABLE tablename ADD add_what AFTER after_what</code></li>
<li><code>SHOW TABLES</code></li>
<li>
<code>DROP TABLE tablename</code></li>
<li><code>DELETE FROM tablename WHERE where_expression</code></li>
<li><code>OPTIMIZE TABLE tablename</code></li>
</ul>
<p>The MyOneLineSQL package is made of the following classes: </p>
<ul>
<li>
<h1>The <code>Parameterable</code> Interface:</h1>
<p>This interface marks a class as able to set text paramaters (such as <code>{PARAM}</code>) that can be processed and replaced by their actual values.</p>
</li>
<li><h1>The <code>SQLable</code> Interface</h1>
<p>This interface marks a class as able to set and get connections to a database</p>
<p>Implementing classes must have a private instance variable such as <code>$dbc</code> and provide its setter and getter methods</p>
</li>
<li><h1>The <code>DBQuery</code> class</h1>
<p>This class provides members to enable the creation of a mySQL query string. This class does not run or execute queries to databases.</p>
<p>DBQuery class implements Parameterable. This enable to set parameters for objects of this class.<br />
For example the parameter {TABLE_NAME} will be replaced by the actual value when running a query to database</p>
<p>The following is the list of parameters used by this class:</p>
<ul>
<li>{WHAT}</li>
<li>{TABLE_NAME}</li>
<li>{WHERE_EXP}</li>
<li>{WHICH_SET}</li>
<li>{WHICH_VALUES}</li>
<li>{ASC_DESC}</li>
<li>{ORDER_BY}</li>
<li>{TABLE_STRUCTURE}</li>
<li>{ADD_WHAT}</li>
<li>{AFTER_WHAT}</li>
<li>{QUERY_LIMITS}</li>
</ul>
<p>Constructors for DBQuery objects take strings (keywords) as their arguments. The string 'keyword' enable a certain query to be defined when creating new DBQuery obejcts. Depening on the keyword given, a set of parameters must be defined in order to successfully run a query via RunDBQuery objects.</p>
<p>The following is the list of keywords supported by this class:</p>
<ul>
<li>SELECT</li>
<li>SELECT_ORDER</li>
<li>SELECT_WHERE</li>
<li>SELECT_WHERE_ORDER</li>
<li>SELECT_WHERE_ORDER_LIMIT</li>
<li>UPDATE</li>
<li>INSERT</li>
<li>CREATE</li>
<li>ALTER</li>
<li>DROP_TABLE</li>
<li>DELETE_WHERE</li>
<li>SHOW</li>
<li>OPTIMIZE</li>
</ul>
<p>For example it is possible to define a select query in this way</p>
<pre>
$q = new DBQuery ( 'SELECT_WHERE' );
$q->SetParameters ( "WHAT", '*' );
$q->SetParameters ( "TABLE_NAME", 'users' );
$q->SetParameters ( "WHERE_EXP", "username='dummy'" );
$q->queryBuilder ();

// to see query built 
echo $q->getThisQuery ();
</pre>
<p>Unless someone is extending the class and adding new paramated query templates, it won't be needed to go through the process of defining parameters for a query as this will be job of the <code>MyOneLineSQL</code> class and the same can be achieved by invoking one of its static methods as follow</p>

<pre>MyOneLineSQL::doSelectWhere('users', $dbc, "username='dummy'", array('*'))</pre>
<p><code>$dbc</code> must refer to a successful database connection reference. A database connection reference constant can be established via the DBConnect class</p>
</li>
<li><h1>The <code>DBConnect</code> class</h1>
<p>This class cannot be instantiated and has only one public static method. This class needs access to file containing definition of costants for database name, user, password and host. It is important to make sure the correct path to the file cvars.inc.php (or else) is given to this class via <code>include_once()</code> function found before class header</p>
<p>For security reasons cvars.inc.php should be placed in a non-public directory, usually one directory above public_html</p>
<p>By calling the static method <code>doDBConnection()</code> the costant <code>DBC</code> is defined. This can then be passed to objects implementing the SQLable interface, granting them access to the database.</p>
<p>As an example it is possible to rewrite the above code as:</p>
<pre>
DBConnect::doDBConnection();
MyOneLineSQL::doSelectWhere('users', DBC, "username='dummy'", array('*'))
</pre>
<p>By passing the <code>DBC</code> constant to the method, the <code>MyOneLineSQL</code> class receives connection to database. What happens in reality is that a RunDBQuery object (implementing <code>SQLable</code> interface) is using this value to execute the query, as the <code>MyOneLineSQL</code> class is not <code>SQLable</code> and does not implement the interface.</p>
</li>
<li><h1>The <code>RunDBQuery</code> class</h1>
<p>This class does the dirty job of executing queries. Constructors for RunDBQuery objects must always receive a DBQuery object passed as argument.</p>
<p>Once a query has run successfully, instances of this class will hold query results and info, and its protocol can be used to do the following:</p>
<ul>
<li>Get the keyword value from <code>DBQuery</code> objects</li>
<li>Get the result reference for executed queries</li>
<li>Get the result assoc array for executed queries</li>
<li>Get the mySQL string to be executed and defined in DBQuery object given to constructor</li>
<li>Get a string representation of the fields and values returned by the executed query</li>
<li>Get a string representation of only the values returned by the executed query</li>
<li>Get a possible mySQL error from executed query</li>
<li>Free the result for the executed query</li>
<li>Get the number of rows for executed query</li>
<li>Get the number of fields for executed query</li>
<li>Get a particular value from a query</li>
<li>Get the array of field names for executed query</li>
<li>Get the integer indexed array result for executed query</li>
<li>Get number of affected rows for executed query</li>
<li>Create and get a set from query result array. This will remove duplicate values from query result array.</li>
</ul>
</li>
<p>RunDBQuery class implements the SQLable interface and as a result it also provides the methods <code>getDbc()</code> and <code>setDbc($adbc)</code> to enable database connection to instances</p>
<li><h1>The <code>MyOneLineSQL</code> class</h1>
<p>The MyOneLineSQL class is a utility class and only provides static methods, it cannot be instantiated.</p>
<p>Each static method always return a RunDBQuery object from which it is possible to get executed query info and result array via its public members. This class is a composition of DBQuery and RunDBQuery objects and allows to execute mySQL query in just one line of code.</p>
<p>This is its procol:</p>
<ul>
<li><code><strong>doSelect($dbTableName, $dbc, $dbFields = array())</strong></code>
<p>where <code>$dbTableName</code> is the table to select, <code>$dbc</code> a database connection reference and <code>$dbFields</code> the array of fields names to select. It is possible to use wild card <code>*</code> to select all fields in a query</p>
<p><em>Example</em></p>
<pre>
DBConnect::doDBConnection();
MyOneLineSQL::doSelect('users', DBC, array('*'));
</pre>
<p><em>Example of selecting only certain fields</em></p>
<pre>
DBConnect::doDBConnection();
MyOneLineSQL::doSelect('users', DBC, array('username', 'password'));
</pre>
</li>
<li><code>doSelectWhere($dbTableName, $dbc, $where, $dbFields = array())</code>
<p>where <code>$dbTableName</code> is the table to select, <code>$dbc</code> a database connection reference, <code>$where</code> a where expression (such as <code>username='dummy'</code>) and <code>$dbFields</code> an array of  fields names.<br />
 <strong>NOTE: </strong><code>$where</code> should not contain the SQL keyword WHERE as this is automatically included when parameters are processed by DBQuery objects.</p>
</li>
<li><code>doSelectOrder($dbTableName, $dbc, $order, $asc_desc = "", $dbFields = array())</code>
<p>where <code>$dbTableName</code> is the table to select, <code>$dbc</code> a database connection reference, <code>$order</code> is a database field name, $asc_desc a ordering mode and <code>$dbFields</code> the array of fields names to select.</p>
<p><em>Example</em></p>
<pre>
DBConnect::doDBConnection();
MyOneLineSQL::doSelectOrder('users', DBC, 'user_id', 'ASC', array('username'));
</pre>
<strong>NOTE: </strong><code>$order</code> should not contain the SQL keyword ORDER BY as this is automatically included when parameters are processed by DBQuery objects.</p>
</li>
<li><code>doSelectWhereOrder($dbTableName, $dbc, $where, $order, $asc_desc = "", $dbFields = array())</code>
<p>see above for arguments info</p>
<p><em>Example</em></p>
<pre>
DBConnect::doDBConnection();
MyOneLineSQL::doSelectWhereOrder('users', DBC, "user_id > '2'" 'user_id', 'ASC', array('username'));
</pre>
</li>
<li><code>doSelectWhereOrderByLimit($dbTableName, $dbc, $where, $order, $limit, $asc_desc = "", $dbFields = array())</code>
<p><em>Example</em></p>
<pre>
DBConnect::doDBConnection();
MyOneLineSQL::doSelectWhereOrderByLimit('users', DBC, "user_id > '2'" 'user_id', '0,10', 'ASC', array('username'));
</pre></li>
<li><code>doInsert($dbTableName, $dbc, $values = array())</code>
<p><em>Example</em></p>
<pre>
DBConnect::doDBConnection();
MyOneLineSQL::doInsert('users(username, password, email)', DBC, array($username, $password, $email));
</pre>
</li>
<li><code>doCreateTable($tableStructure, $dbc)</code>
<p><em>Example</em></p>
<pre>
$structure = "users (
  	          id int UNSIGNED NOT NULL auto_increment,
  	          username VARCHAR(16) NULL,
  	          password  VARCHAR(32) NULL,
  	          acc_email  VARCHAR(100) NULL,
  	          PRIMARY KEY (id),
	          INDEX(username)
	          )TYPE=MyISAM;";
	
DBConnect::doDBConnection();
MyOneLineSQL::doCreateTable($structure, DBC);
</pre>
</li>
<li><code>doAlterTable($dbTableName, $dbc, $add_what, $after_what)</code>
<p><em>Example</em></p>
<pre>
DBConnect::doDBConnection();
MyOneLineSQL::doAlterTable('users', DBC, "first_name VARCHAR(20) NULL", 'acc_email');
</pre>
</li>
<li><code>doDropTable($dbTableName, $dbc)</code>
<p><em>Example</em></p>
<pre>
DBConnect::doDBConnection();
MyOneLineSQL::doDropTable('users', DBC);
</pre>
</li>
<li><code>doDeleteWhere($dbTableName, $dbc, $where)</code>
<p><em>Example</em></p>
<pre>
DBConnect::doDBConnection();
MyOneLineSQL::doDeleteWhere('users', DBC, "username='dummy'");
</pre>
</li>
<li><code>doShowTables($dbc)</code>
<p><em>Example</em></p>
<pre>
DBConnect::doDBConnection();
$objectResult = MyOneLineSQL::doShowTables(DBC);
foreach ( $objectResult->getQueryResultArray () as $value )
{
    foreach ( $value as $v )
    {
        print $v;
    }
}
// ALSO
foreach ( $objectResult->getIntIndexedResultArray () as $value )
{
   print $value;
}
</pre>
</li>
<li><code>doOptimize($dbTableName, $dbc)</code>
<p><em>Example</em></p>
<pre>
DBConnect::doDBConnection();
MyOneLineSQL::doOptimize('users', DBC);
</pre>
</li>
<li><code>doOptimizeAll($dbc)</code>
<p><em>Example</em></p>
<pre>
DBConnect::doDBConnection();
MyOneLineSQL::doOptimizeAll(DBC);
</pre>
</li>
</ul>
</li>
</ul>
<h1>How to get executed query info and results array</h1>
<p><em>Example for select queries</em></p>
<pre>
DBConnect::doDBConnection();
$objectResult = MyOneLineSQL::doSelect('users', DBC, array('username', 'password'));
// to process result array
foreach ( $objectResult->getQueryResultArray () as $value )
{
    foreach ( $value as $v )
    {
       // do something with value
    }
}
// also possible
$resultArray = array();
$resultArray = $objectResult->getIntIndexedResultArray ();
for ($i = 0; $i < count($resultArray); $i++)
{
   print $resultArray [$i];
}
</pre>
<h1>How to get single values from result arrays</h1>
<p>This is achieved via the public method giveValueOf() part of the RunDBQuery class protocol</p>
<p><em>Example</em></p>
<pre>
DBConnect::doDBConnection();
$objectResult = MyOneLineSQL::doSelectWhere('users', DBC, "username='dummy'", array('acc_email'));
$objectResult->giveValueOf('acc_email', 0);
</pre>
<h1>Real examples code and outputs</h1>
<p>The following code examples and outputs have been taken from real execution on a server.</p>
<pre>
&lt;?php
include_once 'Parameterable.class.php';
include_once 'SQLable.class.php';
include_once 'DBconnect.class.php';
include_once 'DBQuery.class.php';
include_once 'RunDBQuery.class.php';
include_once 'MyOneLineSQL.class.php';
DBconnect::doDBConnection ();
$resultArray = array ( );
$resultObject = MyOneLineSQL::doSelect ( 'accounts', DBC, array ('acc_uname' ) );
$resultArray = $resultObject-&gt;getQueryResultArray ();
$intResultArray = $resultObject-&gt;getIntIndexedResultArray ();
echo 'Assoc Array dump';
echo '&lt;br /&gt;';
var_dump ( $resultArray );
echo '&lt;br /&gt;';
echo '&lt;br /&gt;';
echo 'Int indexed array dump';
echo '&lt;br /&gt;';
var_dump ( $intResultArray );
echo '&lt;br /&gt;';
echo '&lt;br /&gt;';
echo 'String representation of result array with field value pair';
echo '&lt;br /&gt;';
echo $resultObject-&gt;toString ();
echo '&lt;br /&gt;';
echo '&lt;br /&gt;';
echo 'String representation of result array with just values';
echo '&lt;br /&gt;';
echo $resultObject-&gt;toStringV ();
echo '&lt;br /&gt;';
echo '&lt;br /&gt;';
echo 'Number of rows';
echo '&lt;br /&gt;';
echo $resultObject-&gt;getNumberOfRows ();
echo '&lt;br /&gt;';
echo '&lt;br /&gt;';
echo 'Number of fields';
echo '&lt;br /&gt;';
echo $resultObject-&gt;getNumberOfFields ();
echo '&lt;br /&gt;';
echo '&lt;br /&gt;';
echo 'Value of acc_uname for row 0';
echo '&lt;br /&gt;';
echo $resultObject-&gt;giveValueOf ( 'acc_uname', 0 );
echo '&lt;br /&gt;';
echo '&lt;br /&gt;';
echo 'Value of acc_uname for row 1';
echo '&lt;br /&gt;';
echo $resultObject-&gt;giveValueOf ( 'acc_uname', 1 );
echo '&lt;br /&gt;';
echo '&lt;br /&gt;';
echo 'Query info';
echo '&lt;br /&gt;';
echo $resultObject-&gt;getQueryResultInfo ();
echo '&lt;br /&gt;';
echo '&lt;br /&gt;';
echo 'Query executed';
echo '&lt;br /&gt;';
echo $resultObject-&gt;getQueryToRun ();
echo '&lt;br /&gt;';
echo '&lt;br /&gt;';
echo 'Keyword used by DBQuery object';
echo '&lt;br /&gt;';
echo $resultObject-&gt;getKeyword ();
echo '&lt;br /&gt;';
echo '&lt;br /&gt;';
$resultObject2 = MyOneLineSQL::doUpdateWhere ( 'accounts', DBC, "username='docooph'", array ("acc_email='hide@address.com'" ) );
echo 'Affected Rows from query ' . $resultObject2-&gt;getQueryToRun ();
echo '&lt;br /&gt;';
echo $resultObject2-&gt;getAffectedRows () . " This is correct as there is no username field in database";
echo '&lt;br /&gt;';
echo '&lt;br /&gt;';
$resultObject3 = MyOneLineSQL::doUpdateWhere ( 'accounts', DBC, "acc_uname='docooph'", array ("acc_email='hide@address.com'" ) );
echo 'Affected Rows from query ' . $resultObject3-&gt;getQueryToRun ();
echo '&lt;br /&gt;';
echo $resultObject3-&gt;getAffectedRows ();
echo '&lt;br /&gt;';
echo '&lt;br /&gt;';
$resultObject4 = MyOneLineSQL::doUpdateWhere ( 'accounts', DBC, "acc_uname='docooph2'", array ("acc_email='hide@address.com'" ) );
echo 'Affected Rows from query ' . $resultObject4-&gt;getQueryToRun ();
echo '&lt;br /&gt;';
echo $resultObject4-&gt;getAffectedRows ();
echo '&lt;br /&gt;';
echo '&lt;br /&gt;';

$resultArray = array ( );
$resultObject = MyOneLineSQL::doSelect ( 'accounts', DBC, array ('acc_uname, acc_email' ) );
$resultArray = $resultObject-&gt;getQueryResultArray ();
$intResultArray = $resultObject-&gt;getIntIndexedResultArray ();
echo 'Assoc Array dump';
echo '&lt;br /&gt;';
var_dump ( $resultArray );
echo '&lt;br /&gt;';
echo '&lt;br /&gt;';
echo 'Int indexed array dump';
echo '&lt;br /&gt;';
var_dump ( $intResultArray );
echo '&lt;br /&gt;';
echo '&lt;br /&gt;';
echo 'String representation of result array with field value pair';
echo '&lt;br /&gt;';
echo $resultObject-&gt;toString ();
echo '&lt;br /&gt;';
echo '&lt;br /&gt;';
echo 'String representation of result array with just values';
echo '&lt;br /&gt;';
echo $resultObject-&gt;toStringV ();
echo '&lt;br /&gt;';
echo '&lt;br /&gt;';
echo 'Number of rows';
echo '&lt;br /&gt;';
echo $resultObject-&gt;getNumberOfRows ();
echo '&lt;br /&gt;';
echo '&lt;br /&gt;';
echo 'Number of fields';
echo '&lt;br /&gt;';
echo $resultObject-&gt;getNumberOfFields ();
echo '&lt;br /&gt;';
echo '&lt;br /&gt;';
echo 'Value of acc_uname for row 0';
echo '&lt;br /&gt;';
echo $resultObject-&gt;giveValueOf ( 'acc_uname', 0 );
echo '&lt;br /&gt;';
echo '&lt;br /&gt;';
echo 'Value of acc_uname for row 1';
echo '&lt;br /&gt;';
echo $resultObject-&gt;giveValueOf ( 'acc_uname', 1 );
echo '&lt;br /&gt;';
echo '&lt;br /&gt;';
echo 'Query info';
echo '&lt;br /&gt;';
echo $resultObject-&gt;getQueryResultInfo ();
echo '&lt;br /&gt;';
echo '&lt;br /&gt;';
echo 'Query executed';
echo '&lt;br /&gt;';
echo $resultObject-&gt;getQueryToRun ();
echo '&lt;br /&gt;';
echo '&lt;br /&gt;';
echo 'Keyword used by DBQuery object';
echo '&lt;br /&gt;';
echo $resultObject-&gt;getKeyword ();
echo '&lt;br /&gt;';
echo '&lt;br /&gt;';
$usernameCheck = MyOneLineSQL::doSelectWhere ( 'accounts', DBC, "acc_uname='dummy'", array ('acc_uname' ) );
if ($usernameCheck-&gt;getNumberOfRows () == 0)
{
   $resultObject = MyOneLineSQL::doInsert ( 'accounts(acc_uname, acc_pass, acc_email)', DBC, array ('dummy', 'xxxxxxxx', 'hide@address.com' ) );
   if (strip_tags ( $resultObject-&gt;toStringV () ) == 'success')
   {
      echo "New values inserted in database";
      echo '&lt;br /&gt;'; echo '&lt;br /&gt;';
   }
}
else 
{
   echo "dummy user already in database";
   echo '&lt;br /&gt;'; echo '&lt;br /&gt;';
}

$resultArray = array ( );
$resultObject = MyOneLineSQL::doSelect ( 'accounts', DBC, array ('acc_uname, acc_email' ) );
$resultArray = $resultObject-&gt;getQueryResultArray ();
$intResultArray = $resultObject-&gt;getIntIndexedResultArray ();
echo 'Assoc Array dump';
echo '&lt;br /&gt;';
var_dump ( $resultArray );
echo '&lt;br /&gt;';
echo '&lt;br /&gt;';
echo 'Int indexed array dump';
echo '&lt;br /&gt;';
var_dump ( $intResultArray );
echo '&lt;br /&gt;';
echo '&lt;br /&gt;';
echo 'String representation of result array with field value pair';
echo '&lt;br /&gt;';
echo $resultObject-&gt;toString ();
echo '&lt;br /&gt;';
echo '&lt;br /&gt;';
echo 'String representation of result array with just values';
echo '&lt;br /&gt;';
echo $resultObject-&gt;toStringV ();
echo '&lt;br /&gt;';
echo '&lt;br /&gt;';
echo 'Number of rows';
echo '&lt;br /&gt;';
echo $resultObject-&gt;getNumberOfRows ();
echo '&lt;br /&gt;';
echo '&lt;br /&gt;';
echo 'Number of fields';
echo '&lt;br /&gt;';
echo $resultObject-&gt;getNumberOfFields ();
echo '&lt;br /&gt;';
echo '&lt;br /&gt;';
echo 'Value of acc_uname for row 0';
echo '&lt;br /&gt;';
echo $resultObject-&gt;giveValueOf ( 'acc_uname', 0 );
echo '&lt;br /&gt;';
echo '&lt;br /&gt;';
echo 'Value of acc_uname for row 2';
echo '&lt;br /&gt;';
echo $resultObject-&gt;giveValueOf ( 'acc_uname', 2 );
echo '&lt;br /&gt;';
echo '&lt;br /&gt;';
echo 'Query info';
echo '&lt;br /&gt;';
echo $resultObject-&gt;getQueryResultInfo ();
echo '&lt;br /&gt;';
echo '&lt;br /&gt;';
echo 'Query executed';
echo '&lt;br /&gt;';
echo $resultObject-&gt;getQueryToRun ();
echo '&lt;br /&gt;';
echo '&lt;br /&gt;';
echo 'Keyword used by DBQuery object';
echo '&lt;br /&gt;';
echo $resultObject-&gt;getKeyword ();
echo '&lt;br /&gt;';
echo '&lt;br /&gt;';
?&gt;
</pre>
<h3>Output</h3>
<pre>
Assoc Array dump
array(3) { [0]=> array(1) { ["acc_uname"]=> string(7) "docooph" } [1]=> array(1) { ["acc_uname"]=> string(8) "docooph2" } [2]=> array(1) { ["acc_uname"]=> string(5) "dummy" } } 

Int indexed array dump
array(3) { [0]=> string(7) "docooph" [1]=> string(8) "docooph2" [2]=> string(5) "dummy" } 

String representation of result array with field value pair
acc_uname docooph

acc_uname docooph2

acc_uname dummy



String representation of result array with just values
docooph

docooph2

dummy



Number of rows
3

Number of fields
1

Value of acc_uname for row 0
docooph

Value of acc_uname for row 1
docooph2

Query info
SELECT acc_uname FROM accounts has run successfully.

Query executed
SELECT acc_uname FROM accounts

Keyword used by DBQuery object
SELECT

Affected Rows from query UPDATE accounts SET acc_email='hide@address.com' WHERE username='docooph'
-1 This is correct as there is no username field in database

Affected Rows from query UPDATE accounts SET acc_email='hide@address.com' WHERE acc_uname='docooph'
1

Affected Rows from query UPDATE accounts SET acc_email='hide@address.com' WHERE acc_uname='docooph2'
1

Assoc Array dump
array(3) { [0]=> array(2) { ["acc_uname"]=> string(7) "docooph" ["acc_email"]=> string(9) "hide@address.com" } [1]=> array(2) { ["acc_uname"]=> string(8) "docooph2" ["acc_email"]=> string(10) "hide@address.com" } [2]=> array(2) { ["acc_uname"]=> string(5) "dummy" ["acc_email"]=> string(14) "hide@address.com" } } 

Int indexed array dump
array(6) { [0]=> string(7) "docooph" [1]=> string(9) "hide@address.com" [2]=> string(8) "docooph2" [3]=> string(10) "hide@address.com" [4]=> string(5) "dummy" [5]=> string(14) "hide@address.com" } 

String representation of result array with field value pair
acc_uname docooph
acc_email hide@address.com

acc_uname docooph2
acc_email hide@address.com

acc_uname dummy
acc_email hide@address.com



String representation of result array with just values
docooph
hide@address.com

docooph2
hide@address.com

dummy
hide@address.com



Number of rows
3

Number of fields
2

Value of acc_uname for row 0
docooph

Value of acc_uname for row 1
docooph2

Query info
SELECT acc_uname, acc_email FROM accounts has run successfully.

Query executed
SELECT acc_uname, acc_email FROM accounts

Keyword used by DBQuery object
SELECT

dummy user already in database

Assoc Array dump
array(3) { [0]=> array(2) { ["acc_uname"]=> string(7) "docooph" ["acc_email"]=> string(9) "hide@address.com" } [1]=> array(2) { ["acc_uname"]=> string(8) "docooph2" ["acc_email"]=> string(10) "hide@address.com" } [2]=> array(2) { ["acc_uname"]=> string(5) "dummy" ["acc_email"]=> string(14) "hide@address.com" } } 

Int indexed array dump
array(6) { [0]=> string(7) "docooph" [1]=> string(9) "hide@address.com" [2]=> string(8) "docooph2" [3]=> string(10) "hide@address.com" [4]=> string(5) "dummy" [5]=> string(14) "hide@address.com" } 

String representation of result array with field value pair
acc_uname docooph
acc_email hide@address.com

acc_uname docooph2
acc_email hide@address.com

acc_uname dummy
acc_email hide@address.com



String representation of result array with just values
docooph
hide@address.com

docooph2
hide@address.com

dummy
hide@address.com



Number of rows
3

Number of fields
2

Value of acc_uname for row 0
docooph

Value of acc_uname for row 2
dummy

Query info
SELECT acc_uname, acc_email FROM accounts has run successfully.

Query executed
SELECT acc_uname, acc_email FROM accounts

Keyword used by DBQuery object
SELECT

</pre>
<h1>How to give database connection to other classes</h1>
<p>MyOneLineSQL package can be used with other packages and/or single classes. All it's needed for a class to set/get connection to database is to implement the SQLable interface.</p>
<p>Example</p>
<pre>
class Dummy implements SQLable
{
    private $dbc;
	  public function __construct($adbc)
	  {
 	  $this->setDbc($adbc);
	  }
   /**
    * Sets connection to db
    * 
    * Sets this object connection to database
    * Implementation of SQLable interface
    *
    * @param dbconnect $adbc
    */
   public function setDbc($adbc)
   {
      $this->dbc = $adbc;
   }
   /**
    * Returns DB connection
    * 
    * Returns mySQL connection
    * Implementation of SQLable interface
    *
    * @return dbconnect
    */
   public function getDbc()
   {
      return $this->dbc;
   }
}
</pre>
<p>Before creating new Dummy objects, a call to the static method doDbConnection() and definition of DBC constant will allow the following:</p>
<pre>
DBConnect::doDBConnection();
$dummy = new Dummy(DBC);
</pre>
</body>
</html>
Return current item: My One Line SQL