Location: PHPKode > scripts > Simple ADO > simple-ado/SimpleADO-DOC.html
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<title>SimpleADO Documentation</title>
		<style type="text/css">
			<!--
			body {
				margin: 30px 5%;
				text-align: left;
				font: 75% Verdana, Arial;
			}

			h1 {
				margin: 0px 0px 70px 0px;
				text-align: center;
				color: #00c;
			}
			h2 {
				margin: 50px 0px 0px 0px;
				color: #c00;
			}
			h3 {
				margin: 50px 0px 10px 0px;
				color: #080;
			}
			h3 .parameters {
				font-size: 90%;
				color: #333;
			}
			h3 .type {
				color: #999;
				font-style: italic;
			}
			hr {
				margin: 5px 0px;
				width: 90%;
				text-align: left;
				color: #aaa;
			}

			.title {
				line-height: 40px;
				font-size: 120%;
				color: #000;
				font-weight: bold;
			}
			pre.code {
				margin: 0px 0px 40px 0px;
				width: 750px;
				padding: 10px;
				background-color: #e5e5e5;
				border: 1px dotted #000;
				font: 120% Courier New, Lucida Console;
			}
			pre.code .php_tags {
				font-weight: bold;
				color: #c00;
			}
			pre.code .function {
				color: #00c;
			}
			pre.code .structure {
				color: #060;
			}
			pre.code .string {
				color: #c00;
			}
			pre.code .numeric {
				color: #f00;
			}
			pre.code .comments {
				color: #f70;
			}

			a:link {
				color: #00c;
				text-decoration: none;
			}
			a:visited {
				color: #00c;
				text-decoration: none;
			}
			a:hover {
				color: #c70;
			}
			a:active {
				color: #c00;
			}

			strong.note {
				color: #00c;
				margin-left: 30px;
			}
			ol {
				margin-top: 5px;
			}
			-->
		</style>
	</head>
