Welcome, Guest. Please login or register.
Did you miss your activation email?
Mar. 10, 2010, 07:34:28 PM
52761 Posts in 11725 Topics by 7891 Members
Latest Member: alenaomilina
News: PRADO 3.1.7 is released!
 
The PRADO Community » Prado v3.x » Component Repository » AdodbCache « previous next »
Pages: [1] Print
Author Topic: AdodbCache  (Read 3237 times)
FragMaster B
PRADO Supporter
Senior Member
*

Karma: 6
Offline Offline

Posts: 228



View Profile WWW
« on: Dec. 20, 2007, 04:26:39 PM »

There's been several implementations of TCache before. This is mine.

I'm still in love with Adodb and use it whenever I can for my database layer. A while ago I posted the Adodb module for Prado 3 that is basically a bootstrap for the wonderful adodb library by John Lim.

I've been wanting to get the benefits from TDbCache, but did not want a new database connection with PDO. So, I created AdodbCache. Works very similarly to TDbCache.

Hopefully somebody can get some use out of it. I'm amazed at the performance boost it has given my apps.

UPDATE (1/28/08): Now performs garbage collection as it should have all along. I updated the wiki. The change is a couple of lines in the "init" method.
UPDATE (5/19/08): Updated for compatibility with Prado 3.1.2. I updated the wiki.
« Last Edit: May. 19, 2008, 10:02:42 PM by FragMaster B » Logged
FragMaster B
PRADO Supporter
Senior Member
*

Karma: 6
Offline Offline

Posts: 228



View Profile WWW
« Reply #1 on: May. 04, 2008, 05:33:12 PM »

I just updated the code for the AdodbCache to incorporate a fix for the following bug: http://www.pradosoft.com/forum/index.php/topic,10101.0.html

I recommend you flush your PradoCache table after applying this fix.
Logged
domingo_eduardo_dg
Junior Member
**

Karma: 0
Offline Offline

Posts: 5


View Profile
« Reply #2 on: Nov. 05, 2008, 06:02:18 PM »

Hello FragMaster B
My English is very bad, but i try to writing jeje.
I made a little modification to the class ADODB for PRADO, of the tutorial http://www.pradosoft.com/wiki/index.php/ADOdb_module_tutorial
Code:
<?php
define
('ADODB_ASSOC_CASE'0); //Instructs ADOdb to always return lowercase field names. For Portability.
 
require_once('adodb/adodb-exceptions.inc.php');
require_once(
'adodb/adodb.inc.php');
 
