CakePHP
  • Documentation
    • Book
    • API
    • Videos
    • Reporting Security Issues
    • Privacy Policy
    • Logos & Trademarks
  • Business Solutions
  • Swag
  • Road Trip
  • Team
  • Community
    • Community
    • Get Involved
    • Issues (GitHub)
    • Bakery
    • Featured Resources
    • Training
    • Meetups
    • My CakePHP
    • CakeFest
    • Newsletter
    • Linkedin
    • YouTube
    • Facebook
    • Twitter
    • Mastodon
    • Help & Support
    • Forum
    • Stack Overflow
    • Slack
    • Paid Support
CakePHP

C CakePHP 1.2 API

  • Overview
  • Tree
  • Deprecated
  • Version:
    • 1.2
      • 4.2
      • 4.1
      • 4.0
      • 3.9
      • 3.8
      • 3.7
      • 3.6
      • 3.5
      • 3.4
      • 3.3
      • 3.2
      • 3.1
      • 3.0
      • 2.10
      • 2.9
      • 2.8
      • 2.7
      • 2.6
      • 2.5
      • 2.4
      • 2.3
      • 2.2
      • 2.1
      • 2.0
      • 1.3
      • 1.2

Classes

  • AclBase
  • AclBehavior
  • AclComponent
  • AclNode
  • AclShell
  • Aco
  • AcoAction
  • AjaxHelper
  • ApcEngine
  • ApiShell
  • App
  • AppController
  • AppHelper
  • AppModel
  • Aro
  • AuthComponent
  • BakeShell
  • BehaviorCollection
  • Cache
  • CacheEngine
  • CacheHelper
  • CakeErrorController
  • CakeLog
  • CakeSchema
  • CakeSession
  • CakeSocket
  • ClassRegistry
  • Component
  • Configure
  • ConnectionManager
  • ConsoleShell
  • ContainableBehavior
  • Controller
  • ControllerTask
  • CookieComponent
  • DataSource
  • DbAcl
  • DbAclSchema
  • DbConfigTask
  • DboAdodb
  • DboDb2
  • DboFirebird
  • DboMssql
  • DboMysql
  • DboMysqlBase
  • DboMysqli
  • DboOdbc
  • DboOracle
  • DboPostgres
  • DboSource
  • DboSqlite
  • DboSybase
  • Debugger
  • EmailComponent
  • ErrorHandler
  • ExtractTask
  • File
  • FileEngine
  • Flay
  • Folder
  • FormHelper
  • Helper
  • HtmlHelper
  • HttpSocket
  • I18n
  • I18nModel
  • i18nSchema
  • I18nShell
  • Inflector
  • IniAcl
  • JavascriptHelper
  • JsHelper
  • JsHelperObject
  • L10n
  • MagicDb
  • MagicFileResource
  • MediaView
  • MemcacheEngine
  • Model
  • ModelBehavior
  • ModelTask
  • Multibyte
  • NumberHelper
  • Object
  • Overloadable
  • Overloadable2
  • PagesController
  • PaginatorHelper
  • Permission
  • PluginTask
  • ProjectTask
  • RequestHandlerComponent
  • Router
  • RssHelper
  • Sanitize
  • Scaffold
  • ScaffoldView
  • SchemaShell
  • Security
  • SecurityComponent
  • SessionComponent
  • SessionHelper
  • SessionsSchema
  • Set
  • Shell
  • String
  • TestSuiteShell
  • TestTask
  • TextHelper
  • ThemeView
  • TimeHelper
  • TranslateBehavior
  • TreeBehavior
  • Validation
  • View
  • ViewTask
  • XcacheEngine
  • Xml
  • XmlElement
  • XmlHelper
  • XmlManager
  • XmlNode
  • XmlTextNode