<body>
	<h1>SimpleADO Documentation</h1>


	<h2>Introduction</h2>
	<hr />
	<p>
	SimpleADO provides the same interface to access any type of ADO Interface. It also has friendly 
	methods that will help to create and execute &quot;SELECT&quot;, &quot;INSERT&quot;, 
	&quot;UPDATE&quot; and &quot;DELETE&quot; queries.
	</p>


	<h2>How to Use</h2>
	<hr />
	<p>First off we will have to ensure that the <strong>ado.xml</strong> config file is setup correctly.  This is pretty easy
	and leaves some pieces up to the class still.
	<ul>
		<li>DB Tag</li>
		<ul>
			<li><strong>Name</strong>:  This is a free form field and can be set to anything you would like to name it.</li>
			<li><strong>ReadOnly</strong>: If set to anything other than false you will only be able to run SELECT queries.</li>
		</ul>
		<li>Other Tags</li>
		<ul>
			<li><strong>Username</strong> &amp; <strong>Password</strong>: These are the variables ADO uses for username &amp; password (NOT YOUR USERNAME &amp; PASSWORD)
			<li><strong>Variable</strong>: This will be what ever is required within the ADO connection string. (eg. Server Name, Database...)</li>
	</ul>
	</p>

	<span class="title">1. The Config File (ado.xml):</span>

	<pre class="code">
	<span class="php_tags">&lt;?xml version=&quot;1.0&quot; encoding=&quot;ISO-8859-1&quot;?&gt;</span>
	<span class="function">&lt;ado&gt;</span>
	<span class="comments">&nbsp;&lt;!--These can be given any name as long as you use that name to connect to it with.--&gt;
	&nbsp;&lt;!--List of connection strings (http://www.carlprothman.net/Default.aspx?tabid=81) --&gt;</span>
	&nbsp;<span class="function">&lt;db name=&quot;MyConnection&quot; readonly=&quot;false&quot;&gt;
	&nbsp;&nbsp;&lt;username variable=&quot;Uid&quot; /&gt;
	&nbsp;&nbsp;&lt;password variable=&quot;Pwd&quot; /&gt;
	&nbsp;&nbsp;&lt;option variable=&quot;DSN&quot;&gt;DSN&lt;/option&gt;
	&nbsp;&lt;/db&gt;
	...
	</span>
	</pre>

	<span class="title">2. Creating the SimpleADO object:</span>

	<pre class="code">
	<span class="php_tags">&lt;?php</span>

	<span class="comments">// Imports SimpleADO class</span>
	<span class="function">require</span> (<span class="string">&quot;class.SimpleADO.php&quot;</span>);

	<span class="comments">// Creates and object called &quot;$SQL&quot;</span>
	$SQL = <span class="structure">new</span> <span class="function">SimpleADO</span>(<span class="string">"UserName"</span>, <span class="string">"Password"</span>, <span class="string">"MyConnection"</span>);


	<span class="php_tags">?&gt;</span>
	</pre>

	<p>
	Parameters are: user, password, connection name (The name you gave your database connection in the XML config file).
	</p>

	<span class="title">3. Using SELECT clause:</span>
	<pre class="code">
	<span class="php_tags">&lt;?php</span>

	$SQL = <span class="structure">new</span> <span class="function">SimpleADO</span>(<span class="string">"UserName"</span>, <span class="string">"Password"</span>, <span class="string">"MyConnection"</span>);

	$SQL-><span class="function">useTable</span>(<span class="string">&quot;clients&quot;</span>);


	<span class="comments">// You could avoid the 3 next steps writing the query:
	// $SQL->query(&quot;SELECT name, email FROM clients WHERE MONTH(birthday) = MONTH(now())&quot;)</span>
	$SQL-><span class="function">setSelection</span>(<span class="string">&quot;name, email&quot;</span>);
	$SQL-><span class="function">setWhere</span>(<span class="string">&quot;MONTH(birthday) = MONTH(now())&quot;</span>);
	$SQL-><span class="function">select</span>();


	<span class="comments">// Printing results</span>

	<span class="structure">foreach</span> ($SQL-><span class="function">recordSet</span>() <span class="structure">as</span> $var =&gt; $val) {
	&nbsp;<span class="function">echo</span> <span class="string">&quot;&lt;br /&gt;&quot;</span> . $val[<span class="string">'name'</span>] . <span class="string">&quot; - &quot;</span>  . $val[<span class="string">'email'</span>];
	}

	<span class="php_tags">?&gt;</span>
	</pre>




	<h2>Methods</h2>
	<hr />

	<p>
	 <h3><span class="type">void</span> SimpleADO <span class="parameters">( <span class="type">str</span> $user, <span class="type">str</span> $password, <span class="type">str</span> $connection_string )</span></h3>

	 Class constructor. Parameters are:
	 <ol>
	   <li>user: database username.</li>
	   <li>password: password for username.</li>
	   <li>connection_name: connection that will be used (XML Config File).</li>
	 </ol>

	</p>

	<p>
	 <h3><span class="type">array</span> recordSet <span class="parameters">( [<span class="type">resource</span> $result] )</span></h3>
	 Returns an array that corresponds to the ADO Recordset, or FALSE if there are no more rows.  If no parameters were defined, it 
	 will use the result of the last executed query.
	</p>

	<p>
	 <h3><span class="type">void</span> useDB <span class="parameters">( <span class="type">str</span> $db_name )</span></h3>
	 Changes the database name specified in the class constructor.
	</p>

	<p>

	 <h3><span class="type">str</span> error <span class="parameters">( )</span></h3>
	 Displays the last error.
	</p>



	<p style="margin-top: 70px; font-weight: bold; color: #c00;">
	 Methods below are intended to make easier the process of creating and executing queries. You will not necessarily use them.
	</p>



	<p>
	 <h3><span class="type">void</span> useTable <span class="parameters">( <span class="type">str</span> $table_name )</span></h3>
	 Defines what table should be used when creating and executing the SQL query.
	</p>

	<p>
	 <h3><span class="type">void</span> setFieldValue <span class="parameters">( <span class="type">str</span> $field, <span class="type">mixed</span> $value, <span class="type">bool</span> $is_sql_function )</span></h3>

	 Creates an internal list of field values that will be used on INSERT or UPDATE queries. Optional parameter sets if 
	 the parameter passed on $value should be interpreted as an SQL function, like NOW(), CONCAT(), etc.
	</p>

	<p>
	 <h3><span class="type">void</span> setWhere <span class="parameters">( <span class="type">str</span> $where_clause )</span></h3>
	 Defines the WHERE clause used on SELECT, UPDATE and DELETE queries. Use this method without writing &quot;WHERE&quot; in 
	 the beginning of the parameter. The right way is: setWhere(&quot;id > 10 AND name LIKE '%Reche%'&quot;);
	</p>

	<p>
	 <h3><span class="type">void</span> setSelection <span class="parameters">( <span class="type">str</span> $selection )</span></h3>
	 Defines the selected fields on SELECT clause. Default is &quot;*&quot;
	</p>

	<p>
	 <h3><span class="type">resource</span> select <span class="parameters">( )</span></h3>
	 Executes a SELECT query.
	</p>

	<p>
	 <h3><span class="type">resource</span> insert <span class="parameters">( )</span></h3>

	 Executes an INSERT query.
	</p>

	<p>
	 <h3><span class="type">resource</span> update <span class="parameters">( )</span></h3>
	 Executes an UPDATE query. If where clause is not defined, the query execution is aborted for security reasons.
	</p>

	<p>

	 <h3><span class="type">resource</span> delete <span class="parameters">( )</span></h3>
	 Executes a DELETE query. If where clause is not defined, the query execution is aborted for security reasons.
	</p>

	<h2>Credits</h2>
	<hr />

	<p>
	Zsolt Munoz <br />

	<em><a href="mailto:hide@address.com">zmunoz at gmail dot com</a></em>
	<hr />
	<p>
	Original Code Modified from	Carlos Reche's code from EasySQL <br />
	</p>
</body>

</html>
Return current item: Simple ADO