/*
|-------------------------------------------------------------------------------------------------------------
| CLASS: adodb
|-------------------------------------------------------------------------------------------------------------
| DESCRIPTION: Makes adodb library available as a Prado module.
|-------------------------------------------------------------------------------------------------------------
| PROPERTY TYPE
|-------------------------------------------------------------------------------------------------------------
| -$db Obj. An instance of the adodb object (NewADOConnection).
| -$_Driver String. Connection type. For example: mysql; mssql, oci8, odbc.
| http://phplens.com/lens/adodb/docs-adodb.htm#DatabasesSupported
| -$_Host String. Host/server name/IP/etc.
| -$_Username String. Database username for authentication.
| -$_Password String. Database password for authentication.
| -$_Database String. Name of database to connect to.
| -$_Persistent = false Boolean. Persistent connection?
| -$_Dialect = 1                 Integer. SQL Dialect for Interbase Driver
|-------------------------------------------------------------------------------------------------------------
| METHOD DESCR/RETURN
|-------------------------------------------------------------------------------------------------------------
| +init($config) Prado method.
| +__call($method, $params) PHP Magic method. Passes calls made to this object into $db.
| +getDatabaseConnection() Instatiates a DB connection or returns the already open DB connection.
| +getDriver() Returns $_Driver.
| +setDriver($value) Sets $_Driver.
| +getHost() Returns $_Host.
| +setHost($value) Sets $_Host.
| +getUsername() Returns $_Username.
| +setUsername($value) Sets $_Username.
| +getPassword() Returns $_Password.
| +setPassword($value) Sets $_Password.
| +getDatabase() Returns $_Database.
| +setDatabase($value) Sets $_Database.
| +getPersistent() Returns $_Persistent.
| +setPersistent($value) Sets $_Persistent.
| +getDialect() Returns $_Dialect.
| +setDialect($value) Sets $_Dialect.
|-------------------------------------------------------------------------------------------------------------
*/
class adodb extends TModule{
private $db;
private $_Driver;
private $_Host;
private $_Username;
private $_Password;
private $_Database;
private $_Persistent false;
private $_Dialect=1;
 

public function init($config){
if (!$this->Driver){
throw new TConfigurationException('Missing param: Driver');
}
if (!$this->Host){
throw new TConfigurationException('Missing param: Host');
}
if (!$this->Username){
throw new TConfigurationException('Missing param: Username');
}
if (!$this->Password){
throw new TConfigurationException('Missing param: Password');        
}
if (!$this->Database){
throw new TConfigurationException('Missing param: Database');        
}
parent::init($config);
}

//PHP magic function.
//This method will pass all method calls to ADODB class/library.
public function __call($method$params){
$conn $this->getDatabaseConnection();
return call_user_func_array(array($conn$method), $params);
}

private function getDatabaseConnection(){
if (!isset($this->db)){
$this->db NewADOConnection($this->Driver);
$this->db->SetFetchMode(ADODB_FETCH_ASSOC);
if($this->Driver=='ibase')
{
$this->db->dialect=$this->Dialect;
}

if ($this->Persistent){
//For more see: http://phplens.com/lens/adodb/docs-adodb.htm#pconnect
$this->db->PConnect($this->Host$this->Username$this->Password$this->Database);
}
else{
//For more see: http://phplens.com/lens/adodb/docs-adodb.htm#connect
$this->db->Connect($this->Host$this->Username$this->Password$this->Database);
}

}
return $this->db;
}

//Getter and setters for params.
public function getDriver(){
return $this->_Driver;
}
public function setDriver($value){
$this->_Driver TPropertyValue::ensureString($value);
}
public function getHost(){
return $this->_Host;
}
public function setHost($value){
$this->_Host TPropertyValue::ensureString($value);
}
public function getUsername(){
return $this->_Username;
}
public function setUsername($value){
$this->_Username TPropertyValue::ensureString($value);
}
public function getPassword(){
return $this->_Password;
}
public function setPassword($value){
$this->_Password TPropertyValue::ensureString($value);
}
public function getDatabase(){
return $this->_Database;
}
public function setDatabase($value){
$this->_Database TPropertyValue::ensureString($value);
}
public function getPersistent(){
return $this->_Persistent;
}
public function setPersistent($value){
$this->_Persistent TPropertyValue::ensureBoolean($value);
}
       public function 
getDialect(){
return $this->_Dialect;
}
public function setDialect($value){
$this->_Dialect TPropertyValue::ensureInteger($value);
}
}
?>


I add the property dialect for Interbase driver, because it has support for the data types on the date, dialect = 3.

You could use:
Code:
<?xml version="1.0" encoding="iso-8859-1"?>
<application id="myAppId" Mode="Debug">
<paths>
<using namespace="Application.modules.*" />
...
</paths>

<modules>
<module id="adodb" class="adodb"
Driver="ibase" Host="localhost" Username="usernamehere" Password="passwordhere" Database="databasenamehere" Dialect="3" />
</modules>
 
        ...
</application>
             

Can be implemented in the following manner without the need to declare in Application.xml, remaining as follows:

Code:
<?php
class home extends TPage{
public function onLoad($param){
$db $this->Application->getModule('adodb');
                
$db->Dialect=3;
$sql 'SELECT email FROM user WHERE user_id=1';
echo $db->GetOne($sql);
}
}
?>



One could continue adding more features to the class, for example: a function to close the connection, etc.

It is a small contribution for those who manage Interbase, I hope to be able to help them.

Greetings

« Last Edit: Nov. 05, 2008, 07:28:52 PM by domingo_eduardo_dg » Logged
rojaro
Global Moderator
Platinum Member
****

Karma: 36
Offline Offline

Posts: 627


PRADO aint no voodoo ...


View Profile WWW
« Reply #3 on: Nov. 05, 2008, 06:20:46 PM »

English please !
Logged

A mathematician is a machine for turning coffee into theorems. ~ Alfred Renyi (*1921 - †1970)
domingo_eduardo_dg
Junior Member
**

Karma: 0
Offline Offline

Posts: 5


View Profile
« Reply #4 on: Nov. 05, 2008, 07:23:24 PM »

Ok, My English is very bad, but i try to writing jeje. I changed the message to English.

Logged
rojaro
Global Moderator
Platinum Member
****

Karma: 36
Offline Offline

Posts: 627


PRADO aint no voodoo ...


View Profile WWW
« Reply #5 on: Nov. 05, 2008, 08:14:02 PM »

Thanks a lot ^^

Greetings from Hamburg / Germany
- rojaro -
Logged

A mathematician is a machine for turning coffee into theorems. ~ Alfred Renyi (*1921 - †1970)
Pages: [1] Print 
« previous next »
Jump to: