[Phpgamedev-cvs-commits] website/docs db_readme.php,NONE,1.1
Status: Planning
Brought to you by:
sphen001
From: Nick <sph...@us...> - 2005-06-14 20:21:08
|
Update of /cvsroot/phpgamedev/website/docs In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21552/docs Added Files: db_readme.php Log Message: --- NEW FILE: db_readme.php --- <?php //----------------------------------------------------------- // FILENAME : index.php // STARTED : Mon Jun 13, 2005 // AUTHOR : Sphen001 (Nick Ross) // SUPPORT : http://phpgamedev.sourceforge.net // COPYRIGHT : Copyright 2005 © PHPGameDev Group // E-MAIL : Sphen001 -at- users -dot- sourceforge -dot- net // $Id: db_readme.php,v 1.1 2005/06/14 20:20:57 sphen001 Exp $ //----------------------------------------------------------- echo (' <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <title> PHPGameDev DB Abstraction Layer </title> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /> <link rel="stylesheet" href="../styles/style.css" type="text/css" /> </head> <body> <!-- Begin header --> <p class="titles" align="center"> PHPGameDev DB Abstraction Layer Readme </p> <br /> <!-- Begin body --> <!-- Begin features --> <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%"> <b> DB Layer Definition: </b> </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%"> <b> Connection Type: </b> </td> <td class="row2"> Supports both normal and persistent connections. </td> </tr> </table> <!-- End features --> <br /> <!-- Begin functions --> <table class="tablebg" width="10%" 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%"> <b> Function:<br />connect($db_host, $db_username, $db_password, $db, $persistent = FALSE) </b> </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%"> <b> Function:<br />disconnect() </b> </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%"> <b> Function:<br />query($query) </b> </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%"> <b> Function:<br />fetch_row($result, $type = \'ASSOC\') </b> </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%"> <b> Function:<br />num_rows($result) </b> </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%"> <b> Function:<br />free_result($result) </b> </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%"> <b> Function:<br />num_queries() </b> </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%"> <b> Function:<br />escape($sql) </b> </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> <!-- End functions --> <br /> <!-- Begin variables --> <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> <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> <!-- End variables --> <br /> <!-- Begin example --> <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">$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> <!-- End example --> <br /> <!-- Begin footer --> <center> <a href="../index.php">Back to Index</a> </center> <br /> <center> <a href="http://validator.w3.org/check?uri=http%3A%2F%2Fphpgamedev.sourceforge.net%2Fdocs%2Fdb_readme.php"><img src="http://www.w3.org/Icons/valid-xhtml10" alt="Valid XHTML 1.0!" height="31" width="88" /></a> </center> <br /> <center> <a href="http://sourceforge.net/projects/phpgamedev/"><img src="http://sourceforge.net/sflogo.php?group_id=140827&type=5" width="210" height="62" border="0" alt="SourceForge.net Logo" /></a> </center> <br /> <p class="copyright" align="center"> All information on this website is Copyright © PHPGameDev Group 2005 </p> <!-- End footer --> </body> </html> '); ?> |