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:  * Sybase layer for DBO
  5:  *
  6:  * Long description for file
  7:  *
  8:  * PHP versions 4 and 5
  9:  *
 10:  * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
 11:  * Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
 12:  *
 13:  * Licensed under The MIT License
 14:  * Redistributions of files must retain the above copyright notice.
 15:  *
 16:  * @copyright     Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
 17:  * @link          http://cakephp.org CakePHP(tm) Project
 18:  * @package       cake
 19:  * @subpackage    cake.cake.libs.model.datasources.dbo
 20:  * @since         CakePHP(tm) v 1.2.0.3097
 21:  * @version       $Revision$
 22:  * @modifiedby    $LastChangedBy$
 23:  * @lastmodified  $Date$
 24:  * @license       http://www.opensource.org/licenses/mit-license.php The MIT License
 25:  */
 26: /**
 27:  * Short description for class.
 28:  *
 29:  * Long description for class
 30:  *
 31:  * @package       cake
 32:  * @subpackage    cake.cake.libs.model.datasources.dbo
 33:  */
 34: class DboSybase extends DboSource {
 35: /**
 36:  * Driver description
 37:  *
 38:  * @var string
 39:  */
 40:     var $description = "Sybase DBO Driver";
 41: /**
 42:  * Start quote for quoted identifiers
 43:  *
 44:  * @var string
 45:  */
 46:     var $startQuote = "";
 47: /**
 48:  * End quote for quoted identifiers
 49:  *
 50:  * @var string
 51:  */
 52:     var $endQuote = "";
 53: /**
 54:  * Base configuration settings for Sybase driver
 55:  *
 56:  * @var array
 57:  */
 58:     var $_baseConfig = array(
 59:         'persistent' => true,
 60:         'host' => 'localhost',
 61:         'login' => 'sa',
 62:         'password' => '',
 63:         'database' => 'cake',
 64:         'port' => '4100'
 65:     );
 66: /**
 67:  * Sybase column definition
 68:  *
 69:  * @var array
 70:  */
 71:     var $columns = array(
 72:         'primary_key' => array('name' => 'numeric(9,0) IDENTITY PRIMARY KEY'),
 73:         'string' => array('name' => 'varchar', 'limit' => '255'),
 74:         'text' => array('name' => 'text'),
 75:         'integer' => array('name' => 'int', 'limit' => '11', 'formatter' => 'intval'),
 76:         'float' => array('name' => 'float', 'formatter' => 'floatval'),
 77:         'datetime' => array('name' => 'datetime', 'format' => 'Y-m-d H:i:s', 'formatter' => 'date'),
 78:         'timestamp' => array('name' => 'timestamp', 'format' => 'Y-m-d H:i:s', 'formatter' => 'date'),
 79:         'time' => array('name' => 'datetime', 'format' => 'H:i:s', 'formatter' => 'date'),
 80:         'date' => array('name' => 'datetime', 'format' => 'Y-m-d', 'formatter' => 'date'),
 81:         'binary' => array('name' => 'image'),
 82:         'boolean' => array('name' => 'bit')
 83:     );
 84: /**
 85:  * Connects to the database using options in the given configuration array.
 86:  *
 87:  * @return boolean True if the database could be connected, else false
 88:  */
 89:     function connect() {
 90:         $config = $this->config;
 91: 
 92:         $port = '';
 93:         if ($config['port'] !== null) {
 94:             $port = ':' . $config['port'];
 95:         }
 96:         if ($config['persistent']) {
 97:             $this->connection = sybase_pconnect($config['host'] . $port, $config['login'], $config['password']);
 98:         } else {
 99:             $this->connection = sybase_connect($config['host'] . $port, $config['login'], $config['password'], true);
100:         }
101:         $this->connected = sybase_select_db($config['database'], $this->connection);
102:         return $this->connected;
103:     }
104: /**
105:  * Check that one of the sybase extensions is installed
106:  *
107:  * @return boolean
108:  **/
109:     function enabled() {
110:         return extension_loaded('sybase') || extension_loaded('sybase_ct');
111:     }
112: /**
113:  * Disconnects from database.
114:  *
115:  * @return boolean True if the database could be disconnected, else false
116:  */
117:     function disconnect() {
118:         $this->connected = !@sybase_close($this->connection);
119:         return !$this->connected;
120:     }
121: /**
122:  * Executes given SQL statement.
123:  *
124:  * @param string $sql SQL statement
125:  * @return resource Result resource identifier
126:  * @access protected
127:  */
128:     function _execute($sql) {
129:         return sybase_query($sql, $this->connection);
130:     }
131: /**
132:  * Returns an array of sources (tables) in the database.
133:  *
134:  * @return array Array of tablenames in the database
135:  */
136:     function listSources() {
137:         $cache = parent::listSources();
138:         if ($cache != null) {
139:             return $cache;
140:         }
141: 
142:         $result = $this->_execute("SELECT name FROM sysobjects WHERE type IN ('U', 'V')");
143:         if (!$result) {
144:             return array();
145:         } else {
146: 
147:             $tables = array();
148:             while ($line = sybase_fetch_array($result)) {
149:                 $tables[] = $line[0];
150:             }
151: 
152:             parent::listSources($tables);
153:             return $tables;
154:         }
155:     }
156: /**
157:  * Returns an array of the fields in given table name.
158:  *
159:  * @param string $tableName Name of database table to inspect
160:  * @return array Fields in table. Keys are name and type
161:  */
162:     function describe(&$model) {
163: 
164:         $cache = parent::describe($model);
165:         if ($cache != null) {
166:             return $cache;
167:         }
168: 
169:         $fields = false;
170:         $cols = $this->query('DESC ' . $this->fullTableName($model));
171: 
172:         foreach ($cols as $column) {
173:             $colKey = array_keys($column);
174:             if (isset($column[$colKey[0]]) && !isset($column[0])) {
175:                 $column[0] = $column[$colKey[0]];
176:             }
177:             if (isset($column[0])) {
178:                 $fields[$column[0]['Field']] = array(
179:                     'type' => $this->column($column[0]['Type']),
180:                     'null' => $column[0]['Null'],
181:                     'length' => $this->length($column[0]['Type']),
182:                 );
183:             }
184:         }
185: 
186:         $this->__cacheDescription($model->tablePrefix.$model->table, $fields);
187:         return $fields;
188:     }
189: /**
190:  * Returns a quoted and escaped string of $data for use in an SQL statement.
191:  *
192:  * @param string $data String to be prepared for use in an SQL statement
193:  * @param string $column The column into which this data will be inserted
194:  * @param boolean $safe Whether or not numeric data should be handled automagically if no column data is provided
195:  * @return string Quoted and escaped data
196:  */
197:     function value($data, $column = null, $safe = false) {
198:         $parent = parent::value($data, $column, $safe);
199: 
200:         if ($parent != null) {
201:             return $parent;
202:         }
203: 
204:         if ($data === null) {
205:             return 'NULL';
206:         }
207: 
208:         if ($data === '') {
209:             return  "''";
210:         }
211: 
212:         switch ($column) {
213:             case 'boolean':
214:                 $data = $this->boolean((bool)$data);
215:             break;
216:             default:
217:                 $data = str_replace("'", "''", $data);
218:             break;
219:         }
220: 
221:         return "'" . $data . "'";
222:     }
223: /**
224:  * Begin a transaction
225:  *
226:  * @param unknown_type $model
227:  * @return boolean True on success, false on fail
228:  * (i.e. if the database/model does not support transactions).
229:  */
230:     function begin(&$model) {
231:         if (parent::begin($model)) {
232:             if ($this->execute('BEGIN TRAN')) {
233:                 $this->_transactionStarted = true;
234:                 return true;
235:             }
236:         }
237:         return false;
238:     }
239: /**
240:  * Commit a transaction
241:  *
242:  * @param unknown_type $model
243:  * @return boolean True on success, false on fail
244:  * (i.e. if the database/model does not support transactions,
245:  * or a transaction has not started).
246:  */
247:     function commit(&$model) {
248:         if (parent::commit($model)) {
249:             $this->_transactionStarted = false;
250:             return $this->execute('COMMIT TRAN');
251:         }
252:         return false;
253:     }
254: /**
255:  * Rollback a transaction
256:  *
257:  * @param unknown_type $model
258:  * @return boolean True on success, false on fail
259:  * (i.e. if the database/model does not support transactions,
260:  * or a transaction has not started).
261:  */
262:     function rollback(&$model) {
263:         if (parent::rollback($model)) {
264:             return $this->execute('ROLLBACK TRAN');
265:         }
266:         return false;
267:     }
268: /**
269:  * Returns a formatted error message from previous database operation.
270:  *
271:  * @todo not implemented
272:  * @return string Error message with error number
273:  */
274:     function lastError() {
275:         return null;
276:     }
277: /**
278:  * Returns number of affected rows in previous database operation. If no previous operation exists,
279:  * this returns false.
280:  *
281:  * @return integer Number of affected rows
282:  */
283:     function lastAffected() {
284:         if ($this->_result) {
285:             return sybase_affected_rows($this->connection);
286:         }
287:         return null;
288:     }
289: /**
290:  * Returns number of rows in previous resultset. If no previous resultset exists,
291:  * this returns false.
292:  *
293:  * @return integer Number of rows in resultset
294:  */
295:     function lastNumRows() {
296:         if ($this->hasResult()) {
297:             return @sybase_num_rows($this->_result);
298:         }
299:         return null;
300:     }
301: /**
302:  * Returns the ID generated from the previous INSERT operation.
303:  *
304:  * @param unknown_type $source
305:  * @return in
306:  */
307:     function lastInsertId($source = null) {
308:         $result=$this->fetchRow('SELECT @@IDENTITY');
309:         return $result[0];
310:     }
311: /**
312:  * Converts database-layer column types to basic types
313:  *
314:  * @param string $real Real database-layer column type (i.e. "varchar(255)")
315:  * @return string Abstract column type (i.e. "string")
316:  */
317:     function column($real) {
318:         if (is_array($real)) {
319:             $col = $real['name'];
320:             if (isset($real['limit']))
321:             {
322:                 $col .= '('.$real['limit'].')';
323:             }
324:             return $col;
325:         }
326: 
327:         $col = str_replace(')', '', $real);
328:         $limit = null;
329:         if (strpos($col, '(') !== false) {
330:             list($col, $limit) = explode('(', $col);
331:         }
332: 
333:         if (in_array($col, array('datetime', 'smalldatetime'))) {
334:             return 'datetime';
335:         } elseif (in_array($col, array('int', 'bigint', 'smallint', 'tinyint'))) {
336:             return 'integer';
337:         } elseif (in_array($col, array('float', 'double', 'real', 'decimal', 'money', 'numeric', 'smallmoney'))) {
338:             return 'float';
339:         } elseif (strpos($col, 'text') !== false) {
340:             return 'text';
341:         } elseif (in_array($col, array('char', 'nchar', 'nvarchar', 'string', 'varchar'))) {
342:             return 'binary';
343:         } elseif (in_array($col, array('binary', 'image', 'varbinary'))) {
344:             return 'binary';
345:         }
346: 
347:         return 'text';
348:     }
349: /**
350:  * Enter description here...
351:  *
352:  * @param unknown_type $results
353:  */
354:     function resultSet(&$results) {
355:         $this->results =& $results;
356:         $this->map = array();
357:         $num_fields = sybase_num_fields($results);
358:         $index = 0;
359:         $j = 0;
360: 
361:         while ($j < $num_fields) {
362: 
363:             $column = sybase_fetch_field($results,$j);
364:             if (!empty($column->table)) {
365:                 $this->map[$index++] = array($column->table, $column->name);
366:             } else {
367:                 $this->map[$index++] = array(0, $column->name);
368:             }
369:             $j++;
370:         }
371:     }
372: /**
373:  * Fetches the next row from the current result set
374:  *
375:  * @return unknown
376:  */
377:     function fetchResult() {
378:         if ($row = sybase_fetch_row($this->results)) {
379:             $resultRow = array();
380:             $i = 0;
381:             foreach ($row as $index => $field) {
382:                 list($table, $column) = $this->map[$index];
383:                 $resultRow[$table][$column] = $row[$index];
384:                 $i++;
385:             }
386:             return $resultRow;
387:         } else {
388:             return false;
389:         }
390:     }
391: }
392: ?>
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