Location: PHPKode > scripts > xMySQL > xmysql/readme.html
<!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
	<title>xMySQL 2.1 Demo</title>
	<style type="text/css">
	<!--
	body { font:11px verdana,arial,helvetica,sans-serif; color:#333; background-color: #ddd; padding-right:0px; padding-left:0px; padding-bottom:0px; margin:50px 0px; padding-top:0px; text-align:center; }
	h1 { font:900 italic 1.8em/1 verdana,arial,helvetica,sans-serif; color:#394198; }
	h2 { margin:2em 0px 0.25em; font:700 1.1em/1 verdana,arial,helvetica,sans-serif; color:#384198; }
	h3 { font-weight:800; font-size:1em; margin:3em 0px 0.35em; color: #394198; }
	p { margin:0px 0px 1em; line-height: 1.8; }
	td { font:11px verdana,arial,helvetica,sans-serif; color:#333; }
	UNKNOWN { margin-top:-1em; text-indent:2.7em; }
	ol { margin-top:0px; margin-bottom:1em; line-height:1.8; }
	ul { margin-top:0px; margin-bottom:1em; line-height:1.8; }
	UNKNOWN { margin-top:0em; }
	a { font-weight:600; color:#09c; text-decoration:none; }
	a:link { color:#394198; }
	a:visited { color:#515abb; }
	a:hover { background-color:#f0f0f0; }
	UNKNOWN { margin-top:0px; text-indent:0px; }
	.keyPoint { border-right:#666 1px dashed; padding-right:0px; border-top:#666 1px dashed; padding-left:0px; padding-bottom:0px; margin:0px 0px 1.5em; border-left:#666 1px dashed; padding-top:0px; border-bottom:#666 1px dashed; background-color:#fff; }
	.keyPoint P { margin:0.5em 1em; font: 1.63em/1.8 Georgia,"Times New Roman",Times,serif; }
	UNKNOWN { margin-top: -0.5em; }
	.markup { border-right:#999 1px dashed; padding-right:0.3em; border-top:#999 1px dashed; padding-left:0.3em; padding-bottom: 0.3em; font:1.1em/1.2 'courier new',monospace; border-left:#999 1px dashed; text-indent:0px; padding-top:0.3em; border-bottom:#999 1px dashed; }
	.comment { background-color:#f0f0f0; color:#808080; }
	#Content { border:4px ridge #ccc; padding-right:15px; padding-left:15px; padding-bottom:15px; margin:0px auto; width:700px; padding-top:15px; background-color:#ccc; text-align:left; }
	.small { font-size:0.8em; }
	.red { color:#b22222; }
	-->
	</style>
</head>

<body>

<a name="top"></a>

<div id="content">
	<h1><img src="http://www.serbe.de/images/sig4.gif" align="right" border="0" /><span class="red">x</span>MySQL 2.1</h1>
	<p class="small">Copyright &copy; 2002, 2003 by Alexander Serbe. All rights reserved.</p>
	<p>&nbsp;</p>
	<hr size="1" color="#000000" noshade />
	<p align="center" class="small"><a href="#vh">Version History</a> | <a href="#var">Variables</a> | <a href="#mlist">Methods (overview)</a> | <a href="#ref">Function Reference</a> | <a href="#ex">Example</a> | <a href="#lic">License Agreement</a></p>
	<hr size="1" color="#000000" noshade />
	<p><b>Version:</b> 2.1<br />
	<b>Date:</b> 16 May 2003</p>
	<p><b>Author:</b> Alexander Serbe ( <a href="mailto:hide@address.com">hide@address.com</a> )<br />
	<b>Contributor(s):</b></p>
	<p><b>Requirements:</b> PHP enabled webserver (PHP4+), access to a MySQL server.</p>
	<p><b>License:</b> <a href="http://www.gnu.org/licenses/gpl.html" target="_blank">GNU General Public License</a><br />
	<span class="small">(Please note the license terms at the end of this document)</span></p>
	<p><i>xMySQL</i> is a PHP class to ease the daily work with MySQL databases. It has been designed to be as simple and effective as possible. Therefore all <i>&quot;unnecessary&quot;</i> functionalities have deliberately been left out and only those you will need more frequently like connecting and disconnecting to or from a MySQL server and executing the basic types of queries like SELECT, INSERT, UPDATE, or DELETE queries, are implemented.</p>
	<p>Nevertheless, these <i>&quot;unnecessary&quot;</i> functionalities may be covered by some classes extending this one, later.</p>
	<hr size="1" color="#000000" noshade />
	<h2><a name="vh"></a>Version History</h2>
	<br />
	<table border="0" cellpadding="3" cellspacing="0" width="100%">
	<tr>
		<td valign="top" width="80"><b>1.0</b></td>
		<td valign="top" width="120">01 Aug 2002</td>
		<td>Initial Release.</td>
	</tr>
	<tr>
		<td valign="top"><b>1.1</b></td>
		<td valign="top">19 Dec 2002</td>
		<td>Update.</td>
	</tr>
	<tr>
		<td valign="top"><b>2.0</b></td>
		<td valign="top">05 Mar 2003</td>
		<td>Update.</td>
	</tr>
	<tr>
		<td valign="top"><b>2.1</b></td>
		<td valign="top">16 May 2003</td>
		<td>Update. New methods <i>classInfo</i>, <i>loadFile</i> and <i>xQuery</i> added. Implementation of the <i>objectStatus</i> class.</td>
	</tr>
	<tr>
		<td align="right" colspan="3"><a href="#top">Back to Top</a></td>
	</tr>
	</table>
	<br />
	<hr size="1" color="#000000" noshade />
	<h2><a name="var"></a>Object Variables</h2>
	<br />
	<table border="0" cellpadding="3" cellspacing="0" width="100%">
	<tr>
		<td valign="top"><b>conn_id</b></td>
		<td><i>Mixed</i> [int/bool]. MySQL connection id.</td>
	</tr>
	<tr>
		<td valign="top"><b>db_host</b></td>
		<td><i>String</i>. MySQL host.</td>
	</tr>
	<tr>
		<td valin="top"><b>db_name</b></td>
		<td><i>String</i>. MySQL database.</td>
	</tr>
	<tr>
		<td valign="top"><b>db_pwd</b></td>
		<td><i>String</i>. MySQL password.</td>
	</tr>
	<tr>
		<td valign="top"><b>db_uid</b></td>
		<td><i>String</i>. MySQL username.</td>
	</tr>
	<tr>
		<td valign="top"><b>host_list</b></td>
		<td><i>String</i>. Contents of the <i>host list</i> file</td>
	</tr>
	<tr>
		<td align="right" colspan="2"><a href="#top">Back to Top</a></td>
	</tr>
	</table>
	<br />
	<hr size="1" color="#000000" noshade />
	<h2><a name="mlist"></a>Object Methods (Overview)</h2>
	<br />
	<ul>
		<li><a href="#classinfo">classInfo</a> (public)<br />
		Provides information about the class.</li>
		<li><a href="#loadfile">loadFile</a> (private)<br />
		Loads the content of a text file either ino a scalar variable (string) or line by line into an array.</li>
		<li><a href="#setdbconnection">setDbConnection</a> (public)<br />
		Stores the connection data provided in the host list file for one specific MySQL server.</li>
		<li><a href="#xclose">xClose</a> (private)<br />
		Terminates an existing connection to a MySQL server.</li>
		<li><a href="#xconnect">xConnect</a> (private)<br />
		Connects to the MySQL server currently set with the <i>setDbConnection</i> method.</li>
		<li><a href="#xdelete">xDelete</a> (public)<br />
		Executes a DELETE query and returns either the number of affected rows or <i>false</i> if no rows were affected or an error occured.</li>
		<li><a href="#xinsert">xInsert</a> (public)<br />
		Executes an INSERT query and returns the id of the inserted record or <i>false</i> if an error occured.</li>
		<li><a href="#xmysql">xMySQL</a> (public / constructor)<br />
		Initializes a new xMySQL object.</li>
		<li><a href="#xquery">xQuery</a> (public)<br />
		Executes a query and returns the resource id or <i>false</i> if an error occured.</li>
		<li><a href="#xselect">xSelect</a> (public)<br />
		Executes a SELECT query and returns the results in a two-dimensional array or <i>false</i> if an error occured.</li>
		<li><a href="#xupdate">xUpdate</a> (public)<br />
		Executes an UPDATE query and returns either the number of affected rows or <i>false</i> if no rows were affected or an error occured.</li>
	</ul>
	<br />
	<div align="right"><a href="#top">Back to Top</a></div>
	<hr size="1" color="#000000" noshade />
	<h2><a name="ref"></a>Function Reference</h2>
	<br />
	<table border="0" cellpadding="3" cellspacing="0">
	<tr>
		<td colspan="2"><a name="classinfo"></a><b>classInfo</b> <span class="small">(added v2.1)</span></td>
	</tr>
	<tr>
		<td width="100"><u>Signature:</u></td>
		<td><i>array</i> <b>classInfo (</b> <i>void</i> <b>)</b></td>
	</tr>
	<tr>
		<td width="100"><u>Access:</u></td>
		<td>Public</td>
	</tr>
	<tr>
		<td valign="top" width="100"><u>Description:</u></td>
		<td>Provides information about the class. Returns an associative array cointaining the following elements: name, version, extends, implements, date, author, email, contributors, copyright, license, download (url), check_version (url).</td>
	</tr>
	<tr>
		<td align="right" colspan="2"><a href="#mlist">Back to List</a> | <a href="#top">Back to Top</a></td>
	</tr>
	<tr>
		<td colspan="2"><hr size="1" color="#c0c0c0" noshade /></td>
	</tr>
	<tr>
		<td colspan="2"><a name="loadfile"></a><b>loadFile</b> <span class="small">(added v2.1)</span></td>
	</tr>
	<tr>
		<td width="100"><u>Signature:</u></td>
		<td><i>mixed</i> <b>loadFile (</b> <i>string</i> file [, <i>integer</i> mode] <b>)</b></td>
	</tr>
	<tr>
		<td width="100"><u>Access:</u></td>
		<td>Private</td>
	</tr>
	<tr>
		<td valign="top" width="100"><u>Description:</u></td>
		<td>Loads the content of a file (<i>$file</i>) either into a scalar variable (string, mode 1) or an array (mode 2). Returns the file content in the chosen format or <i>false</i> if the file was empty or doesn't exist.</td>
	</tr>
	<tr>
		<td align="right" colspan="2"><a href="#mlist">Back to List</a> | <a href="#top">Back to Top</a></td>
	</tr>
	<tr>
		<td colspan="2"><hr size="1" color="#c0c0c0" noshade /></td>
	</tr>
	<tr>
		<td colspan="2"><a name="setdbconnection"></a><b>setDbConnection</b> <span class="small">(added v1.1; last modified v2.1)</span></td>
	</tr>
	<tr>
		<td width="100"><u>Signature:</u></td>
		<td><i>boolean</i> <b>setDbConnection (</b> <i>integer</i> host_id <b>)</b></td>
	</tr>
	<tr>
		<td width="100"><u>Access:</u></td>
		<td>Public</td>
	</tr>
	<tr>
		<td valign="top" width="100"><u>Description:</u></td>
		<td>Stores the data needed to connect to a MySQL server. Returns <i>true</i> if the host was found in the list, otherwise <i>false</i>.</td>
	</tr>
	<tr>
		<td align="right" colspan="2"><a href="#mlist">Back to List</a> | <a href="#top">Back to Top</a></td>
	</tr>
	<tr>
		<td colspan="2"><hr size="1" color="#c0c0c0" noshade /></td>
	</tr>
	<tr>
		<td colspan="2"><a name="xclose"></a><b>xClose</b> <span class="small">(added v1.0; last modified v2.1)</span></td>
	</tr>
	<tr>
		<td width="100"><u>Signature:</u></td>
		<td><i>boolean</i> <b>xClose (</b> <i>void</i> <b>)</b></td>
	</tr>
	<tr>
		<td width="100"><u>Access:</u></td>
		<td>Private</td>
	</tr>
	<tr>
		<td valign="top" width="100"><u>Description:</u></td>
		<td>Disconnects from a MySQL server. Returns <i>true</i> if the attempt was successful, otherwise <i>false</i>.</td>
	</tr>
	<tr>
		<td align="right" colspan="2"><a href="#mlist">Back to List</a> | <a href="#top">Back to Top</a></td>
	</tr>
	<tr>
		<td colspan="2"><hr size="1" color="#c0c0c0" noshade /></td>
	</tr>
	<tr>
		<td colspan="2"><a name="xconnect"></a><b>xConnect</b> <span class="small">(added v1.0; last modified v2.1)</span></td>
	</tr>
	<tr>
		<td width="100"><u>Signature:</u></td>
		<td><i>boolean</i> <b>xConnect (</b> <i>void</i> <b>)</b></td>
	</tr>
	<tr>
		<td width="100"><u>Access:</u></td>
		<td>Private</td>
	</tr>
	<tr>
		<td valign="top" width="100"><u>Description:</u></td>
		<td>Connects to a MySQLserver. Returns <i>true</i> if the attempt was successful, otherwise <i>false</i>.</td>
	</tr>
	<tr>
		<td align="right" colspan="2"><a href="#mlist">Back to List</a> | <a href="#top">Back to Top</a></td>
	</tr>
	<tr>
		<td colspan="2"><hr size="1" color="#c0c0c0" noshade /></td>
	</tr>
	<tr>
		<td colspan="2"><a name="xdelete"></a><b>xDelete</b> <span class="small">(added v1.0; last modified v2.1)</span></td>
	</tr>
	<tr>
		<td width="100"><u>Signature:</u></td>
		<td><i>integer</i> <b>xDelete (</b> <i>string</i> table [, <i>string</i> where] <b>)</b></td>
	</tr>
	<tr>
		<td width="100"><u>Access:</u></td>
		<td>Public</td>
	</tr>
	<tr>
		<td valign="top" width="100"><u>Description:</u></td>
		<td>Executes a DELETE query in table <i>$table</i>. Returns  the number of deleted records or <i>false</i> if no records were deleted or an error occured.</td>
	</tr>
	<tr>
		<td align="right" colspan="2"><a href="#mlist">Back to List</a> | <a href="#top">Back to Top</a></td>
	</tr>
	<tr>
		<td colspan="2"><hr size="1" color="#c0c0c0" noshade /></td>
	</tr>
	<tr>
		<td colspan="2"><a name="xinsert"></a><b>xInsert</b> <span class="small">(added v1.0; last modified v2.1)</span></td>
	</tr>
	<tr>
		<td width="100"><u>Signature:</u></td>
		<td><i>integer</i> <b>xInsert (</b> <i>string</i> table, <i>array</i> fields, <i>array</i> values <b>)</b></td>
	</tr>
	<tr>
		<td width="100"><u>Access:</u></td>
		<td>Public</td>
	</tr>
	<tr>
		<td valign="top" width="100"><u>Description:</u></td>
		<td>Executes an INSERT query. Returns the id of the inserted record. If an error occured <i>false</i>.</td>
	</tr>
	<tr>
		<td align="right" colspan="2"><a href="#mlist">Back to List</a> | <a href="#top">Back to Top</a></td>
	</tr>
	<tr>
		<td colspan="2"><hr size="1" color="#c0c0c0" noshade /></td>
	</tr>
	<tr>
		<td colspan="2"><a name="xmysql"></a><b>xMySQL</b> <span class="small">(added v1.0; last modified v2.1)</span></td>
	</tr>
	<tr>
		<td width="100"><u>Signature:</u></td>
		<td><i>void</i> <b>xMySQL (</b> <i>string</i> host_list, <i>integer</i> host_id [, <i>object</i> os] <b>)</b></td>
	</tr>
	<tr>
		<td width="100"><u>Access:</u></td>
		<td>Public / Constructor</td>
	</tr>
	<tr>
		<td valign="top" width="100"><u>Description:</u></td>
		<td>Initializes a new xMySQL object. Returns <i>void</i>.</td>
	</tr>
	<tr>
		<td align="right" colspan="2"><a href="#mlist">Back to List</a> | <a href="#top">Back to Top</a></td>
	</tr>
	<tr>
		<td colspan="2"><hr size="1" color="#c0c0c0" noshade /></td>
	</tr>
	<tr>
		<td colspan="2"><a name="xquery"></a><b>xQuery</b> <span class="small">(added v2.1)</span></td>
	</tr>
	<tr>
		<td width="100"><u>Signature:</u></td>
		<td><i>integer</i> <b>xQuery (</b> <i>string</i> query <b>)</b></td>
	</tr>
	<tr>
		<td width="100"><u>Access:</u></td>
		<td>Public</td>
	</tr>
	<tr>
		<td valign="top" width="100"><u>Description:</u></td>
		<td>Executes a query and returns the resource id. If an error occured, xQuery returns <i>false</i>.</td>
	</tr>
	<tr>
		<td align="right" colspan="2"><a href="#mlist">Back to List</a> | <a href="#top">Back to Top</a></td>
	</tr>
	<tr>
		<td colspan="2"><hr size="1" color="#c0c0c0" noshade /></td>
	</tr>
	<tr>
		<td colspan="2"><a name="xselect"></a><b>xSelect</b> <span class="small">(added v1.0; v2.1)</span></td>
	</tr>
	<tr>
		<td width="100"><u>Signature:</u></td>
		<td><i>array</i> <b>xSelect (</b> <i>string</i> select, <i>string</i> from [, <i>string</i> where [, <i>string</i> order_by [, <i>string</i> limit]]] <b>)</b></td>
	</tr>
	<tr>
		<td width="100"><u>Access:</u></td>
		<td>Public</td>
	</tr>
	<tr>
		<td valign="top" width="100"><u>Description:</u></td>
		<td>Executes a SELECT query and returns a two-dimensional array containing the results. If no records were found or an error occured, xSelect returns <i>false</i>.</td>
	</tr>
	<tr>
		<td align="right" colspan="2"><a href="#mlist">Back to List</a> | <a href="#top">Back to Top</a></td>
	</tr>
	<tr>
		<td colspan="2"><hr size="1" color="#c0c0c0" noshade /></td>
	</tr>
	<tr>
		<td colspan="2"><a name="xupdate"></a><b>xUpdate</b> <span class="small">(added v1.0; last modified v2.1)</span></td>
	</tr>
	<tr>
		<td width="100"><u>Signature:</u></td>
		<td><i>integer</i> <b>xUpdate (</b> <i>string</i> table, <i>array</i> fields, <i>array</i> values [, <i>string</i> where] <b>)</b></td>
	</tr>
	<tr>
		<td width="100"><u>Access:</u></td>
		<td>Public</td>
	</tr>
	<tr>
		<td valign="top" width="100"><u>Description:</u></td>
		<td>Executes an UPDATE query. Returns the number of affected rows or <i>false</i> if an error occured.</td>
	</tr>
	<tr>
		<td align="right" colspan="2"><a href="#mlist">Back to List</a> | <a href="#top">Back to Top</a></td>
	</tr>
	</table>
	<br />
	<hr size="1" color="#000000" noshade />
	<h2><a name="ex"></a>Example</h2>
	<br />
	<p>To run this script, you should change the file <i>&quot;xmysql.host_list.php&quot</i> to match your MySQL server. If you use it local, it should be enough to change the database.<br />
	Execute the script called <i>&quot;testdata.php&quot;</i> (make sure to place it in the same folder as the xMySQL class). This script creates a table named <i>xmysql_test</i> and inserts some data into it.<br />
	<br />
	<div class="markup"><span class="comment">// Include the class files</span><br />
	include ( &quot;objectstatus.class.php&quot; );<br />
	include ( &quot;xmysql.class.php&quot; );<br />
	<br />
	<span class="comment">// Initialize a new objectStatus instance. This is not mandatory...</span><br />
	$os = new objectStatus ();<br />
	<br />
	<span class="comment">// Initialize a new xMySQL object</span><br />
	$db = new xMySQL ( &quot;xmysql.host_list.php&quot;, 0, &amp;$os );<br />
	<br />
	<span class="comment">// Execute a SELECT query</span><br />
	$select = &quot;test_field_1, test_field_2&quot;;<br />
	$from = &quot;xmysql_test&quot;;<br />
	$where = &quot;test_id>=5&quot;;<br />
	<br />
	$result = $db->xSelect ( $select, $from, $where );<br />
	<br />
	<span class="comment">// Print out the results</span><br />
	echo &quot;&lt;hr /&gt;&quot;;<br />
	for ( $i=0; $i&lt;count ( $result ); $i++ )<br />
	{<br />
	&nbsp;&nbsp;&nbsp;&nbsp;$row = $result[$i];<br />
	&nbsp;&nbsp;&nbsp;&nbsp;echo $row[0] . &quot;-&quot; . $row[1] . &quot;<br />&quot;;<br />
	}<br />
	echo &quot;&lt;hr /&gt;&quot;;<br />
	<br />
	<span class="comment">// Display status messages...</span><br 7>
	echo $db->os->statusPrintout ();<br />
	...
	</div>
	<p>I have attached this file (named <i>&quot;example.php&quot;</i>) to the download package of this class... So you won't have to hack it in yourself ;-).</p>
	<p><b>Note:</b> I tried to make this example as easy and comprehensible as possible. But since I have developed this thing, some aspects in this example may seem completely clear to me... but not to you. If you encounter any problems with this class, please don't hesitate <a href="mailto:hide@address.com?subject=xMySQL">asking me</a>.</p>
	<p align="right" class="small"><a href="#top">Back to Top</a></p>
	<br />
	<hr size="1" color="#000000" noshade />
	<h2><a name="lic"></a>GNU General Public License</h2>
	<br />
	<p>This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.<br />
	This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details.<br />
	You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.</p>
	<p align="right" class="small"><a href="#top">Back to Top</a> | <a href="http://www.gnu.org/licenses/gpl.html#SEC1" target="_blank">more...</a></p>
	<hr size="1" color="#c0c0c0" noshade />
	<p>Dieses Programm ist freie Software. Sie können es unter den Bedingungen der GNU General Public License, wie von der Free Software Foundation veröffentlicht, weitergeben und/oder modifizieren, entweder gemäß Version 2 der Lizenz oder (nach Ihrer Option) jeder späteren Version.<br />
	Die Veröffentlichung dieses Programms erfolgt in der Hoffnung, daß es Ihnen von Nutzen sein wird, aber OHNE IRGENDEINE GARANTIE, sogar ohne die implizite Garantie der MARKTREIFE oder der VERWENDBARKEIT FÜR EINEN BESTIMMTEN ZWECK. Details finden Sie in der GNU General Public License.<br />
	Sie sollten eine Kopie der GNU General Public License zusammen mit diesem Programm erhalten haben. Falls nicht, schreiben Sie an die Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.</p>
	<p align="right" class="small"><a href="#top">Back to Top</a> | <a href="http://www.gnu.de/gpl-ger.html" target="_blank">mehr...</a></p>
	<hr size="1" color="#c0c0c0" noshade />
	<p>Ce programme est libre, vous pouvez le redistribuer et/ou le modifier selon les termes de la Licence Publique Générale GNU publiée par la Free Software Foundation (version 2 ou bien toute autre version ultérieure choisie par vous).<br />
	Ce programme est distribué car potentiellement utile, mais SANS AUCUNE GARANTIE, ni explicite ni implicite, y compris les garanties de commercialisation ou d'adaptation dans un but spécifique. Reportez-vous à la Licence Publique Générale GNU pour plus de détails.<br />
	Vous devez avoir reçu une copie de la Licence Publique Générale GNU en même temps que ce programme ; si ce n'est pas le cas, écrivez à la Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, États-Unis.</p>
	<p align="right" class="small"><a href="#top">Back to Top</a> | <a href="http://www.linux-france.org/prj/escritor/FR/GPL.htm#GPL-Adresse" target="_blank">plus...</a></p>
	<hr size="1" color="#000000" noshade />
	<p align="center" class="small">Copyright &copy; 2002, 2003 by Alexander Serbe. All rights reserved.</p>
</div>

</body>
</html>
Return current item: xMySQL