PHP Classes

how to use

Recommend this page to a friend!

      PHP 5 Namespace database cache class  >  All threads  >  how to use  >  (Un) Subscribe thread alerts  
Subject:how to use
Summary:i don't found an example
Messages:2
Author:Thompson Moreira
Date:2013-03-28 21:57:20
Update:2013-04-08 10:01:24
 

  1. how to use   Reply   Report abuse  
Picture of Thompson Moreira Thompson Moreira - 2013-03-28 21:57:20
Hello,

i tryed understand this package, but i can't because two kinds: the comments language is not in english and you don't post an example of how to use. Can you add a example file?

  2. Re: how to use   Reply   Report abuse  
Picture of mehmet samli mehmet samli - 2013-04-08 10:01:24 - In reply to message 1 from Thompson Moreira
<?php
use model\cache\Timeout;

use model\db\DBResult;

use model\db\DB;
$DB = DB::getInstance();
# insert method
#########################################################
$sql = 'INSERT INTO test (a,b,c) VALUES (?,?,?)';
$paramArr = array(
(int) "22",
(string) "aa",
(double) 44.33
);
$DB->startTransaction();
try{
$DB->insert($sql, $paramArr);
$DB->commit();
echo "auto Increment or sequence ID : ".$DB->last_id();
}catch (PDOException $error){
$DB->rollback();
trigger_error($error->getMessage(),E_USER_ERROR);
}
#########################################################

# update method
#########################################################
$sql = 'UPDATE test SET a=? WHERE id=?';
$paramArr = array('xxxx',22);
$DB->startTransaction();
try{
$DB->update($sql, $paramArr);
$DB->commit();
}catch (PDOException $error){
$DB->rollback();
trigger_error($error->getMessage(),E_USER_ERROR);
}
#########################################################

# delete method
#########################################################
$sql = 'DELETE FROM test WHERE id=?';
$paramArr = array(22);
$DB->startTransaction();
try{
$DB->delete($sql, $paramArr);
$DB->commit();
}catch (PDOException $error){
$DB->rollback();
trigger_error($error->getMessage(),E_USER_ERROR);
}
#########################################################

# select method
#########################################################
$sql = 'SELECT a,b,c FROM test WHERE id > ?';
$result = new DBResult();
$DB->select($result,$sql, array(1));
echo '<table>
<tr>
<td>A</td>
<td>B</td>
<td>C</td>
</tr>
';

for($i=0;$i<$result->num_rows;$i++){
echo '<tr>
<td>'.$result->dataArr[$i]['a'].'</td>
<td>'.$result->dataArr[$i]['b'].'</td>
<td>'.$result->dataArr[$i]['c'].'</td>
</tr>';
}
echo '<table>';

# select + memcached method
$sql = 'SELECT a,b,c FROM test WHERE id > ?';
$result = new DBResult();
$DB->select($result,$sql, array(1),Timeout::get(1, Timeout::MINUTE));
echo '<table>
<tr>
<td>A</td>
<td>B</td>
<td>C</td>
</tr>
';

for($i=0;$i<$result->num_rows;$i++){
echo '<tr>
<td>'.$result->dataArr[$i]['a'].'</td>
<td>'.$result->dataArr[$i]['b'].'</td>
<td>'.$result->dataArr[$i]['c'].'</td>
</tr>';
}
echo '<table>';