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 <?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:
<?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:
<?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