<?php
mb_http_input("iso-8859-1");
mb_http_output("iso-8859-1");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>TbsSQL</title>
<style type="text/css">
<!--
body,td,th {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 11px;
}
.sql {
font-family: "Courier New", Courier, mono;
color: #006600;
}
.decal {
margin-left: 10px;
}
.title1 {
font-size: 13px;
font-weight: bold;
}
.versioning {
background-color: #EAEAEA;
}
.split {
border-bottom-width: 1px;
border-bottom-style: solid;
border-bottom-color: #666666;
}
.split0 {
border-top-width: 1px;
border-top-style: solid;
border-top-color: #666666;
}
-->
</style>
</head>
<body>
<table width="100%" border="0" cellspacing="0" cellpadding="3">
<tr>
<td width="200"><a href="http://www.tinybutstrong.com">Skrol29</a>, 2007-03-02 </td>
<td><h3 align="center">TbsSQL 2.0</h3></td>
<td width="200"> </td>
</tr>
</table>
<hr />
TbsSQL is a PHP class for SQL abstraction.<br />
The goal of this tool is to reduce the code when working with SQL through PHP.<br />
The TbsSQL is available for the following databases:<br />
<div class="decal">- MySQL<br />
- MySQLi<br />
- SQL-Server (via Ms-Odbc)<br />
- PostgreSQL (version 7.2 or higher) </div>
<br />
<br />
<span class="title1">• Coding </span><br />
<div class="decal"> The main asset of TbsSQL is the habitably to merge in the SQL statement a variable number of arguments and protect them against <a href="http://en.wikipedia.org/wiki/Sql_injection">Sql Injection</a>.<br />
<br />
<u>Example:</u> <br />
<div class="sql">$id = 29;<br />
$name = "boby";
<br />
$Db->Execute('UPDATE table1 SET name=@2@ WHERE (id=%1%)', $id, $name);</div>
<br />
In this example, the SQL statement sent to the database will be: <span class="sql">UPDATE table1 SET name='boby' WHERE (id=29)</span><br />
<br />
TbsSQL supports the following jokers in your SQL statements:<br />
(n must be the number of the place of the argument in the TbsSQL command)<br />
<table width="100%" border="0" cellspacing="0" cellpadding="3">
<tr>
<td width="10">-</td>
<td width="40">%n%</td>
<td>the argument will be protected against Sql Injection.</td>
</tr>
<tr>
<td>-</td>
<td>@n@ </td>
<td>the argument will be protected against Sql Injection and delimited as a string value with the relevant format for the database.</td>
</tr>
<tr>
<td>-</td>
<td>#n#</td>
<td>the argument will be converted as a date value without time with the relevant format for the database.</td>
</tr>
<tr>
<td>-</td>
<td>~n~ </td>
<td>the argument will be converted as a date and time value with the relevant format for the database. </td>
</tr>
</table>
</div>
<br />
<span class="title1">• Hook </span><br />
<div class="decal"> TbsSQL is compatible with the <a href="http://www.tinybutstrong.com">TinyButStrong</a> Template Engine.<br />
Use the keyword 'tbssql' to have the MergeBlock() method using your TbsSQL instance.<br />
Example : <span class="sql">$TBS->MergeBlock('block1','tbssql','SELECT * FROM table1')</span></div>
<span class="title1"><br />
• License<br />
</span>
<div class="decal"> TbsSQL is a free and open source. It is published under the LGPL license. </div>
<br />
<span class="title1">• Synopsis </span><br />
<div class="decal">
<table width="100%" border="0" cellspacing="0" cellpadding="4">
<tr>
<td width="260" valign="top" class="split0 split">$Db = new <strong>clsTbsSQL</strong>($srv='',$uid='',$pwd='',$db='',$drv=''); </td>
<td valign="top" class="split0 split">Instantiates the class.
Giving connection information is optional. </td>
</tr>
<tr>
<td valign="top" class="split">$Db-><strong>Connect</strong>($srv,$uid,$pwd,$db,$drv='')<br />
or<br />
$Db-><strong>Connect</strong>('glob_var');</td>
<td valign="top" class="split">Open a connection to the database.<br />
Syntax 1 example:<br />
<div class="decal"><span class="sql">$Db->Connect('localhost','root','xxx','db_prod');</span><br />
The argument $drv is needed only for some Dabase Systems.</div>
Syntax 2 example:<br />
<div class="decal"><span class="sql">$glob_var = array('srv'=>'localhost','uid'=>'root','pwd'=>'xxx','db'=>'db_prod');<br />
$Db->Connect('glob_var');</span><br />
'glob_var' must be the name of a global variable beeing a PHP array with the keys described above.<br />
The global variable is <strong>destroyed</strong> just after the connection. </div>
<div class="versioning">Versioning: syntax2 is available since TbsSQL version 2.0</div>
<u>Note:</u> You don't need to call this method if your connection has already been opened before. In this case, you just have to assign the connection id to property ->Id. (example: $Db->Id = $mycn). You don't have to do this assignation when PHP can work automatically with the last opened connection. This is the case for MySQL for example.</td>
</tr>
<tr>
<td valign="top" class="split">$Db-><strong>Close</strong>()</td>
<td valign="top" class="split">Close the current connection to the database.</td>
</tr>
<tr>
<td valign="top" class="split">$Db-><strong>Execute</strong>($sql,...*...)</td>
<td valign="top" class="split">Execute the Sql statement.</td>
</tr>
<tr>
<td valign="top" class="split">$Db-><strong>GetVal</strong>($sql,...*...)</td>
<td valign="top" class="split">Returns the value of the first column in the first record of the query.<br />
If no record is returned by the query, then the function returns False.</td>
</tr>
<tr>
<td valign="top" class="split">$Db-><strong>GetRow</strong>($sql,...*...)</td>
<td valign="top" class="split">Returns an associative PHP array which is the first record returned by the query.</td>
</tr>
<tr>
<td valign="top" class="split">$Db-><strong>GetRows</strong>($sql,...*...)</td>
<td valign="top" class="split">Returns a PHP array of all records returned by the query.</td>
</tr>
<tr>
<td valign="top" class="split">$Db-><strong>GetList</strong>($sql,...*...)</td>
<td valign="top" class="split">Returns a PHP array with first column as keys and second column as values. If only one columns is given by the query then they the values of the array.<br />
<div class="decal"><u>Example:</u> $Db->GetList('SELECT id,name FROM t_people');<br />
will return something like: array(1=>'Peter', 2=>'Dave', 3=>'Jane' ,...)</div></td>
</tr>
<tr>
<td valign="top" class="split">$Db-><strong>GetSql</strong>($sql,...*...)</td>
<td valign="top" class="split">Returns the SQL statement with merged arguments.</td>
</tr>
<tr>
<td valign="top" class="split">$Db-><strong>LastRowId</strong>()</td>
<td valign="top" class="split">Returns the value of the identifier generated by the last INSERT query of your connection. </td>
</tr>
<tr>
<td valign="top" class="split">$Db-><strong>AffectedRows</strong>()</td>
<td valign="top" class="split">Returns the number of rows affected by the last UPDATE or DELETE query of your connection. </td>
</tr>
<tr>
<td valign="top" class="split">$Db-><strong>Id</strong></td>
<td valign="top" class="split">(read/write) The resource Id of your connection. </td>
</tr>
<tr>
<td valign="top" class="split">$Db-><strong>Mode</strong></td>
<td valign="top" class="split">(read/write) default value is 1.<br />
0: silent mode, no database error message is displayed. <br />
1: normal mode, the database error message is displayed when an error occurs. <br />
2: debug mode, the full SQL statement is also recalled when an error occurs.<br />
3: trace mode, all queries are displayed.</td>
</tr>
<tr>
<td valign="top"> </td>
<td valign="top"> </td>
</tr>
<tr>
<td colspan="2" valign="top">...*... means a variable number of arguments that will be merged in the SQL statement. </td>
</tr>
</table>
</div>
<br />
<span class="title1">• Deprecated </span><br />
<div class="decal">
<table width="100%" border="0" cellspacing="0" cellpadding="3">
<tr>
<td width="260" valign="top">$Db->Row1($sql,...*...)</td>
<td valign="top">Same as $Db->GetRow()</td>
</tr>
<tr>
<td valign="top">$Db->Rows($sql,...*...)</td>
<td valign="top">Same as $Db->GetRows()</td>
</tr>
<tr>
<td valign="top">$Db->Value($default,$sql,...*...)</td>
<td valign="top">Same as $Db->GetVal() but with a default value. </td>
</tr>
</table>
</div>
</body>
</html>