Location: PHPKode > scripts > PhARoS > pharos/Documentation.html
<html>
<head>
<meta http-equiv=Content-Type content="text/html; charset=windows-1252">
<title>PhARoS Documentation</title>
<style>
<!--
 @font-face {
font-family:"Cambria Math";
 panose-1:2 4 5 3 5 4 6 3 2 4;
}
@font-face {
font-family:Cambria;
 panose-1:2 4 5 3 5 4 6 3 2 4;
}
@font-face {
font-family:Calibri;
 panose-1:2 15 5 2 2 2 4 3 2 4;
}
p.MsoNormal, li.MsoNormal, div.MsoNormal {
	line-height:115%;
	font-size:11.0pt;
	font-family:"Calibri", "sans-serif";
}
h1 {
	mso-style-link:"Heading 1 Char";
	line-height:115%;
	page-break-after:avoid;
	font-size:14.0pt;
	font-family:"Cambria", "serif";
	color:#2A6C7D;
}
h2 {
	mso-style-link:"Heading 2 Char";
	line-height:115%;
	page-break-after:avoid;
	font-size:13.0pt;
	font-family:"Cambria", "serif";
	color:#3891A7;
}
p.MsoQuote, li.MsoQuote, div.MsoQuote {
	mso-style-link:"Quote Char";
	line-height:115%;
	font-size:11.0pt;
	font-family:"Calibri", "sans-serif";
	color:black;
	font-style:italic;
}
span.MsoSubtleEmphasis {
	color:gray;
	font-style:italic;
}
span.MsoIntenseEmphasis {
	color:#3891A7;
	font-weight:bold;
	font-style:italic;
}
span.MsoSubtleReference {
	font-variant:small-caps;
	color:#FEB80A;
	text-decoration:underline;
}
span.Heading1Char {
	mso-style-name:"Heading 1 Char";
	mso-style-link:"Heading 1";
	font-family:"Cambria", "serif";
	color:#2A6C7D;
	font-weight:bold;
}
span.QuoteChar {
	mso-style-name:"Quote Char";
	mso-style-link:Quote;
	color:black;
	font-style:italic;
}
span.Heading2Char {
	mso-style-name:"Heading 2 Char";
	mso-style-link:"Heading 2";
	font-family:"Cambria", "serif";
	color:#3891A7;
	font-weight:bold;
}
.MsoPapDefault {
	line-height:115%;
}
@page Section1 {
	size:8.5in 11.0in;
}
div.Section1 {
	page:Section1;
}
-->
</style>
</head>
<body bgcolor="#FFFFFF" lang=EN-US>
<div class=Section1>
  <h1>Introduction to PhARoS</h1>
  <table class=LightShading-Accent11 border=1 cellspacing=0 cellpadding=0
 style='border-collapse:collapse;border:none'>
    <tr>
      <td width=638 valign=top style='width:6.65in;border-top:solid #3891A7 1.0pt;
  border-left:none;border-bottom:solid #3891A7 1.0pt;border-right:none;
  padding:0in 5.4pt 0in 5.4pt'><p class=MsoNormal style='line-height:normal'>PhARoS Ain’t a Rocket Science and after reading
          this simple document you will say the same.</p>
        <p class=MsoNormal style='line-height:normal'>Really simple and minimal PhARoS provides a minimal
          set of user routines to let you generate your standard SQL queries using
          modified version of active record pattern. Also taking away all the boiler
          level strings from the programmer making code simpler.</p>
        <p class=MsoNormal style='line-height:normal'>Since PhARoS is not dependent upon any of the
          databases classes at all, you can yourself choose how to query database
          either by directly using the functions (like mysql_query) or choose any of
          the databases abstraction libraries (adodblite or adodb itself).</p>
        <p class=MsoNormal style='line-height:normal'>Also since it is based on principle of minimalism,
          unlike any of the active record classes (Propel or Doctrine) it is plug n
          play. So no tight integration or complex XML configurations. All you will be
          doing is feeling the complete power to generate the queries with decent
          readable code. Unlike some libraries it only requires PHP 4+ version and
          that’s it. Since there is not much bloated code still you will be able to use
          CRUD like methods to generate queries for you. They key routines are
          selectQuery, insertQuery, updateQuery, deleteQuery (see below and you will
          understand).</p>
        <p class=MsoNormal style='line-height:normal'>The document provides everything you need to get
          started and making your life easier with PhARoS. You can create a pharos
          object and start using it straight away .e.g.</p>
        <p class=MsoNormal style='line-height:
  normal'><b><span style='color:#2A6C7D'>require_once(‘PhARoS.php’);</span></b></p>
        <p class=MsoNormal style='line-height:
  normal'><b><span style='color:#2A6C7D'>$ar = new PhARoS();</span></b></p>
        <p class=MsoNormal style='line-height:
  normal'>You can use following set of routines in combination to generate
          queries. Each section will describe you example usage and a partial or full
          output query (partial ones indicate by …)</p></td>
    </tr>
  </table>
  <table class=MsoTableLightShadingAccent3 border=1 cellspacing=0 cellpadding=0
 style='border-collapse:collapse;border:none'>
    <tr>
      <td width=638 valign=top style='width:6.65in;border-top:solid #C32D2E 1.0pt;
  border-left:none;border-bottom:solid #C32D2E 1.0pt;border-right:none;
  padding:0in 5.4pt 0in 5.4pt'><h2 style='line-height:normal'><span class=MsoIntenseEmphasis><span
  style='font-weight:normal;font-style:normal'>Selecting columns</span></span></h2>
        <p class=MsoNormal align=center style='
  text-align:center;line-height:normal'><span class=MsoIntenseEmphasis><span
  style='font-weight:normal'>$ar-&gt;select(‘col1’,’col2’);</span></span></p>
        <p class=MsoNormal align=center style='
  text-align:center;line-height:normal'><span class=MsoIntenseEmphasis><span
  style='font-weight:normal'>Or</span></span></p>
        <p class=MsoNormal align=center style='
  text-align:center;line-height:normal'><span class=MsoIntenseEmphasis><span
  style='font-weight:normal'>$ar-&gt;select(array(‘col1’,’col2’));</span></span></p>
        <p class=MsoNormal align=center style='
  text-align:center;line-height:normal'><span class=MsoSubtleEmphasis><b>Generated
          output:</b></span></p>
        <p class=MsoNormal align=center style='
  text-align:center;line-height:normal'><span class=MsoSubtleEmphasis><b>SELECT
          col1,col2 …</b></span></p>
        <p class=MsoNormal style='line-height:
  normal'><span style='color:#912122'>As clear from above example usually a
          select can take any number of string arguments specifying table column names
          or an array containing those names. The first statement shows how I can specify
          col1 and col2 from a table as arguments however the second statement
          demonstrates the array usage.<br>
          You can pass any number of arguments (either string or array) to this
          function</span></p></td>
    </tr>
    <tr>
      <td width=638 valign=top style='width:6.65in;border:none;background:#F2C8C8;
  padding:0in 5.4pt 0in 5.4pt'><h2 style='line-height:normal'><span class=MsoIntenseEmphasis><span
  style='font-weight:normal;font-style:normal'>From Table</span></span></h2>
        <p class=MsoNormal align=center style='
  text-align:center;line-height:normal'><span class=MsoIntenseEmphasis><span
  style='font-weight:normal'>$ar-&gt;from(‘entries’);</span></span></p>
        <p class=MsoQuote align=center style='
  text-align:center;line-height:normal'><span class=MsoSubtleEmphasis><b><span
  style='font-style:normal'>Generated output:</span></b></span></p>
        <p class=MsoQuote align=center style='
  text-align:center;line-height:normal'><span class=MsoSubtleEmphasis><b><span
  style='font-style:normal'>… FROM entries …</span></b></span></p>
        <p class=MsoNormal style='line-height:
  normal'><span style='color:#912122'>Sets the target table (<b>entries in
          above example), </b>if it is called again from table name will be overwritten
          or changed.</span></p></td>
    </tr>
    <tr>
      <td width=638 valign=top style='width:6.65in;border:none;padding:0in 5.4pt 0in 5.4pt'><h2 style='line-height:normal'><span class=MsoIntenseEmphasis><span
  style='font-weight:normal;font-style:normal'>Where conditions</span></span></h2>
        <p class=MsoNormal style='line-height:
  normal'><span style='color:#912122'>There are as many flavors available as
          you can think of for the where clause, since it is always the most used.
          Let’s have a glimpse at them. You can either pass a single string specifying
          complete condition. Like this:</span></p>
        <p class=MsoNormal align=center style='

  text-align:center;line-height:normal'><span class=MsoIntenseEmphasis><span
  style='font-weight:normal'>$ar-&gt;where(“name = ‘zohaib’ AND age &gt; 20”);</span></span></p>
        <p class=MsoNormal align=center style='
  text-align:center;line-height:normal'><span class=MsoSubtleEmphasis><b>Generated
          output:</b></span></p>
        <p class=MsoNormal align=center style='
  text-align:center;line-height:normal'><span class=MsoSubtleEmphasis><b>…
          WHERE name=’zohaib’ AND age&gt;20 …</b></span></p>
        <p class=MsoNormal style='line-height:
  normal'><span style='color:#912122'>In above method user has complete control
          over string and will be used as it is (.i.e. no quotes are added to query;
          hence user is responsible for handling SQL injection)</span></p>
        <p class=MsoNormal style='line-height:
  normal'><span style='color:#912122'>The second way is to specify the column
          and value pair, this method will automatically <b>add slashes</b> to the
          value objects as well hence recommended:</span></p>
        <p class=MsoNormal align=center style='
  text-align:center;line-height:normal'><span class=MsoIntenseEmphasis><span
  style='font-weight:normal'>$ar-&gt;where(‘name’, $_POST[‘name’]);</span></span></p>
        <p class=MsoNormal align=center style='
  text-align:center;line-height:normal'><span class=MsoIntenseEmphasis><span
  style='font-weight:normal'>$ar-&gt;where(‘age &gt;’,20);</span></span></p>
        <p class=MsoNormal align=center style='
  text-align:center;line-height:normal'><span class=MsoSubtleEmphasis><b>Generated
          output:</b></span></p>
        <p class=MsoNormal align=center style='
  text-align:center;line-height:normal'><span class=MsoSubtleEmphasis><b>…
          WHERE name=’zohaib’ AND age&gt;’20’ …</b></span></p>
        <p class=MsoNormal style='line-height:
  normal'><span style='color:#912122'>When you call it <b>where</b> twice it
          automatically concatenated the next condition with AND operator. You may
          change this operator by specifying it to the PhARoS like this:</span></p>
        <p class=MsoNormal align=center style='
  text-align:center;line-height:normal'><span class=MsoIntenseEmphasis><span
  style='font-weight:normal'>$ar-&gt;where(‘name’, $_POST[‘name’]);</span></span></p>
        <p class=MsoNormal align=center style='
  text-align:center;line-height:normal'><span class=MsoIntenseEmphasis><span
  style='font-weight:normal'>$ar-&gt;where(‘age &gt;’,20,’OR’);</span></span></p>
        <p class=MsoNormal align=center style='
  text-align:center;line-height:normal'><span class=MsoIntenseEmphasis><span
  style='font-weight:normal'>$ar-&gt;where(‘pay’,40,’AND’);</span></span></p>
        <p class=MsoNormal align=center style='
  text-align:center;line-height:normal'><span class=MsoSubtleEmphasis><b>Generated
          output:</b></span></p>
        <p class=MsoNormal align=center style='
  text-align:center;line-height:normal'><span class=MsoSubtleEmphasis><b>…
          WHERE name=’zohaib’ OR age&gt;’20’ AND pay=’40’…</b></span></p>
        <p class=MsoNormal style='line-height:
  normal'><span style='color:#912122'>Simple yet powerful! PhARoS can detect
          the passed value type and generate the specific operator accordingly, for
          example if you pass an array as value object it will automatically generate
          the IN operator .i.e.</span></p>
        <p class=MsoNormal align=center style='
  text-align:center;line-height:normal'><span class=MsoIntenseEmphasis><span
  style='font-weight:normal'>$ar-&gt;where(‘id’, array(50,32,71));</span></span></p>
        <p class=MsoNormal align=center style='
  text-align:center;line-height:normal'><span class=MsoIntenseEmphasis><span
  style='font-weight:normal'>$ar-&gt;where(‘age &gt;’,20,’OR’);</span></span></p>
        <p class=MsoNormal align=center style='
  text-align:center;line-height:normal'><span class=MsoSubtleEmphasis><b>Generated
          output:</b></span></p>
        <p class=MsoNormal align=center style='
  text-align:center;line-height:normal'><span class=MsoSubtleEmphasis><b>…
          WHERE id IN (’50’,’32’,’71’) OR age&gt;’20’ …</b></span></p>
        <p class=MsoNormal style='line-height:
  normal'><span style='color:#912122'>You can also specify the array operator
          your self and PhARoS will detect it .i.e.</span></p>
        <p class=MsoNormal align=center style='
  text-align:center;line-height:normal'><span class=MsoIntenseEmphasis><span
  style='font-weight:normal'>$ar-&gt;where(‘id NOT IN’, array(50,32,71));</span></span></p>
        <p class=MsoNormal align=center style='
  text-align:center;line-height:normal'><span class=MsoIntenseEmphasis><span
  style='font-weight:normal'>$ar-&gt;where(‘age &gt;’,20,’OR’);</span></span></p>
        <p class=MsoNormal align=center style='
  text-align:center;line-height:normal'><span class=MsoSubtleEmphasis><b>Generated
          output:</b></span></p>
        <p class=MsoNormal align=center style='
  text-align:center;line-height:normal'><span class=MsoSubtleEmphasis><b>…
          WHERE id NOT IN (’50’,’32’,’71’) OR age&gt;’20’ …</b></span></p>
        <p class=MsoNormal style='line-height:
  normal'><span style='color:#912122'>Good enough! PhARoS is also intelligent
          for NULLs</span></p>
        <p class=MsoNormal align=center style='
  text-align:center;line-height:normal'><span class=MsoIntenseEmphasis><span
  style='font-weight:normal'>$ar-&gt;where(‘fid’, NULL);</span></span></p>
        <p class=MsoNormal align=center style='
  text-align:center;line-height:normal'><span class=MsoIntenseEmphasis><span
  style='font-weight:normal'>$ar-&gt;where(‘age &gt;’,20);</span></span></p>
        <p class=MsoNormal align=center style='
  text-align:center;line-height:normal'><span class=MsoSubtleEmphasis><b>Generated
          output:</b></span></p>
        <p class=MsoNormal align=center style='
  text-align:center;line-height:normal'><span class=MsoSubtleEmphasis><b>…
          WHERE fid IS NULL AND age&gt;’20’ …</b></span></p>
        <p class=MsoNormal style='line-height:
  normal'><span style='color:#912122'>And same operator detection holds here (for
          NULL) as well like before</span></p>
        <p class=MsoNormal align=center style='
  text-align:center;line-height:normal'><span class=MsoIntenseEmphasis><span
  style='font-weight:normal'>$ar-&gt;where(‘fid IS NOT’, NULL);</span></span></p>
        <p class=MsoNormal align=center style='
  text-align:center;line-height:normal'><span class=MsoIntenseEmphasis><span
  style='font-weight:normal'>$ar-&gt;where(‘age &gt;’,20);</span></span></p>
        <p class=MsoNormal align=center style='
  text-align:center;line-height:normal'><span class=MsoSubtleEmphasis><b>Generated
          output:</b></span></p>
        <p class=MsoNormal align=center style='
  text-align:center;line-height:normal'><span class=MsoSubtleEmphasis><b>…
          WHERE fid IS NULL AND age&gt;’20’ …</b></span></p>
        <p class=MsoNormal style='line-height:
  normal'><span style='color:#912122'>Who can forget the good old LIKE
          operator:</span></p>
        <p class=MsoNormal align=center style='
  text-align:center;line-height:normal'><span class=MsoIntenseEmphasis><span
  style='font-weight:normal'>$ar-&gt;where(‘name LIKE’, ‘%ohaib’);</span></span></p>
        <p class=MsoNormal align=center style='
  text-align:center;line-height:normal'><span class=MsoIntenseEmphasis><span
  style='font-weight:normal'>$ar-&gt;where(‘age &gt;’,20);</span></span></p>
        <p class=MsoNormal align=center style='
  text-align:center;line-height:normal'><span class=MsoSubtleEmphasis><b>Generated
          output:</b></span></p>
        <p class=MsoNormal align=center style='
  text-align:center;line-height:normal'><span class=MsoSubtleEmphasis><b>…
          WHERE name LIKE ‘%ohaib’ AND age&gt;’20’ …</b></span></p>
        <p class=MsoNormal style='line-height:
  normal'><span style='color:#912122'>Now time for most elegant feature of the
          PhARoS, you can do the same as above using associative arrays, this can be
          very useful when using it on GET or POST variables,</span></p>
        <p class=MsoNormal align=center style='
  text-align:center;line-height:normal'><span class=MsoIntenseEmphasis><span
  style='font-weight:normal'>$ar-&gt;where(<br>
          array(‘id’=&gt; array(1,2,3,4,5),‘age &gt;’ =&gt; 20,‘fid’=&gt;NULL,‘name
          LIKE’=&gt;’%ohaib’)<br>
          );</span></span></p>
        <p class=MsoNormal align=center style='
  text-align:center;line-height:normal'><span class=MsoSubtleEmphasis><b>Generated
          output:</b></span></p>
        <p class=MsoNormal align=center style='
  text-align:center;line-height:normal'><span class=MsoSubtleEmphasis><b>…
          WHERE id IN(‘1’,’2’,’3’,’4’,’5’) AND age &gt; ‘20’ AND fid IS NULL AND
          age&gt;’20’  AND name LIKE ‘%ohaib’…</b></span></p>
        <p class=MsoNormal style='line-height:
  normal'><span style='color:#912122'>Want to change the concatenation
          operator? Simply ask PhARoS!!!</span></p>
        <p class=MsoNormal align=center style='
  text-align:center;line-height:normal'><span class=MsoIntenseEmphasis><span
  style='font-weight:normal'>$ar-&gt;where(array(</span></span></p>
        <p class=MsoNormal align=center style='
  text-align:center;line-height:normal'><span class=MsoIntenseEmphasis><span
  style='font-weight:normal'>‘id’=&gt; array(1,2,3,4,5),</span></span></p>
        <p class=MsoNormal align=center style='
  text-align:center;line-height:normal'><span class=MsoIntenseEmphasis><span
  style='font-weight:normal'>‘age &gt;’ =&gt; 20,</span></span></p>
        <p class=MsoNormal align=center style='
  text-align:center;line-height:normal'><span class=MsoIntenseEmphasis><span
  style='font-weight:normal'>‘fid’=&gt;NULL,</span></span></p>
        <p class=MsoNormal align=center style='
  text-align:center;line-height:normal'><span class=MsoIntenseEmphasis><span
  style='font-weight:normal'>‘name LIKE’=&gt;’%ohaib’),</span></span></p>
        <p class=MsoNormal align=center style='
  text-align:center;line-height:normal'><span class=MsoIntenseEmphasis>‘OR’</span><span
  class=MsoIntenseEmphasis><span style='font-weight:normal'>);</span></span></p>
        <p class=MsoNormal align=center style='
  text-align:center;line-height:normal'><span class=MsoSubtleEmphasis><b>Generated
          output:</b></span></p>
        <p class=MsoNormal align=center style='
  text-align:center;line-height:normal'><span class=MsoSubtleEmphasis><b>…
          WHERE id IN(‘1’,’2’,’3’,’4’,’5’) OR age &gt; ‘20’ OR fid IS NULL OR
          age&gt;’20’  OR name LIKE ‘%ohaib’…</b></span></p>
        <p class=MsoNormal style='line-height:
  normal'><span style='color:#912122'>Well you have some “<b>complex</b>” kind
          of conditional structure but still want PhARoS to do the work for you? Well I
          got inspired by the <b>PDO style query preparation system</b> and also
          provided that .e.g.</span></p>
        <p class=MsoNormal align=center style='
  text-align:center;line-height:normal'><span class=MsoIntenseEmphasis><span
  style='font-weight:normal'>$ar-&gt;where(‘(id IN :ids AND  fid =:fid) OR
          age&gt;=:age’,</span></span></p>
        <p class=MsoNormal align=center style='
  text-align:center;line-height:normal'><span class=MsoIntenseEmphasis><span
  style='font-weight:normal'>array(</span></span></p>
        <p class=MsoNormal align=center style='
  text-align:center;line-height:normal'><span class=MsoIntenseEmphasis><span
  style='font-weight:normal'>‘id’=&gt;array(1,2,3),</span></span></p>
        <p class=MsoNormal align=center style='
  text-align:center;line-height:normal'><span class=MsoIntenseEmphasis><span
  style='font-weight:normal'>‘fid’=&gt;32,</span></span></p>
        <p class=MsoNormal align=center style='
  text-align:center;line-height:normal'><span class=MsoIntenseEmphasis><span
  style='font-weight:normal'>‘age’=&gt;20</span></span></p>
        <p class=MsoNormal align=center style='
  text-align:center;line-height:normal'><span class=MsoIntenseEmphasis><span
  style='font-weight:normal'>));</span></span></p>
        <p class=MsoNormal align=center style='
  text-align:center;line-height:normal'><span class=MsoSubtleEmphasis><b>Generated
          output:</b></span></p>
        <p class=MsoNormal align=center style='
  text-align:center;line-height:normal'><span class=MsoSubtleEmphasis><b>…
          WHERE (id IN (‘1’,’2’,’3’) AND fid=’32’) OR age&gt;=’20’…</b></span></p>
        <p class=MsoNormal style='line-height:
  normal'><span style='color:#912122'>I think its enough to generate almost above
          average queries.</span></p></td>
    </tr>
    <tr>
      <td width=638 valign=top style='width:6.65in;border:none;background:#F2C8C8;
  padding:0in 5.4pt 0in 5.4pt'><h2 style='line-height:normal'><span class=MsoIntenseEmphasis><span
  style='font-weight:normal'>Joining Tables</span></span></h2>
        <p class=MsoNormal style='line-height:
  normal'><span style='color:#912122'>Joining table is also simple, here is the
          basic syntax:</span></p>
        <p class=MsoNormal align=center style='
  text-align:center;line-height:normal'><span class=MsoIntenseEmphasis><span
  style='font-weight:normal'>$ar-&gt;join(tableName ,joinCondition, type);</span></span></p>
        <p class=MsoNormal style='line-height:
  normal'><span style='color:#912122'>Simply replace the table name, join
          condition, and type with your requirements .e.g.</span></p>
        <p class=MsoNormal align=center style='
  text-align:center;line-height:normal'><span class=MsoIntenseEmphasis><span
  style='font-weight:normal'>$ar-&gt;from(‘posts’);</span></span></p>
        <p class=MsoNormal align=center style='
  text-align:center;line-height:normal'><span class=MsoIntenseEmphasis><span
  style='font-weight:normal'>$ar-&gt;join(‘comments’ ,’posts.id=comments.pid’,
          ‘LEFT’);</span></span></p>
        <p class=MsoNormal align=center style='
  text-align:center;line-height:normal'><span class=MsoSubtleEmphasis><b>Generated
          output:</b></span></p>
        <p class=MsoNormal align=center style='
  text-align:center;line-height:normal'><span class=MsoSubtleEmphasis><b>… FROM
          posts LEFT JOIN comments ON (posts.id = comments.id)…</b></span></p>
        <p class=MsoNormal align=center style='
  text-align:center;line-height:normal'><span class=MsoIntenseEmphasis><span
  style='font-weight:normal'>$ar-&gt;from(‘posts’);</span></span></p>
        <p class=MsoNormal align=center style='
  text-align:center;line-height:normal'><span class=MsoIntenseEmphasis><span
  style='font-weight:normal'>$ar-&gt;join(‘comments’ ,’posts.id=comments.pid’,
          ‘RIGHT’);</span></span></p>
        <p class=MsoNormal align=center style='
  text-align:center;line-height:normal'><span class=MsoSubtleEmphasis><b>Generated
          output:</b></span></p>
        <p class=MsoNormal align=center style='
  text-align:center;line-height:normal'><span class=MsoSubtleEmphasis><b>… FROM
          posts RIGHT JOIN comments ON (posts.id = comments.id)…</b></span></p></td>
    </tr>
    <tr>
      <td width=638 valign=top style='width:6.65in;border:none;padding:0in 5.4pt 0in 5.4pt'><h2 style='line-height:normal'><span class=MsoIntenseEmphasis><span
  style='font-weight:normal;font-style:normal'>Order By</span></span></h2>
        <p class=MsoNormal style='line-height:
  normal'><span style='color:#912122'>Ordering can be done in two ways, one is like
          the where function call <b>where()</b> passing column name and order
          type(DESC by default) passing pair .i.e.</span></p>
        <p class=MsoNormal align=center style='
  text-align:center;line-height:normal'><span class=MsoIntenseEmphasis><span
  style='font-weight:normal'>$ar-&gt;orderBy(‘name’);</span></span></p>
        <p class=MsoNormal align=center style='
  text-align:center;line-height:normal'><span class=MsoIntenseEmphasis><span
  style='font-weight:normal'>$ar-&gt;orderBy(‘age’,’ASC’);</span></span></p>
        <p class=MsoNormal align=center style='
  text-align:center;line-height:normal'><span class=MsoIntenseEmphasis><span
  style='font-weight:normal'>$ar-&gt;orderBy(‘id’,’DESC’);</span></span></p>
        <p class=MsoNormal align=center style='
  text-align:center;line-height:normal'><span class=MsoSubtleEmphasis><b>Generated
          output:</b></span></p>
        <p class=MsoNormal align=center style='
  text-align:center;line-height:normal'><span class=MsoSubtleEmphasis><b>…
          ORDER BY name DESC, age ASC, id DESC…</b></span></p>
        <p class=MsoNormal style='line-height:
  normal'><span style='color:#912122'>Other method can be to pass associative
          array with each key as name and value as order type .i.e. the above output
          can be achieved by single call as well </span></p>
        <p class=MsoNormal align=center style='
  text-align:center;line-height:normal'><span class=MsoIntenseEmphasis><span
  style='font-weight:normal'>$ar-&gt;orderBy(</span></span></p>
        <p class=MsoNormal align=center style='
  text-align:center;line-height:normal'><span class=MsoIntenseEmphasis><span
  style='font-weight:normal'>array(</span></span></p>
        <p class=MsoNormal align=center style='
  text-align:center;line-height:normal'><span class=MsoIntenseEmphasis><span
  style='font-weight:normal'>‘name’=&gt;’DESC’,</span></span></p>
        <p class=MsoNormal align=center style='
  text-align:center;line-height:normal'><span class=MsoIntenseEmphasis><span
  style='font-weight:normal'>‘age’=&gt;’ASC’,</span></span></p>
        <p class=MsoNormal align=center style='
  text-align:center;line-height:normal'><span class=MsoIntenseEmphasis><span
  style='font-weight:normal'>‘id’=&gt;’DESC’</span></span></p>
        <p class=MsoNormal align=center style='
  text-align:center;line-height:normal'><span class=MsoIntenseEmphasis><span
  style='font-weight:normal'>));</span></span></p></td>
    </tr>
    <tr>
      <td width=638 valign=top style='width:6.65in;border:none;background:#F2C8C8;
  padding:0in 5.4pt 0in 5.4pt'><h2 style='line-height:normal'><span class=MsoIntenseEmphasis><span
  style='font-weight:normal;font-style:normal'>Group By</span></span></h2>
        <p class=MsoNormal style='line-height:
  normal'><span style='color:#912122'>Parameters are same as that of calling
          methodology of <b>select()</b></span></p>
        <p class=MsoNormal align=center style='
  text-align:center;line-height:normal'><span class=MsoIntenseEmphasis><span
  style='font-weight:normal'>$ar-&gt;groupBy(‘col1’,’col2’);</span></span></p>
        <p class=MsoNormal align=center style='
  text-align:center;line-height:normal'><span class=MsoIntenseEmphasis><span
  style='font-weight:normal'>Or</span></span></p>
        <p class=MsoNormal align=center style='
  text-align:center;line-height:normal'><span class=MsoIntenseEmphasis><span
  style='font-weight:normal'>$ar-&gt; groupBy (array(‘col1’,’col2’));</span></span></p>
        <p class=MsoNormal align=center style='
  text-align:center;line-height:normal'><span class=MsoSubtleEmphasis><b>Generated
          output:</b></span></p>
        <p class=MsoNormal align=center style='
  text-align:center;line-height:normal'><span class=MsoSubtleEmphasis><b>…
          GROUP BY col1,col2 …</b></span></p></td>
    </tr>
    <tr>
      <td width=638 valign=top style='width:6.65in;border:none;padding:0in 5.4pt 0in 5.4pt'><h2 style='line-height:normal'><span class=MsoIntenseEmphasis><span
  style='font-weight:normal;font-style:normal'>Group conditions (Having)</span></span></h2>
        <p class=MsoNormal style='line-height:
  normal'><span style='color:#912122'>You have the same powers as that of the <b>where()</b> system (see the where conditions section) except the last PDO parsing part,
          but don’t worry there is an cut down version as “<b>?”</b> operator .i.e.</span></p>
        <p class=MsoNormal align=center style='
  text-align:center;line-height:normal'><span class=MsoIntenseEmphasis><span
  style='font-weight:normal'>$ar-&gt;having(array(‘cnt_totl’=&gt;1,’p
          &lt;’=&gt;30),’OR’);</span></span></p>
        <p class=MsoNormal align=center style='
  text-align:center;line-height:normal'><span class=MsoIntenseEmphasis><span
  style='font-weight:normal'>$ar-&gt;having(‘avg_age &gt;’,20);</span></span></p>
        <p class=MsoNormal align=center style='
  text-align:center;line-height:normal'><span class=MsoIntenseEmphasis><span
  style='font-weight:normal'>$ar-&gt;having(‘cpl IN (?)’,array(10,3,20));</span></span></p>
        <p class=MsoNormal align=center style='
  text-align:center;line-height:normal'><span class=MsoIntenseEmphasis><span
  style='font-weight:normal'>$ar-&gt;having(‘pp &lt; ?’,20,’OR’);</span></span></p>
        <p class=MsoNormal align=center style='
  text-align:center;line-height:normal'><span class=MsoSubtleEmphasis><b>Generated
          output:</b></span></p>
        <p class=MsoNormal align=center style='
  text-align:center;line-height:normal'><span class=MsoSubtleEmphasis><b>…
          HAVING cnt_totl=’1’ OR p&lt;’30’ AND avg_age &gt; ‘20’ AND cpl IN
          (‘10’,’3’,’20’) AND pp &lt; ‘20’…</b></span></p>
        <h2 style='line-height:normal'><span class=MsoIntenseEmphasis><span
  style='font-weight:normal;font-style:normal'>&nbsp;</span></span></h2></td>
    </tr>
    <tr>
      <td width=638 valign=top style='width:6.65in;border:none;border-bottom:solid #C32D2E 1.0pt;
  background:#F2C8C8;padding:0in 5.4pt 0in 5.4pt'><h2 style='line-height:normal'><span class=MsoIntenseEmphasis><span
  style='font-weight:normal;font-style:normal'>Generating Select Query</span></span></h2>
        <p class=MsoNormal style='line-height:
  normal'><span style='color:#912122'>After you are done with applying
          everything we are ready to generate query, do it by few key strokes like
          this:</span></p>
        <p class=MsoNormal align=center style='
  text-align:center;line-height:normal'><span class=MsoIntenseEmphasis><span
  style='font-weight:normal'>$ar-&gt;where(‘id’,arrary(1,2,3))</span></span></p>
        <p class=MsoNormal align=center style='
  text-align:center;line-height:normal'><span class=MsoIntenseEmphasis><span
  style='font-weight:normal'>$ar-&gt;from(‘comments’);</span></span></p>
        <p class=MsoNormal align=center style='
  text-align:center;line-height:normal'><span class=MsoIntenseEmphasis><span
  style='font-weight:normal'>$qry = $ar-&gt;selectQuery();</span></span></p>
        <p class=MsoNormal align=center style='
  text-align:center;line-height:normal'><span class=MsoSubtleEmphasis><b>Generated
          output:</b></span></p>
        <p class=MsoNormal align=center style='
  text-align:center;line-height:normal'><span class=MsoSubtleEmphasis><b>SELECT
          * FROM comments WHERE id IN(‘1’,’2’,’3’)</b></span></p>
        <p class=MsoNormal style='line-height:
  normal'><span style='color:#912122'>Same query can be also generated like
          this</span></p>
        <p class=MsoNormal align=center style='
  text-align:center;line-height:normal'><span class=MsoIntenseEmphasis><span
  style='font-weight:normal'>$ar-&gt;where(‘id’,arrary(1,2,3))</span></span></p>
        <p class=MsoNormal align=center style='
  text-align:center;line-height:normal'><span class=MsoIntenseEmphasis><span
  style='font-weight:normal'>$qry = $ar-&gt;selectQuery(‘comments’);</span></span></p></td>
    </tr>
  </table>
  <table class=MsoTableLightShadingAccent6 border=1 cellspacing=0 cellpadding=0
 style='border-collapse:collapse;border:none'>
    <tr>
      <td width=638 valign=top style='width:6.65in;border-top:solid #475A8D 1.0pt;
  border-left:none;border-bottom:solid #475A8D 1.0pt;border-right:none;
  padding:0in 5.4pt 0in 5.4pt'><h2 style='line-height:normal'><span style='font-weight:normal'>Generating
          Insert, Delete, or Update Queries</span></h2>
        <p class=MsoNormal style='line-height:
  normal'><b><span style='color:#354369'>For generating an insert or an update
          query you must set the data first, you can set the data by the set() call
          .e.g.</span></b></p>
        <p class=MsoNormal align=center style='
  text-align:center;line-height:normal'><span class=MsoIntenseEmphasis><span
  style='font-weight:normal'>$ar-&gt;set(‘title’,’My Comments’);</span></span></p>
        <p class=MsoNormal align=center style='
  text-align:center;line-height:normal'><span class=MsoIntenseEmphasis><span
  style='font-weight:normal'>$ar-&gt;set(array(</span></span></p>
        <p class=MsoNormal align=center style='
  text-align:center;line-height:normal'><span class=MsoIntenseEmphasis><span
  style='font-weight:normal'>‘commentText’ =&gt; $comment,</span></span></p>
        <p class=MsoNormal align=center style='
  text-align:center;line-height:normal'><span class=MsoIntenseEmphasis><span
  style='font-weight:normal'>‘date’=&gt; date()</span></span></p>
        <p class=MsoNormal align=center style='
  text-align:center;line-height:normal'><span class=MsoIntenseEmphasis><span
  style='font-weight:normal'>)); //Works both ways</span></span></p>
        <p class=MsoNormal align=center style='
  text-align:center;line-height:normal'><span class=MsoIntenseEmphasis><span
  style='font-weight:normal'>$ar-&gt;insertQuery(‘comments’);</span></span></p>
        <p class=MsoNormal align=center style='
  text-align:center;line-height:normal'><span class=MsoSubtleEmphasis><b>Generated
          output:</b></span></p>
        <p class=MsoNormal align=center style='
  text-align:center;line-height:normal'><span class=MsoSubtleEmphasis><b>INSERT
          INTO comments(title,commentText,date) Values(‘My Comments’, ’here is my
          comment’,’2131232133’);</b></span></p>
        <p class=MsoNormal style='line-height:
  normal'><b><span style='color:#354369'>Simple same goes for the update query
          generation</span></b></p>
        <p class=MsoNormal align=center style='
  text-align:center;line-height:normal'><span class=MsoIntenseEmphasis><span
  style='font-weight:normal'>$ar-&gt;set(‘title’,’My Comments’);</span></span></p>
        <p class=MsoNormal align=center style='
  text-align:center;line-height:normal'><span class=MsoIntenseEmphasis><span
  style='font-weight:normal'>$ar-&gt;set(array(‘commentText’ =&gt; $comment));</span></span></p>
        <p class=MsoNormal align=center style='
  text-align:center;line-height:normal'><span class=MsoIntenseEmphasis><span
  style='font-weight:normal'>$ar-&gt;where(‘id’,1)</span></span></p>
        <p class=MsoNormal align=center style='
  text-align:center;line-height:normal'><span class=MsoIntenseEmphasis><span
  style='font-weight:normal'>$ar-&gt;updateQuery(‘comments’);</span></span></p>
        <p class=MsoNormal align=center style='
  text-align:center;line-height:normal'><span class=MsoSubtleEmphasis><b>Generated
          output:</b></span></p>
        <p class=MsoNormal align=center style='
  text-align:center;line-height:normal'><span class=MsoSubtleEmphasis><b>UPDATE
          comments SET title = ‘My Comments’, commentText=’blah blah blah’ WHERE
          id=’1’;</b></span></p>
        <p class=MsoNormal style='line-height:
  normal'><b><span style='color:#354369'>Deletion, I guess you would have
          guessed it up-till now:</span></b></p>
        <p class=MsoNormal align=center style='
  text-align:center;line-height:normal'><span class=MsoIntenseEmphasis><span
  style='font-weight:normal'>$ar-&gt;where(‘id’,1)</span></span></p>
        <p class=MsoNormal align=center style='
  text-align:center;line-height:normal'><span class=MsoIntenseEmphasis><span
  style='font-weight:normal'>$ar-&gt;deleteQuery(‘comments’);</span></span></p>
        <p class=MsoNormal align=center style='
  text-align:center;line-height:normal'><span class=MsoSubtleEmphasis><b>Generated
          output:</b></span></p>
        <p class=MsoNormal align=center style='
  text-align:center;line-height:normal'><span class=MsoSubtleEmphasis><b>DELETE
          FROM comments WHERE id = ‘1’;</b></span></p></td>
    </tr>
  </table>
  <table class=MsoTableLightShadingAccent2 border=1 cellspacing=0 cellpadding=0
 style='border-collapse:collapse;border:none'>
    <tr>
      <td width=638 valign=top style='width:6.65in;border-top:solid #FEB80A 1.0pt;
  border-left:none;border-bottom:solid #FEB80A 1.0pt;border-right:none;
  padding:0in 5.4pt 0in 5.4pt'><h2 style='line-height:normal'>PHP 5 Users</h2></td>
    </tr>
    <tr>
      <td width=638 valign=top style='width:6.65in;border:none;border-bottom:solid #FEB80A 1.0pt;
  background:#FEEDC2;padding:0in 5.4pt 0in 5.4pt'><p class=MsoNormal style='line-height:
  normal'><b><span style='color:#C48B01'>PHP 5 users can chain methods for
          example</span></b></p>
        <p class=MsoNormal align=center style='
  text-align:center;line-height:normal'><span class=MsoIntenseEmphasis><span
  style='font-weight:normal'>$qry = $ar-&gt;where(‘id’,1)-&gt;deleteQuery(‘comments’);</span></span></p>
        <p class=MsoNormal align=center style='
  text-align:center;line-height:normal'><span class=MsoIntenseEmphasis><span
  style='font-weight:normal'>or</span></span></p>
        <p class=MsoNormal align=center style='
  text-align:center;line-height:normal'><span class=MsoIntenseEmphasis><span
  style='font-weight:normal'>$ar-&gt;where(‘id’,arrary(1,2,3))-&gt;from(‘comments’)-&gt;selectQuery();</span></span></p>
        <p class=MsoNormal style='line-height:
  normal'><b><span style='color:#C48B01'>Making code more sleek ;)</span></b></p></td>
    </tr>
  </table>
</div>
</body>
</html>
Return current item: PhARoS