Functions

  • __enclose
  • make_clean_css
  • mb_encode_mimeheader
  • mb_stripos
  • mb_stristr
  • mb_strlen
  • mb_strpos
  • mb_strrchr
  • mb_strrichr
  • mb_strripos
  • mb_strrpos
  • mb_strstr
  • mb_strtolower
  • mb_strtoupper
  • mb_substr
  • mb_substr_count
  • write_css_cache
  1: <?php
  2: /* SVN FILE: $Id$ */
  3: 
  4: /**
  5:  * ODBC for DBO
  6:  *
  7:  * Long description for file
  8:  *
  9:  * PHP versions 4 and 5
 10:  *
 11:  * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
 12:  * Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
 13:  *
 14:  * Licensed under The MIT License
 15:  * Redistributions of files must retain the above copyright notice.
 16:  *
 17:  * @copyright     Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
 18:  * @link          http://cakephp.org CakePHP(tm) Project
 19:  * @package       cake
 20:  * @subpackage    cake.cake.libs.model.dbo
 21:  * @since         CakePHP(tm) v 0.10.5.1790
 22:  * @version       $Revision$
 23:  * @modifiedby    $LastChangedBy$
 24:  * @lastmodified  $Date$
 25:  * @license       http://www.opensource.org/licenses/mit-license.php The MIT License
 26:  */
 27: 
 28: /**
 29:  * Short description for class.
 30:  *
 31:  * Long description for class
 32:  *
 33:  * @package       cake
 34:  * @subpackage    cake.cake.libs.model.datasources.dbo
 35:  */
 36: class DboOdbc extends DboSource {
 37: /**
 38:  * Driver description
 39:  *
 40:  * @var string
 41:  */
 42:     var $description = "ODBC DBO Driver";
 43: /**
 44:  * Table/column starting quote
 45:  *
 46:  * @var string
 47:  */
 48:     var $startQuote = "`";
 49: /**
 50:  * Table/column end quote
 51:  *
 52:  * @var string
 53:  */
 54:     var $endQuote = "`";
 55: /**
 56:  * Driver base configuration
 57:  *
 58:  * @var array
 59:  */
 60:     var $_baseConfig = array(
 61:         'persistent' => true,
 62:         'login' => 'root',
 63:         'password' => '',
 64:         'database' => 'cake',
 65:         'connect'  => 'odbc_pconnect'
 66:     );
 67: /**
 68:  * Enter description here...
 69:  *
 70:  * @var unknown_type
 71:  */
 72:     var $columns = array();
 73: 
 74:     //  var $columns = array('primary_key' => array('name' => 'int(11) DEFAULT NULL auto_increment'),
 75:     //                      'string' => array('name' => 'varchar', 'limit' => '255'),
 76:     //                      'text' => array('name' => 'text'),
 77:     //                      'integer' => array('name' => 'int', 'limit' => '11'),
 78:     //                      'float' => array('name' => 'float'),
 79:     //                      'datetime' => array('name' => 'datetime', 'format' => 'Y-m-d h:i:s', 'formatter' => 'date'),
 80:     //                      'timestamp' => array('name' => 'datetime', 'format' => 'Y-m-d h:i:s', 'formatter' => 'date'),
 81:     //                      'time' => array('name' => 'time', 'format' => 'h:i:s', 'formatter' => 'date'),
 82:     //                      'date' => array('name' => 'date', 'format' => 'Y-m-d', 'formatter' => 'date'),
 83:     //                      'binary' => array('name' => 'blob'),
 84:     //                      'boolean' => array('name' => 'tinyint', 'limit' => '1'));
 85: /**
 86:  * Connects to the database using options in the given configuration array.
 87:  *
 88:  * @return boolean True if the database could be connected, else false
 89:  */
 90:     function connect() {
 91:         $config = $this->config;
 92:         $connect = $config['connect'];
 93:         if (!$config['persistent']) {
 94:             $connect = 'odbc_connect';
 95:         }
 96:         if (!function_exists($connect)) {
 97:             exit('no odbc?');
 98:         }
 99:         $this->connected = false;
100:         $this->connection = $connect($config['database'], $config['login'], $config['password'],  SQL_CUR_USE_ODBC);
101:         if ($this->connection) {
102:             $this->connected = true;
103:         }
104: 
105:         return $this->connected;
106:     }
107: /**
108:  * Check if the ODBC extension is installed/loaded
109:  *
110:  * @return boolean
111:  **/
112:     function enabled() {
113:         return extension_loaded('odbc');
114:     }
115: /**
116:  * Disconnects from database.
117:  *
118:  * @return boolean True if the database could be disconnected, else false
119:  */
120:     function disconnect() {
121:         return @odbc_close($this->connection);
122:     }
123: /**
124:  * Executes given SQL statement.
125:  *
126:  * @param string $sql SQL statement
127:  * @return resource Result resource identifier
128:  * @access protected
129:  */
130:     function _execute($sql) {
131:         switch ($sql) {
132:             case 'BEGIN':
133:                 return odbc_autocommit($this->connection, false);
134:             case 'COMMIT':
135:                 return odbc_commit($this->connection);
136:             case 'ROLLBACK':
137:                 return odbc_rollback($this->connection);
138:         }
139:         // TODO: should flags be set? possible requirement:  SQL_CURSOR_STATIC
140:         return odbc_exec($this->connection, $sql);
141:     }
142: /**
143:  * Returns an array of sources (tables) in the database.
144:  *
145:  * @return array Array of tablenames in the database
146:  */
147:     function listSources() {
148:         $cache = parent::listSources();
149:         if ($cache != null) {
150:             return $cache;
151:         }
152: 
153:         $result = odbc_tables($this->connection);
154: 
155:         $tables = array();
156:         while (odbc_fetch_row($result)) {
157:             array_push($tables, odbc_result($result, 'TABLE_NAME'));
158:         }
159: 
160:         parent::listSources($tables);
161:         return $tables;
162:     }
163: /**
164:  * Returns an array of the fields in given table name.
165:  *
166:  * @param Model $model Model object to describe
167:  * @return array Fields in table. Keys are name and type
168:  */
169:     function &describe(&$model) {
170:         $cache=parent::describe($model);
171: 
172:         if ($cache != null) {
173:                 return $cache;
174:         }
175: 
176:         $fields = array();
177:         $sql = 'SELECT * FROM ' . $this->fullTableName($model);
178:         $result = odbc_exec($this->connection, $sql);
179: 
180:         $count = odbc_num_fields($result);
181: 
182:         for ($i = 1; $i <= $count; $i++) {
183:                 $cols[$i - 1] = odbc_field_name($result, $i);
184:         }
185: 
186:         foreach ($cols as $column) {
187:             $type = odbc_field_type(odbc_exec($this->connection, 'SELECT ' . $column . ' FROM ' . $this->fullTableName($model)), 1);
188:             $fields[$column] = array('type' => $type);
189:         }
190: 
191:         $this->__cacheDescription($model->tablePrefix . $model->table, $fields);
192:         return $fields;
193:     }
194: /**
195:  * Returns a quoted and escaped string of $data for use in an SQL statement.
196:  *
197:  * @param string $data String to be prepared for use in an SQL statement
198:  * @param string $column The column into which this data will be inserted
199:  * @return string Quoted and escaped
200:  * @todo Add logic that formats/escapes data based on column type
201:  */
202:     function value($data, $column = null) {
203:         $parent=parent::value($data, $column);
204: 
205:         if ($parent != null) {
206:                 return $parent;
207:         }
208: 
209:         if ($data === null) {
210:                 return 'NULL';
211:         }
212: 
213:         if (!is_numeric($data)) {
214:                 return "'" . $data . "'";
215:         }
216: 
217:         return $data;
218:     }
219: /**
220:  * Returns a formatted error message from previous database operation.
221:  *
222:  * @return string Error message with error number
223:  */
224:     function lastError() {
225:         if ($error = odbc_errormsg($this->connection)) {
226:             return odbc_error($this->connection) . ': ' . $error;
227:         }
228:         return null;
229:     }
230: /**
231:  * Returns number of affected rows in previous database operation. If no previous operation exists,
232:  * this returns false.
233:  *
234:  * @return integer Number of affected rows
235:  */
236:     function lastAffected() {
237:         if ($this->hasResult()) {
238:             return odbc_num_rows($this->_result);
239:         }
240:         return null;
241:     }
242: /**
243:  * Returns number of rows in previous resultset. If no previous resultset exists,
244:  * this returns false.
245:  *
246:  * @return int Number of rows in resultset
247:  */
248:     function lastNumRows() {
249:         if ($this->hasResult()) {
250:             return odbc_num_rows($this->_result);
251:         }
252:         return null;
253:     }
254: /**
255:  * Returns the ID generated from the previous INSERT operation.
256:  *
257:  * @param unknown_type $source
258:  * @return int
259:  */
260:     function lastInsertId($source = null) {
261:         $result = $this->fetchRow('SELECT @@IDENTITY');
262:         return $result[0];
263:     }
264: /**
265:  * Enter description here...
266:  *
267:  * @param string $real Real database-layer column type (i.e. "varchar(255)")
268:  */
269:     function column($real) {
270:         if (is_array($real)) {
271:             $col=$real['name'];
272:             if (isset($real['limit'])) {
273:                 $col .= '(' . $real['limit'] . ')';
274:             }
275:             return $col;
276:         }
277:         return $real;
278:     }
279: /**
280: * Enter description here...
281: *
282: * @param unknown_type $results
283: */
284:     function resultSet(&$results) {
285:         $this->results =& $results;
286:         $num_fields = odbc_num_fields($results);
287:         $this->map = array();
288:         $index = 0;
289:         $j = 0;
290:         while ($j < $num_fields) {
291:             $column = odbc_field_name($results, $j+1);
292: 
293:             if (strpos($column, '_dot_') !== false) {
294:                 list($table, $column) = explode('_dot_', $column);
295:                 $this->map[$index++] = array($table, $column);
296:             } else {
297:                 $this->map[$index++] = array(0, $column);
298:             }
299:             $j++;
300:         }
301:     }
302: /**
303: * Generates the fields list of an SQL query.
304: *
305: * @param Model $model
306: * @param string $alias Alias tablename
307: * @param mixed $fields
308: * @return array
309: */
310:     function fields(&$model, $alias = null, $fields = null, $quote = true) {
311:         if (empty($alias)) {
312:             $alias = $model->name;
313:         }
314:         if (!is_array($fields)) {
315:             if ($fields != null) {
316:                 $fields = array_map('trim', explode(',', $fields));
317:             } else {
318:                 foreach($model->tableToModel as $tableName => $modelName) {
319:                     foreach($this->__descriptions[$model->tablePrefix .$tableName] as $field => $type) {
320:                         $fields[] = $modelName .'.' .$field;
321:                     }
322:                 }
323:             }
324:         }
325: 
326:         $count = count($fields);
327: 
328:         if ($count >= 1 && $fields[0] != '*' && strpos($fields[0], 'COUNT(*)') === false) {
329:             for ($i = 0; $i < $count; $i++) {
330:                 if (!preg_match('/^.+\\(.*\\)/', $fields[$i])) {
331:                     $prepend = '';
332:                     if (strpos($fields[$i], 'DISTINCT') !== false) {
333:                         $prepend = 'DISTINCT ';
334:                         $fields[$i] = trim(str_replace('DISTINCT', '', $fields[$i]));
335:                     }
336: 
337:                     if (strrpos($fields[$i], '.') === false) {
338:                         $fields[$i] = $prepend . $this->name($alias) . '.' . $this->name($fields[$i]) . ' AS ' . $this->name($alias . '_dot_' . $fields[$i]);
339:                     } else {
340:                         $build = explode('.', $fields[$i]);
341:                         $fields[$i] = $prepend . $this->name($build[0]) . '.' . $this->name($build[1]) . ' AS ' . $this->name($build[0] . '_dot_' . $build[1]);
342:                     }
343:                 }
344:             }
345:         }
346:         return $fields;
347:     }
348: /**
349:  * Fetches the next row from the current result set
350:  *
351:  * @return unknown
352:  */
353:     function fetchResult() {
354:         if ($row = odbc_fetch_row($this->results)) {
355:             $resultRow = array();
356:             $numFields = odbc_num_fields($this->results);
357:             $i = 0;
358:             for($i = 0; $i < $numFields; $i++) {
359:                 list($table, $column) = $this->map[$i];
360:                 $resultRow[$table][$column] = odbc_result($this->results, $i + 1);
361:             }
362:             return $resultRow;
363:         }
364:         return false;
365:     }
366: }
367: ?>
OpenHub
Rackspace
Rackspace
  • Business Solutions
  • Showcase
  • Documentation
  • Book
  • API
  • Videos
  • Reporting Security Issues
  • Privacy Policy
  • Logos & Trademarks
  • Community
  • Get Involved
  • Issues (GitHub)
  • Bakery
  • Featured Resources
  • Training
  • Meetups
  • My CakePHP
  • CakeFest
  • Newsletter
  • Linkedin
  • YouTube
  • Facebook
  • Twitter
  • Mastodon
  • Help & Support
  • Forum
  • Stack Overflow
  • Slack
  • Paid Support

Generated using CakePHP API Docs