Overview

Namespaces

  • None
  • RedBeanPHP
    • Adapter
    • BeanHelper
    • Cursor
    • Driver
    • Logger
      • RDefault
    • QueryWriter
    • RedException
    • Repository
    • Util

Classes

  • R
  • RedBean_SimpleModel
  • RedBeanPHP\Adapter\DBAdapter
  • RedBeanPHP\AssociationManager
  • RedBeanPHP\BeanCollection
  • RedBeanPHP\BeanHelper\SimpleFacadeBeanHelper
  • RedBeanPHP\Cursor\NullCursor
  • RedBeanPHP\Cursor\PDOCursor
  • RedBeanPHP\Driver\RPDO
  • RedBeanPHP\DuplicationManager
  • RedBeanPHP\Facade
  • RedBeanPHP\Finder
  • RedBeanPHP\Jsonable
  • RedBeanPHP\LabelMaker
  • RedBeanPHP\Logger\RDefault
  • RedBeanPHP\Logger\RDefault\Debug
  • RedBeanPHP\Observable
  • RedBeanPHP\OODB
  • RedBeanPHP\OODBBean
  • RedBeanPHP\QueryWriter\AQueryWriter
  • RedBeanPHP\QueryWriter\CUBRID
  • RedBeanPHP\QueryWriter\MySQL
  • RedBeanPHP\QueryWriter\PostgreSQL
  • RedBeanPHP\QueryWriter\SQLiteT
  • RedBeanPHP\R
  • RedBeanPHP\Repository
  • RedBeanPHP\Repository\Fluid
  • RedBeanPHP\Repository\Frozen
  • RedBeanPHP\SimpleModel
  • RedBeanPHP\SimpleModelHelper
  • RedBeanPHP\TagManager
  • RedBeanPHP\ToolBox
  • RedBeanPHP\Util\ArrayTool
  • RedBeanPHP\Util\DispenseHelper
  • RedBeanPHP\Util\Dump
  • RedBeanPHP\Util\MultiLoader
  • RedBeanPHP\Util\Transaction

Interfaces

  • RedBeanPHP\Adapter
  • RedBeanPHP\BeanHelper
  • RedBeanPHP\Cursor
  • RedBeanPHP\Driver
  • RedBeanPHP\Logger
  • RedBeanPHP\Observer
  • RedBeanPHP\Plugin
  • RedBeanPHP\QueryWriter

Exceptions

  • RedBeanPHP\RedException
  • RedBeanPHP\RedException\SQL

