Thread: [Phpgamedev-cvs-commits] plugins readme.html,NONE,1.1
Status: Planning
Brought to you by:
sphen001
From: Nick <sph...@us...> - 2005-06-09 01:39:33
|
Update of /cvsroot/phpgamedev/plugins In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24971 Added Files: readme.html Log Message: Initial commit of readme file. --- NEW FILE: readme.html --- <!-- $Id: readme.html,v 1.1 2005/06/09 01:39:24 sphen001 Exp $ --> <html> <head> <title>PHPGameDev DB Abstraction Layer</title> <link rel="stylesheet" href="style.css" type="text/css" /> </head> <body> <p class="titles" align="center">PHPGameDev DB Abstraction Layer Readme</p> <center><a href="http://phpgamedev.sourceforge.net/index.html">Back to Index</a></center> <br /> <table class="tablebg" width="90%" align="center" border="0" cellspacing="1" cellpadding="1"> <tr> <th colspan="2"> Feature List </th> </tr> <tr> <td class="nav" colspan="2" align="center"> Features of the PHPGameDev DB Abstraction Layer </td> </tr> <tr> <td class="row1" width="25%"> DB Layer Definition: </td> <td class="row2"> All of the DB layers support a type definition. You can use this definition to switch between code for different DBMS's. <br /><br /> For example, if you had a query that would not run in Oracle, you could use a switch to switch what code you use. <br /><br /> <pre> <span class="php_comment">// We have a query that will run on every DBMS except Oracle</span> <span class="php_keyword">switch</span> ( <span class="php_default">DB</span> ) { <span class="php_keyword">case</span> <span class="php_string">'MySQL'</span> : <span class="php_keyword">case</span> <span class="php_string">'MSSQL'</span> : <span class="php_default">$sql</span> = <span class="php_string">'Regular SQL code here'</span>; <span class="php_keyword">break</span>; <span class="php_keyword">case</span> <span class="php_string">'Oracle'</span> : <span class="php_default">$sql</span> = <span class="php_string">'Oracle specific SQL code here'</span>; <span class="php_keyword">break</span>; } </pre> </td> </tr> <tr> <td class="row1" width="25%"> Connection Type: </td> <td class="row2"> Supports both normal and persistent connections. </td> </tr> </table> <br /> <table class="tablebg" width="90%" align="center" border="0" cellspacing="1" cellpadding="1"> <tr> <th colspan="2"> Function Reference </th> </tr> <tr> <td class="nav" colspan="2" align="center"> Here we'll define all the functions and explain what they are used for. </td> </tr> <tr> <td class="row1" width="25%"> Function:<br />connect($db_host, $db_username, $db_password, $db, $persistent = FALSE) </td> <td class="row2"> This function connects to a DB. Only <b>$persistent</b> is not required. <br /><br /> <b>$db_host:</b> The hostname of the DB server you are connecting to. <br /> <b>$db_username:</b> The DB username you will be using. <br /> <b>$db_password:</b> The DB password you will be using. <br /> <b>$db:</b> The specific DB you will be accessing. <br /> <b>$persistent:</b> Open a persistent connection or not. Defaults to no. <br /><br /> Returns TRUE on success, and FALSE on failure. <br /><br /> <b>Example:</b> <br /> <pre> <span class="php_default">$db</span>-><span class="php_default">connect</span>(<span class="php_string">'localhost', 'root', '', 'some_db', FALSE)</span>; </pre> </td> </tr> <tr> <td class="row1" width="25%"> Function:<br />disconnect() </td> <td class="row2"> This function disconnects from a DB. You do not specify any arguments. <br /><br /> Returns TRUE on success, and FALSE on failure. <br /><br /> <b>Example:</b> <br /> <pre> <span class="php_default">$db</span>-><span class="php_default">disconnect</span>(); </pre> </td> </tr> <tr> <td class="row1" width="25%"> Function:<br />query($query) </td> <td class="row2"> This function executes a query on the DB. All arguments are required. <br /><br /> <b>$query:</b> The SQL query that is to be executed. <br /><br /> Returns the result on success, and FALSE on failure. <br /><br /> <b>Example:</b> <br /> <pre> <span class="php_default">$sql</span> = <span class="php_string">"SELECT *</span> <span class="php_string">FROM some_db</span> <span class="php_string">WHERE some_condition='some_condition'"</span>; <span class="php_default">$db</span>-><span class="php_default">query($sql)</span>; </pre> </td> </tr> <tr> <td class="row1" width="25%"> Function:<br />fetch_row($result, $type = 'ASSOC') </td> <td class="row2"> This function fetches a row from the DB. Only $result is required. <br /><br /> <b>$result:</b> The result of an executed SQL query. <br /> <b>$type:</b> The type of fetch_row you want to perform. Defaults to ASSOC. <br /><br /> <b>Types:</b> <br /><br /> <b>ASSOC:</b> Fetches an associative array (mysql_fetch_assoc()) <br /> <b>ARRAY:</b> Fetches an array (mysql_fetch_array()) <br /> <b>OBJECT:</b> Fetches an object (mysql_fetch_object()) <br /> <b>ROW:</b> Fetches a single row (mysql_fetch_row()) <br /><br /> Returns row on success, and FALSE on failure. <br /><br /> <b>Example:</b> <br /> <pre> <span class="php_keyword">while</span> ( <span class="php_default">$row</span> = <span class="php_default">$db</span>-><span class="php_default">fetch_row</span>(<span class="php_default">$result</span>, <span class="php_string">'ASSOC'</span>) ) { <span class="php_keyword">echo</span> <span class="php_default">$row</span>[<span class="php_string">'field_name'</span>]; } <span class="php_keyword">while</span> ( <span class="php_default">$row</span> = <span class="php_default">$db</span>-><span class="php_default">fetch_row</span>(<span class="php_default">$result</span>, <span class="php_string">'ARRAY'</span>) ) { <span class="php_keyword">echo</span> <span class="php_default">$row</span>[0]; } <span class="php_keyword">while</span> ( <span class="php_default">$row</span> = <span class="php_default">$db</span>-><span class="php_default">fetch_row</span>(<span class="php_default">$result</span>, <span class="php_string">'OBJECT'</span>) ) { <span class="php_keyword">echo</span> <span class="php_default">$row</span>-><span class="php_default">some_field</span>; } <span class="php_keyword">while</span> ( <span class="php_default">$row</span> = <span class="php_default">$db</span>-><span class="php_default">fetch_row</span>(<span class="php_default">$result</span>, <span class="php_string">'ROW'</span>) ) { <span class="php_keyword">echo</span> <span class="php_default">$row</span>[0]; } </pre> </td> </tr> <tr> <td class="row1" width="25%"> Function:<br />num_rows($result) </td> <td class="row2"> This function fetches the number of rows affected by the executed SQL query. All arguments are required. <br /><br /> <b>$result:</b> The result of an executed SQL query. <br /><br /> Returns number of rows on success, and FALSE on failure. <br /><br /> <b>Example:</b> <br /> <pre> <span class="php_keyword">echo</span> <span class="php_default">$db</span>-><span class="php_default">num_rows</span>(<span class="php_default">$result</span>); </pre> </td> </tr> <tr> <td class="row1" width="25%"> Function:<br />free_result($result) </td> <td class="row2"> This function frees up the memory associated with the executed SQL query. All arguments are required. <br /><br /> <b>$result:</b> The result of an executed SQL query. <br /><br /> Returns TRUE always. <br /><br /> <b>Example:</b> <br /> <pre> <span class="php_default">$db</span>-><span class="php_default">free_result</span>(<span class="php_default">$result</span>); </pre> </td> </tr> <tr> <td class="row1" width="25%"> Function:<br />num_queries() </td> <td class="row2"> This function returns the number of queries that were performed during the scripts execution. <br /><br /> Returns the number of queries performed. <br /><br /> <b>Example:</b> <br /> <pre> <span class="php_keyword">echo</span> <span class="php_default">$db</span>-><span class="php_default">num_queries</span>(); </pre> </td> </tr> <tr> <td class="row1" width="25%"> Function:<br />escape($sql) </td> <td class="row2"> This function escapes a SQL query. <br /><br /> Returns the escaped query <br /><br /> <b>Example:</b> <br /> <pre> <span class="php_default">$sql</span> = <span class="php_string">"SELECT *</span> <span class="php_string">FROM some_table"</span>; <span class="php_default">$sql</span> = <span class="php_default">$db</span>-><span class="php_default">escape</span>(<span class="php_default">$sql</span>); </pre> </td> </tr> </table> <br /> <table class="tablebg" width="90%" align="center" border="0" cellspacing="1" cellpadding="1"> <tr> <th colspan="2"> Variable Reference </th> </tr> <tr> <td class="nav" colspan="2" align="center"> Here are explanations of the variables used in the DB layer. </td> </tr> <tr> <td class="row1" width="25%"> <b>var $connect_id:</b> </td> <td class="row2"> Contains the connection details of the DB connection. </td> </tr> <tr> <td class="row1" width="25%"> <b>var $query_result:</b> </td> <td class="row2"> Contains the result of the executed SQL query. </td> </tr> <tr> <td class="row1" width="25%"> <b>var $query_rowset:</b> </td> <td class="row2"> Contains a row selected from the result of the executed SQL query. </td> </tr> <tr> <td class="row1" width="25%"> <b>var $num_rows:</b> <td class="row2"> Contains the number of affected rows. </td> </tr> <tr> <td class="row1" width="25%"> <b>var $num_queries:</b> </td> <td class="row2"> Contains the number of queries performed in the scripts execution. </td> </tr> </table> <br /> <table class="tablebg" width="90%" align="center" border="0" cellspacing="1" cellpadding="1"> <tr> <th>Example Script</th> </tr> <tr> <td class="nav" colspan="2" align="center"> An example script to demonstrate the features of this layer </td> </tr> <tr> <td class="row1"> <pre> <span class="php_comment">// Include the DB layer, and instantiate a new class</span> <span class="php_keyword">include</span> <span class="php_string">'./db_*.php'</span>; <span class="php_default">$db</span> = <span class="php_keyword">new</span> <span class="php_default">db</span>; <span class="php_comment">// Connect</span> <span class="php_default">$db</span>-><span class="php_default">connect</span>(<span class="php_string">'localhost'</span>, <span class="php_string">'root'</span>, <span class="php_string">''</span>, <span class="php_string">'db'</span>, <span class="php_keyword">FALSE</span>); <span class="php_comment">// Perform a query</span> <span class="php_keyword">switch</span> ( <span class="php_default">DB</span> ) { <span class="php_keyword">case</span> <span class="php_string">'MySQL'</span> : <span class="php_keyword">case</span> <span class="php_string">'MSSQL'</span> : <span class="php_default">$sql</span> = <span class="php_string">"SELECT *</span> <span class="php_string">FROM some_table"</span>; <span class="php_keyword">break</span>; <span class="php_keyword">case</span> <span class="php_string">'Oracle'</span> : <span class="php_default">$sql</span> = <span class="php_string">"Oracle specific code"</span>; <span class="php_keyword">break</span>; } <span class="php_default">$sql</span> = <span class="php_default">$db</span>-><span class="php_default">escape($sql)</span>; <span class="php_default">$result</span> = <span class="php_default">$db</span>-><span class="php_default">query($sql)</span>; <span class="php_comment">// Get the result set</span> <span class="php_keyword">while</span> ( <span class="php_default">$row</span> = <span class="php_default">$db</span>-><span class="php_default">fetch_row($result</span>, <span class="php_string">'ASSOC'</span>) ) { <span class="php_keyword">echo</span> <span class="php_default">$row</span>[<span class="php_string">'field_name'</span>]; } <span class="php_comment">// Get then number of affected rows and number of queries</span> <span class="php_keyword">echo</span> <span class="php_default">$db</span>-><span class="php_default">num_rows($result)</span>; <span class="php_keyword">echo</span> <span class="php_default">$db</span>-><span class="php_default">num_queries()</span>; <span class="php_comment">// Disconnect</span> <span class="php_default">$db</span>-><span class="php_default">disconnect()</span>; </pre> </td> </tr> </table> <br /> <center><a href="http://phpgamedev.sourceforge.net/index.html">Back to Index</a></center> |