Functions

  • array_flatten
  • dmp
  • EID
  • genslots
  • Overview
  • Namespace
  • Class
  1: <?php
  2: 
  3: namespace RedBeanPHP\Adapter;
  4: 
  5: use RedBeanPHP\Observable as Observable;
  6: use RedBeanPHP\Adapter as Adapter;
  7: use RedBeanPHP\Driver as Driver;
  8: 
  9: /**
 10:  * DBAdapter (Database Adapter)
 11:  *
 12:  * An adapter class to connect various database systems to RedBean
 13:  * Database Adapter Class. The task of the database adapter class is to
 14:  * communicate with the database driver. You can use all sorts of database
 15:  * drivers with RedBeanPHP. The default database drivers that ships with
 16:  * the RedBeanPHP library is the RPDO driver ( which uses the PHP Data Objects
 17:  * Architecture aka PDO ).
 18:  *
 19:  * @file    RedBeanPHP/Adapter/DBAdapter.php
 20:  * @author  Gabor de Mooij and the RedBeanPHP Community.
 21:  * @license BSD/GPLv2
 22:  *
 23:  * @copyright
 24:  * (c) copyright G.J.G.T. (Gabor) de Mooij and the RedBeanPHP community.
 25:  * This source file is subject to the BSD/GPLv2 License that is bundled
 26:  * with this source code in the file license.txt.
 27:  */
 28: class DBAdapter extends Observable implements Adapter
 29: {
 30:     /**
 31:      * @var Driver
 32:      */
 33:     private $db = NULL;
 34: 
 35:     /**
 36:      * @var string
 37:      */
 38:     private $sql = '';
 39: 
 40:     /**
 41:      * Constructor.
 42:      *
 43:      * Creates an instance of the RedBean Adapter Class.
 44:      * This class provides an interface for RedBean to work
 45:      * with ADO compatible DB instances.
 46:      *
 47:      * @param Driver $database ADO Compatible DB Instance
 48:      */
 49:     public function __construct( $database )
 50:     {
 51:         $this->db = $database;
 52:     }
 53: 
 54:     /**
 55:      * @see Adapter::getSQL
 56:      */
 57:     public function getSQL()
 58:     {
 59:         return $this->sql;
 60:     }
 61: 
 62:     /**
 63:      * @see Adapter::exec
 64:      */
 65:     public function exec( $sql, $bindings = array(), $noevent = FALSE )
 66:     {
 67:         if ( !$noevent ) {
 68:             $this->sql = $sql;
 69:             $this->signal( 'sql_exec', $this );
 70:         }
 71: 
 72:         return $this->db->Execute( $sql, $bindings );
 73:     }
 74: 
 75:     /**
 76:      * @see Adapter::get
 77:      */
 78:     public function get( $sql, $bindings = array() )
 79:     {
 80:         $this->sql = $sql;
 81:         $this->signal( 'sql_exec', $this );
 82: 
 83:         return $this->db->GetAll( $sql, $bindings );
 84:     }
 85: 
 86:     /**
 87:      * @see Adapter::getRow
 88:      */
 89:     public function getRow( $sql, $bindings = array() )
 90:     {
 91:         $this->sql = $sql;
 92:         $this->signal( 'sql_exec', $this );
 93: 
 94:         return $this->db->GetRow( $sql, $bindings );
 95:     }
 96: 
 97:     /**
 98:      * @see Adapter::getCol
 99:      */
100:     public function getCol( $sql, $bindings = array() )
101:     {
102:         $this->sql = $sql;
103:         $this->signal( 'sql_exec', $this );
104: 
105:         return $this->db->GetCol( $sql, $bindings );
106:     }
107: 
108:     /**
109:      * @see Adapter::getAssoc
110:      */
111:     public function getAssoc( $sql, $bindings = array() )
112:     {
113:         $this->sql = $sql;
114: 
115:         $this->signal( 'sql_exec', $this );
116: 
117:         $rows  = $this->db->GetAll( $sql, $bindings );
118: 
119:         $assoc = array();
120:         if ( !$rows ) {
121:             return $assoc;
122:         }
123: 
124:         foreach ( $rows as $row ) {
125:             if ( empty( $row ) ) continue;
126: 
127:             if ( count( $row ) > 2 ) {
128:             $key   = array_shift( $row );
129:             $value = $row;
130:         } elseif ( count( $row ) > 1 ) {
131:                 $key   = array_shift( $row );
132:                 $value = array_shift( $row );
133:             } else {
134:                 $key   = array_shift( $row );
135:                 $value = $key;
136:             }
137: 
138:             $assoc[$key] = $value;
139:         }
140: 
141:         return $assoc;
142:     }
143: 
144:     /**
145:      * @see Adapter::getAssocRow
146:      */
147:     public function getAssocRow($sql, $bindings = array())
148:     {
149:         $this->sql = $sql;
150:         $this->signal( 'sql_exec', $this );
151: 
152:         return $this->db->GetAssocRow( $sql, $bindings );
153:     }
154: 
155:     /**
156:      * @see Adapter::getCell
157:      */
158:     public function getCell( $sql, $bindings = array(), $noSignal = NULL )
159:     {
160:         $this->sql = $sql;
161: 
162:         if ( !$noSignal ) $this->signal( 'sql_exec', $this );
163: 
164:         return $this->db->GetOne( $sql, $bindings );
165:     }
166: 
167:     /**
168:      * @see Adapter::getCursor
169:      */
170:     public function getCursor( $sql, $bindings = array() )
171:     {
172:         return $this->db->GetCursor( $sql, $bindings );
173:     }
174: 
175:     /**
176:      * @see Adapter::getInsertID
177:      */
178:     public function getInsertID()
179:     {
180:         return $this->db->getInsertID();
181:     }
182: 
183:     /**
184:      * @see Adapter::getAffectedRows
185:      */
186:     public function getAffectedRows()
187:     {
188:         return $this->db->Affected_Rows();
189:     }
190: 
191:     /**
192:      * @see Adapter::getDatabase
193:      */
194:     public function getDatabase()
195:     {
196:         return $this->db;
197:     }
198: 
199:     /**
200:      * @see Adapter::startTransaction
201:      */
202:     public function startTransaction()
203:     {
204:         $this->db->StartTrans();
205:     }
206: 
207:     /**
208:      * @see Adapter::commit
209:      */
210:     public function commit()
211:     {
212:         $this->db->CommitTrans();
213:     }
214: 
215:     /**
216:      * @see Adapter::rollback
217:      */
218:     public function rollback()
219:     {
220:         $this->db->FailTrans();
221:     }
222: 
223:     /**
224:      * @see Adapter::close.
225:      */
226:     public function close()
227:     {
228:         $this->db->close();
229:     }
230: }
231: 
API documentation generated by ApiGen