summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJonathon Hill <jhill@brandmovers.com>2012-11-12 14:51:41 +0100
committerJonathon Hill <jhill@brandmovers.com>2012-11-12 14:51:41 +0100
commit3978fc33d82dd7f778d1adbf30744f4dfac41c25 (patch)
treef32be1ae610f0cfeff65c35abecd14e8ea5cadc6
parent275cf274860c6ed181d50b398efd3a21d7ba9135 (diff)
parenta9ab46d7a031bda304eb9b6658ffaf693b8d9bcb (diff)
Merge remote-tracking branch 'upstream/develop' into develop
Conflicts: user_guide_src/source/changelog.rst Signed-off-by: Jonathon Hill <jhill@brandmovers.com>
-rw-r--r--application/config/config.php10
-rw-r--r--application/config/foreign_chars.php80
-rw-r--r--application/controllers/welcome.php3
-rw-r--r--application/views/errors/error_404.php3
-rw-r--r--application/views/errors/error_db.php3
-rw-r--r--application/views/errors/error_general.php3
-rw-r--r--application/views/errors/error_php.php3
-rw-r--r--application/views/welcome_message.php3
-rw-r--r--contributing.md2
-rw-r--r--system/core/Benchmark.php3
-rw-r--r--system/core/CodeIgniter.php96
-rw-r--r--system/core/Common.php52
-rw-r--r--system/core/Config.php3
-rw-r--r--system/core/Controller.php3
-rw-r--r--system/core/Exceptions.php3
-rw-r--r--system/core/Hooks.php3
-rw-r--r--system/core/Input.php54
-rw-r--r--system/core/Lang.php3
-rw-r--r--system/core/Loader.php111
-rw-r--r--system/core/Log.php (renamed from system/libraries/Log.php)5
-rw-r--r--system/core/Model.php3
-rw-r--r--system/core/Output.php3
-rw-r--r--system/core/Router.php144
-rw-r--r--system/core/Security.php3
-rw-r--r--system/core/URI.php128
-rw-r--r--system/core/Utf8.php3
-rw-r--r--system/database/DB.php46
-rw-r--r--system/database/DB_cache.php31
-rw-r--r--system/database/DB_driver.php312
-rw-r--r--system/database/DB_forge.php706
-rw-r--r--system/database/DB_query_builder.php486
-rw-r--r--system/database/DB_result.php203
-rw-r--r--system/database/DB_utility.php77
-rw-r--r--system/database/drivers/cubrid/cubrid_driver.php67
-rw-r--r--system/database/drivers/cubrid/cubrid_forge.php253
-rw-r--r--system/database/drivers/cubrid/cubrid_result.php9
-rw-r--r--system/database/drivers/cubrid/cubrid_utility.php5
-rw-r--r--system/database/drivers/ibase/ibase_driver.php62
-rw-r--r--system/database/drivers/ibase/ibase_forge.php214
-rw-r--r--system/database/drivers/ibase/ibase_result.php5
-rw-r--r--system/database/drivers/ibase/ibase_utility.php7
-rw-r--r--system/database/drivers/mssql/mssql_driver.php84
-rw-r--r--system/database/drivers/mssql/mssql_forge.php164
-rw-r--r--system/database/drivers/mssql/mssql_result.php9
-rw-r--r--system/database/drivers/mssql/mssql_utility.php20
-rw-r--r--system/database/drivers/mysql/mysql_driver.php84
-rw-r--r--system/database/drivers/mysql/mysql_forge.php231
-rw-r--r--system/database/drivers/mysql/mysql_result.php13
-rw-r--r--system/database/drivers/mysql/mysql_utility.php26
-rw-r--r--system/database/drivers/mysqli/mysqli_driver.php77
-rw-r--r--system/database/drivers/mysqli/mysqli_forge.php231
-rw-r--r--system/database/drivers/mysqli/mysqli_result.php9
-rw-r--r--system/database/drivers/mysqli/mysqli_utility.php26
-rw-r--r--system/database/drivers/oci8/oci8_driver.php131
-rw-r--r--system/database/drivers/oci8/oci8_forge.php151
-rw-r--r--system/database/drivers/oci8/oci8_result.php37
-rw-r--r--system/database/drivers/oci8/oci8_utility.php14
-rw-r--r--system/database/drivers/odbc/odbc_driver.php61
-rw-r--r--system/database/drivers/odbc/odbc_forge.php130
-rw-r--r--system/database/drivers/odbc/odbc_result.php17
-rw-r--r--system/database/drivers/odbc/odbc_utility.php11
-rw-r--r--system/database/drivers/pdo/pdo_driver.php62
-rw-r--r--system/database/drivers/pdo/pdo_forge.php129
-rw-r--r--system/database/drivers/pdo/pdo_result.php7
-rw-r--r--system/database/drivers/pdo/pdo_utility.php11
-rw-r--r--system/database/drivers/pdo/subdrivers/pdo_4d_driver.php36
-rw-r--r--system/database/drivers/pdo/subdrivers/pdo_4d_forge.php209
-rw-r--r--system/database/drivers/pdo/subdrivers/pdo_cubrid_driver.php35
-rw-r--r--system/database/drivers/pdo/subdrivers/pdo_cubrid_forge.php212
-rw-r--r--system/database/drivers/pdo/subdrivers/pdo_dblib_driver.php70
-rw-r--r--system/database/drivers/pdo/subdrivers/pdo_dblib_forge.php136
-rw-r--r--system/database/drivers/pdo/subdrivers/pdo_firebird_driver.php44
-rw-r--r--system/database/drivers/pdo/subdrivers/pdo_firebird_forge.php228
-rw-r--r--system/database/drivers/pdo/subdrivers/pdo_ibm_driver.php40
-rw-r--r--system/database/drivers/pdo/subdrivers/pdo_ibm_forge.php146
-rw-r--r--system/database/drivers/pdo/subdrivers/pdo_informix_driver.php34
-rw-r--r--system/database/drivers/pdo/subdrivers/pdo_informix_forge.php155
-rw-r--r--system/database/drivers/pdo/subdrivers/pdo_mysql_driver.php47
-rw-r--r--system/database/drivers/pdo/subdrivers/pdo_mysql_forge.php218
-rw-r--r--system/database/drivers/pdo/subdrivers/pdo_oci_driver.php62
-rw-r--r--system/database/drivers/pdo/subdrivers/pdo_oci_forge.php133
-rw-r--r--system/database/drivers/pdo/subdrivers/pdo_odbc_driver.php54
-rw-r--r--system/database/drivers/pdo/subdrivers/pdo_odbc_forge.php62
-rw-r--r--system/database/drivers/pdo/subdrivers/pdo_pgsql_driver.php49
-rw-r--r--system/database/drivers/pdo/subdrivers/pdo_pgsql_forge.php194
-rw-r--r--system/database/drivers/pdo/subdrivers/pdo_sqlite_driver.php40
-rw-r--r--system/database/drivers/pdo/subdrivers/pdo_sqlite_forge.php229
-rw-r--r--system/database/drivers/pdo/subdrivers/pdo_sqlsrv_driver.php70
-rw-r--r--system/database/drivers/pdo/subdrivers/pdo_sqlsrv_forge.php136
-rw-r--r--system/database/drivers/postgre/postgre_driver.php65
-rw-r--r--system/database/drivers/postgre/postgre_forge.php254
-rw-r--r--system/database/drivers/postgre/postgre_result.php9
-rw-r--r--system/database/drivers/postgre/postgre_utility.php22
-rw-r--r--system/database/drivers/sqlite/sqlite_driver.php42
-rw-r--r--system/database/drivers/sqlite/sqlite_forge.php195
-rw-r--r--system/database/drivers/sqlite/sqlite_result.php9
-rw-r--r--system/database/drivers/sqlite/sqlite_utility.php11
-rw-r--r--system/database/drivers/sqlite3/sqlite3_driver.php40
-rw-r--r--system/database/drivers/sqlite3/sqlite3_forge.php205
-rw-r--r--system/database/drivers/sqlite3/sqlite3_result.php16
-rw-r--r--system/database/drivers/sqlite3/sqlite3_utility.php11
-rw-r--r--system/database/drivers/sqlsrv/sqlsrv_driver.php90
-rw-r--r--system/database/drivers/sqlsrv/sqlsrv_forge.php164
-rw-r--r--system/database/drivers/sqlsrv/sqlsrv_result.php5
-rw-r--r--system/database/drivers/sqlsrv/sqlsrv_utility.php22
-rw-r--r--system/helpers/array_helper.php3
-rw-r--r--system/helpers/captcha_helper.php3
-rw-r--r--system/helpers/cookie_helper.php3
-rw-r--r--system/helpers/date_helper.php20
-rw-r--r--system/helpers/directory_helper.php14
-rw-r--r--system/helpers/download_helper.php3
-rw-r--r--system/helpers/email_helper.php15
-rw-r--r--system/helpers/file_helper.php37
-rw-r--r--system/helpers/form_helper.php87
-rw-r--r--system/helpers/html_helper.php9
-rw-r--r--system/helpers/inflector_helper.php24
-rw-r--r--system/helpers/language_helper.php3
-rw-r--r--system/helpers/number_helper.php3
-rw-r--r--system/helpers/path_helper.php3
-rw-r--r--system/helpers/security_helper.php3
-rw-r--r--system/helpers/smiley_helper.php8
-rw-r--r--system/helpers/string_helper.php10
-rw-r--r--system/helpers/text_helper.php3
-rw-r--r--system/helpers/typography_helper.php3
-rw-r--r--system/helpers/url_helper.php20
-rw-r--r--system/helpers/xml_helper.php3
-rw-r--r--system/language/english/calendar_lang.php1
-rw-r--r--system/language/english/date_lang.php1
-rw-r--r--system/language/english/db_lang.php5
-rw-r--r--system/language/english/email_lang.php1
-rw-r--r--system/language/english/form_validation_lang.php1
-rw-r--r--system/language/english/ftp_lang.php1
-rw-r--r--system/language/english/imglib_lang.php1
-rw-r--r--system/language/english/migration_lang.php2
-rw-r--r--system/language/english/number_lang.php1
-rw-r--r--system/language/english/profiler_lang.php1
-rw-r--r--system/language/english/unit_test_lang.php1
-rw-r--r--system/language/english/upload_lang.php1
-rw-r--r--system/libraries/Cache/Cache.php5
-rw-r--r--system/libraries/Cache/drivers/Cache_apc.php5
-rw-r--r--system/libraries/Cache/drivers/Cache_dummy.php5
-rw-r--r--system/libraries/Cache/drivers/Cache_file.php5
-rw-r--r--system/libraries/Cache/drivers/Cache_memcached.php5
-rw-r--r--system/libraries/Cache/drivers/Cache_redis.php5
-rw-r--r--system/libraries/Cache/drivers/Cache_wincache.php5
-rw-r--r--system/libraries/Calendar.php3
-rw-r--r--system/libraries/Cart.php20
-rw-r--r--system/libraries/Driver.php3
-rw-r--r--system/libraries/Email.php343
-rw-r--r--system/libraries/Encrypt.php3
-rw-r--r--system/libraries/Form_validation.php24
-rw-r--r--system/libraries/Ftp.php106
-rw-r--r--system/libraries/Image_lib.php17
-rw-r--r--system/libraries/Javascript.php20
-rw-r--r--system/libraries/Migration.php3
-rw-r--r--system/libraries/Pagination.php298
-rw-r--r--system/libraries/Parser.php3
-rw-r--r--system/libraries/Profiler.php34
-rwxr-xr-xsystem/libraries/Session/Session.php36
-rwxr-xr-xsystem/libraries/Session/drivers/Session_cookie.php41
-rwxr-xr-xsystem/libraries/Session/drivers/Session_native.php5
-rw-r--r--system/libraries/Table.php3
-rw-r--r--system/libraries/Trackback.php44
-rw-r--r--system/libraries/Typography.php3
-rw-r--r--system/libraries/Unit_test.php85
-rw-r--r--system/libraries/Upload.php243
-rw-r--r--system/libraries/User_agent.php3
-rwxr-xr-xsystem/libraries/Xmlrpc.php372
-rw-r--r--system/libraries/Xmlrpcs.php3
-rw-r--r--system/libraries/Zip.php3
-rw-r--r--system/libraries/javascript/Jquery.php97
-rw-r--r--tests/codeigniter/core/Loader_test.php1
-rw-r--r--tests/codeigniter/database/DB_driver_test.php2
-rw-r--r--tests/codeigniter/helpers/directory_helper_test.php8
-rw-r--r--tests/codeigniter/helpers/form_helper_test.php15
-rw-r--r--tests/mocks/autoloader.php19
-rw-r--r--tests/mocks/database/db/driver.php1
-rw-r--r--tests/mocks/database/schema/skeleton.php6
-rw-r--r--user_guide_src/source/changelog.rst137
-rw-r--r--user_guide_src/source/contributing/index.rst2
-rw-r--r--user_guide_src/source/database/forge.rst61
-rw-r--r--user_guide_src/source/database/utilities.rst78
-rw-r--r--user_guide_src/source/general/alternative_php.rst21
-rw-r--r--user_guide_src/source/general/ancillary_classes.rst61
-rw-r--r--user_guide_src/source/general/autoloader.rst18
-rw-r--r--user_guide_src/source/general/caching.rst30
-rw-r--r--user_guide_src/source/general/cli.rst14
-rw-r--r--user_guide_src/source/general/common_functions.rst177
-rw-r--r--user_guide_src/source/general/controllers.rst216
-rw-r--r--user_guide_src/source/general/core_classes.rst40
-rw-r--r--user_guide_src/source/general/creating_drivers.rst5
-rw-r--r--user_guide_src/source/general/creating_libraries.rst93
-rw-r--r--user_guide_src/source/general/credits.rst2
-rw-r--r--user_guide_src/source/general/drivers.rst16
-rw-r--r--user_guide_src/source/general/environments.rst6
-rw-r--r--user_guide_src/source/general/errors.rst66
-rw-r--r--user_guide_src/source/general/helpers.rst58
-rw-r--r--user_guide_src/source/general/hooks.rst73
-rw-r--r--user_guide_src/source/general/index.rst2
-rw-r--r--user_guide_src/source/general/libraries.rst23
-rw-r--r--user_guide_src/source/general/managing_apps.rst44
-rw-r--r--user_guide_src/source/general/models.rst97
-rw-r--r--user_guide_src/source/general/profiling.rst28
-rw-r--r--user_guide_src/source/general/requirements.rst14
-rw-r--r--user_guide_src/source/general/reserved_names.rst41
-rw-r--r--user_guide_src/source/general/routing.rst61
-rw-r--r--user_guide_src/source/general/security.rst51
-rw-r--r--user_guide_src/source/general/styleguide.rst42
-rw-r--r--user_guide_src/source/general/urls.rst41
-rw-r--r--user_guide_src/source/general/views.rst53
-rw-r--r--user_guide_src/source/general/welcome.rst2
-rw-r--r--user_guide_src/source/helpers/array_helper.rst66
-rw-r--r--user_guide_src/source/helpers/captcha_helper.rst99
-rw-r--r--user_guide_src/source/helpers/cookie_helper.rst65
-rw-r--r--user_guide_src/source/helpers/date_helper.rst339
-rw-r--r--user_guide_src/source/helpers/directory_helper.rst5
-rw-r--r--user_guide_src/source/helpers/download_helper.rst32
-rw-r--r--user_guide_src/source/helpers/email_helper.rst48
-rw-r--r--user_guide_src/source/helpers/file_helper.rst178
-rw-r--r--user_guide_src/source/helpers/form_helper.rst518
-rw-r--r--user_guide_src/source/helpers/html_helper.rst296
-rw-r--r--user_guide_src/source/helpers/inflector_helper.rst82
-rw-r--r--user_guide_src/source/helpers/language_helper.rst25
-rw-r--r--user_guide_src/source/helpers/number_helper.rst32
-rw-r--r--user_guide_src/source/helpers/path_helper.rst31
-rw-r--r--user_guide_src/source/helpers/security_helper.rst70
-rw-r--r--user_guide_src/source/helpers/smiley_helper.rst70
-rw-r--r--user_guide_src/source/helpers/string_helper.rst136
-rw-r--r--user_guide_src/source/helpers/text_helper.rst138
-rw-r--r--user_guide_src/source/helpers/typography_helper.rst45
-rw-r--r--user_guide_src/source/helpers/url_helper.rst300
-rw-r--r--user_guide_src/source/installation/upgrade_211.rst4
-rw-r--r--user_guide_src/source/installation/upgrade_212.rst4
-rw-r--r--user_guide_src/source/installation/upgrade_213.rst20
-rw-r--r--user_guide_src/source/installation/upgrade_300.rst138
-rw-r--r--user_guide_src/source/installation/upgrading.rst3
-rw-r--r--user_guide_src/source/libraries/form_validation.rst11
-rw-r--r--user_guide_src/source/libraries/input.rst93
-rw-r--r--user_guide_src/source/libraries/sessions.rst2
-rw-r--r--user_guide_src/source/libraries/unit_testing.rst2
240 files changed, 10770 insertions, 4698 deletions
diff --git a/application/config/config.php b/application/config/config.php
index ab1508e7b..0562953b0 100644
--- a/application/config/config.php
+++ b/application/config/config.php
@@ -62,11 +62,11 @@ $config['index_page'] = 'index.php';
| URI string. The default setting of 'AUTO' works for most servers.
| If your links do not seem to work, try one of the other delicious flavors:
|
-| 'AUTO' Default - auto detects
-| 'PATH_INFO' Uses the PATH_INFO
-| 'QUERY_STRING' Uses the QUERY_STRING
-| 'REQUEST_URI' Uses the REQUEST_URI
-| 'ORIG_PATH_INFO' Uses the ORIG_PATH_INFO
+| 'AUTO' Default - auto detects
+| 'CLI' or 'argv' Uses $_SERVER['argv'] (for php-cli only)
+| 'PATH_INFO' Uses $_SERVER['PATH_INFO']
+| 'REQUEST_URI' Uses $_SERVER['REQUEST_URI']
+| 'QUERY_STRING' Uses $_SERVER['QUERY_STRING']
|
*/
$config['uri_protocol'] = 'AUTO';
diff --git a/application/config/foreign_chars.php b/application/config/foreign_chars.php
index 6614caa31..5a2bb0cf7 100644
--- a/application/config/foreign_chars.php
+++ b/application/config/foreign_chars.php
@@ -40,44 +40,56 @@ $foreign_characters = array(
'/Ä/' => 'Ae',
'/Ü/' => 'Ue',
'/Ö/' => 'Oe',
- '/À|Á|Â|Ã|Ä|Å|Ǻ|Ā|Ă|Ą|Ǎ|Α|Ά|Ả|Ạ|Ầ|Ẫ|Ẩ|Ậ|Ằ|Ắ|Ẵ|Ẳ|Ặ/' => 'A',
- '/à|á|â|ã|å|ǻ|ā|ă|ą|ǎ|ª|α|ά|ả|ạ|ầ|ấ|ẫ|ẩ|ậ|ằ|ắ|ẵ|ẳ|ặ/' => 'a',
+ '/À|Á|Â|Ã|Ä|Å|Ǻ|Ā|Ă|Ą|Ǎ|Α|Ά|Ả|Ạ|Ầ|Ẫ|Ẩ|Ậ|Ằ|Ắ|Ẵ|Ẳ|Ặ|А/' => 'A',
+ '/à|á|â|ã|å|ǻ|ā|ă|ą|ǎ|ª|α|ά|ả|ạ|ầ|ấ|ẫ|ẩ|ậ|ằ|ắ|ẵ|ẳ|ặ|а/' => 'a',
+ '/Б/' => 'B',
+ '/б/' => 'b',
'/Ç|Ć|Ĉ|Ċ|Č/' => 'C',
'/ç|ć|ĉ|ċ|č/' => 'c',
+ '/Д/' => 'D',
+ '/д/' => 'd',
'/Ð|Ď|Đ|Δ/' => 'Dj',
'/ð|ď|đ|δ/' => 'dj',
- '/È|É|Ê|Ë|Ē|Ĕ|Ė|Ę|Ě|Ε|Έ|Ẽ|Ẻ|Ẹ|Ề|Ế|Ễ|Ể|Ệ/' => 'E',
- '/è|é|ê|ë|ē|ĕ|ė|ę|ě|έ|ε|ẽ|ẻ|ẹ|ề|ế|ễ|ể|ệ/' => 'e',
- '/Ĝ|Ğ|Ġ|Ģ|Γ/' => 'G',
- '/ĝ|ğ|ġ|ģ|γ/' => 'g',
+ '/È|É|Ê|Ë|Ē|Ĕ|Ė|Ę|Ě|Ε|Έ|Ẽ|Ẻ|Ẹ|Ề|Ế|Ễ|Ể|Ệ|Е|Ё|Э/' => 'E',
+ '/è|é|ê|ë|ē|ĕ|ė|ę|ě|έ|ε|ẽ|ẻ|ẹ|ề|ế|ễ|ể|ệ|е|ё|э/' => 'e',
+ '/Ф/' => 'F',
+ '/ф/' => 'f',
+ '/Ĝ|Ğ|Ġ|Ģ|Γ|Г/' => 'G',
+ '/ĝ|ğ|ġ|ģ|γ|г/' => 'g',
'/Ĥ|Ħ/' => 'H',
'/ĥ|ħ/' => 'h',
- '/Ì|Í|Î|Ï|Ĩ|Ī|Ĭ|Ǐ|Į|İ|Η|Ή|Ί|Ι|Ϊ|Ỉ|Ị/' => 'I',
- '/ì|í|î|ï|ĩ|ī|ĭ|ǐ|į|ı|η|ή|ί|ι|ϊ|ỉ|ị/' => 'i',
+ '/Ì|Í|Î|Ï|Ĩ|Ī|Ĭ|Ǐ|Į|İ|Η|Ή|Ί|Ι|Ϊ|Ỉ|Ị|И|Й/' => 'I',
+ '/ì|í|î|ï|ĩ|ī|ĭ|ǐ|į|ı|η|ή|ί|ι|ϊ|ỉ|ị|и|й/' => 'i',
'/Ĵ/' => 'J',
'/ĵ/' => 'j',
- '/Ķ|Κ/' => 'K',
- '/ķ|κ/' => 'k',
- '/Ĺ|Ļ|Ľ|Ŀ|Ł|Λ/' => 'L',
- '/ĺ|ļ|ľ|ŀ|ł|λ/' => 'l',
- '/Ñ|Ń|Ņ|Ň|Ν/' => 'N',
- '/ñ|ń|ņ|ň|ʼn|ν/' => 'n',
- '/Ò|Ó|Ô|Õ|Ō|Ŏ|Ǒ|Ő|Ơ|Ø|Ǿ|Ο|Ό|Ω|Ώ|Ỏ|Ọ|Ồ|Ố|Ỗ|Ổ|Ộ|Ờ|Ớ|Ỡ|Ở|Ợ/' => 'O',
- '/ò|ó|ô|õ|ō|ŏ|ǒ|ő|ơ|ø|ǿ|º|ο|ό|ω|ώ|ỏ|ọ|ồ|ố|ỗ|ổ|ộ|ờ|ớ|ỡ|ở|ợ/' => 'o',
- '/Ŕ|Ŗ|Ř|Ρ/' => 'R',
- '/ŕ|ŗ|ř|ρ/' => 'r',
- '/Ś|Ŝ|Ş|Ș|Š|Σ/' => 'S',
- '/ś|ŝ|ş|ș|š|ſ|σ|ς/' => 's',
- '/Ț|Ţ|Ť|Ŧ|τ/' => 'T',
- '/ț|ţ|ť|ŧ/' => 't',
- '/Ù|Ú|Û|Ũ|Ū|Ŭ|Ů|Ű|Ų|Ư|Ǔ|Ǖ|Ǘ|Ǚ|Ǜ|Ũ|Ủ|Ụ|Ừ|Ứ|Ữ|Ử|Ự/' => 'U',
- '/ù|ú|û|ũ|ū|ŭ|ů|ű|ų|ư|ǔ|ǖ|ǘ|ǚ|ǜ|υ|ύ|ϋ|ủ|ụ|ừ|ứ|ữ|ử|ự/' => 'u',
+ '/Ķ|Κ|К/' => 'K',
+ '/ķ|κ|к/' => 'k',
+ '/Ĺ|Ļ|Ľ|Ŀ|Ł|Λ|Л/' => 'L',
+ '/ĺ|ļ|ľ|ŀ|ł|λ|л/' => 'l',
+ '/М/' => 'M',
+ '/м/' => 'm',
+ '/Ñ|Ń|Ņ|Ň|Ν|Н/' => 'N',
+ '/ñ|ń|ņ|ň|ʼn|ν|н/' => 'n',
+ '/Ò|Ó|Ô|Õ|Ō|Ŏ|Ǒ|Ő|Ơ|Ø|Ǿ|Ο|Ό|Ω|Ώ|Ỏ|Ọ|Ồ|Ố|Ỗ|Ổ|Ộ|Ờ|Ớ|Ỡ|Ở|Ợ|О/' => 'O',
+ '/ò|ó|ô|õ|ō|ŏ|ǒ|ő|ơ|ø|ǿ|º|ο|ό|ω|ώ|ỏ|ọ|ồ|ố|ỗ|ổ|ộ|ờ|ớ|ỡ|ở|ợ|о/' => 'o',
+ '/П/' => 'P',
+ '/п/' => 'p',
+ '/Ŕ|Ŗ|Ř|Ρ|Р/' => 'R',
+ '/ŕ|ŗ|ř|ρ|р/' => 'r',
+ '/Ś|Ŝ|Ş|Ș|Š|Σ|С/' => 'S',
+ '/ś|ŝ|ş|ș|š|ſ|σ|ς|с/' => 's',
+ '/Ț|Ţ|Ť|Ŧ|τ|Т/' => 'T',
+ '/ț|ţ|ť|ŧ|т/' => 't',
+ '/Ù|Ú|Û|Ũ|Ū|Ŭ|Ů|Ű|Ų|Ư|Ǔ|Ǖ|Ǘ|Ǚ|Ǜ|Ũ|Ủ|Ụ|Ừ|Ứ|Ữ|Ử|Ự|У/' => 'U',
+ '/ù|ú|û|ũ|ū|ŭ|ů|ű|ų|ư|ǔ|ǖ|ǘ|ǚ|ǜ|υ|ύ|ϋ|ủ|ụ|ừ|ứ|ữ|ử|ự|у/' => 'u',
'/Ý|Ÿ|Ŷ|Υ|Ύ|Ϋ|Ỳ|Ỹ|Ỷ|Ỵ/' => 'Y',
'/ý|ÿ|ŷ|ỳ|ỹ|ỷ|ỵ/' => 'y',
+ '/В/' => 'V',
+ '/в/' => 'v',
'/Ŵ/' => 'W',
'/ŵ/' => 'w',
- '/Ź|Ż|Ž|Ζ/' => 'Z',
- '/ź|ż|ž|ζ/' => 'z',
+ '/Ź|Ż|Ž|Ζ|З/' => 'Z',
+ '/ź|ż|ž|ζ|з/' => 'z',
'/Æ|Ǽ/' => 'AE',
'/ß/'=> 'ss',
'/IJ/' => 'IJ',
@@ -89,6 +101,22 @@ $foreign_characters = array(
'/β/' => 'v',
'/μ/' => 'm',
'/ψ/' => 'ps',
+ '/Ж/'=>'Zh',
+ '/ж/'=>'zh',
+ '/Х/'=>'Kh',
+ '/х/'=>'kh',
+ '/Ц/'=>'Tc',
+ '/ц/'=>'tc',
+ '/Ч/'=>'Ch',
+ '/ч/'=>'ch',
+ '/Ш/'=>'Sh',
+ '/ш/'=>'sh',
+ '/Щ/'=>'Shch',
+ '/щ/'=>'shch',
+ '/Ю/'=>'Iu',
+ '/ю/'=>'iu',
+ '/Я/'=>'Ia',
+ '/я/'=>'ia'
);
/* End of file foreign_chars.php */
diff --git a/application/controllers/welcome.php b/application/controllers/welcome.php
index 1ed82d2a7..f70dd78ad 100644
--- a/application/controllers/welcome.php
+++ b/application/controllers/welcome.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
class Welcome extends CI_Controller {
diff --git a/application/views/errors/error_404.php b/application/views/errors/error_404.php
index fe48fd524..4a8823dee 100644
--- a/application/views/errors/error_404.php
+++ b/application/views/errors/error_404.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
?><!DOCTYPE html>
<html lang="en">
<head>
diff --git a/application/views/errors/error_db.php b/application/views/errors/error_db.php
index 76ca6df7a..21d5d86ef 100644
--- a/application/views/errors/error_db.php
+++ b/application/views/errors/error_db.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
?><!DOCTYPE html>
<html lang="en">
<head>
diff --git a/application/views/errors/error_general.php b/application/views/errors/error_general.php
index e9baf1665..5bf361113 100644
--- a/application/views/errors/error_general.php
+++ b/application/views/errors/error_general.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
?><!DOCTYPE html>
<html lang="en">
<head>
diff --git a/application/views/errors/error_php.php b/application/views/errors/error_php.php
index b76dc8a9e..c0c4bd622 100644
--- a/application/views/errors/error_php.php
+++ b/application/views/errors/error_php.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
?>
<div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">
diff --git a/application/views/welcome_message.php b/application/views/welcome_message.php
index d227f82d1..27332f456 100644
--- a/application/views/welcome_message.php
+++ b/application/views/welcome_message.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
?><!DOCTYPE html>
<html lang="en">
<head>
diff --git a/contributing.md b/contributing.md
index f3f94fbc8..b6d486d00 100644
--- a/contributing.md
+++ b/contributing.md
@@ -7,7 +7,7 @@ Issues are a quick way to point out a bug. If you find a bug or documentation er
1. There is not already an open Issue
2. The issue has already been fixed (check the develop branch, or look for closed Issues)
-3. Is it something really obvious that you fix it yourself?
+3. Is it something really obvious that you can fix yourself?
Reporting issues is helpful but an even better approach is to send a Pull Request, which is done by "Forking" the main repository and committing to your own copy. This will require you to use the version control system called Git.
diff --git a/system/core/Benchmark.php b/system/core/Benchmark.php
index f94db2721..e80ee54dd 100644
--- a/system/core/Benchmark.php
+++ b/system/core/Benchmark.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Benchmark Class
diff --git a/system/core/CodeIgniter.php b/system/core/CodeIgniter.php
index f27086386..89081b572 100644
--- a/system/core/CodeIgniter.php
+++ b/system/core/CodeIgniter.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* System Initialization File
@@ -255,23 +256,22 @@
* Security check
* ------------------------------------------------------
*
- * None of the functions in the app controller or the
+ * None of the methods in the app controller or the
* loader class can be called via the URI, nor can
- * controller functions that begin with an underscore
+ * controller functions that begin with an underscore.
*/
$class = $RTR->fetch_class();
$method = $RTR->fetch_method();
- if ( ! class_exists($class)
- OR strpos($method, '_') === 0
- OR in_array(strtolower($method), array_map('strtolower', get_class_methods('CI_Controller')))
- )
+ if ( ! class_exists($class) OR $method[0] === '_' OR method_exists('CI_Controller', $method))
{
if ( ! empty($RTR->routes['404_override']))
{
- $x = explode('/', $RTR->routes['404_override'], 2);
- $class = $x[0];
- $method = isset($x[1]) ? $x[1] : 'index';
+ if (sscanf($RTR->routes['404_override'], '%[^/]/%s', $class, $method) !== 2)
+ {
+ $method = 'index';
+ }
+
if ( ! class_exists($class))
{
if ( ! file_exists(APPPATH.'controllers/'.$class.'.php'))
@@ -288,6 +288,42 @@
}
}
+ if (method_exists($class, '_remap'))
+ {
+ $params = array($method, array_slice($URI->rsegments, 2));
+ $method = '_remap';
+ }
+ else
+ {
+ // WARNING: It appears that there are issues with is_callable() even in PHP 5.2!
+ // Furthermore, there are bug reports and feature/change requests related to it
+ // that make it unreliable to use in this context. Please, DO NOT change this
+ // work-around until a better alternative is available.
+ if ( ! in_array(strtolower($method), array_map('strtolower', get_class_methods($class)), TRUE))
+ {
+ if (empty($RTR->routes['404_override']))
+ {
+ show_404($class.'/'.$method);
+ }
+ elseif (sscanf($RTR->routes['404_override'], '%[^/]/%s', $class, $method) !== 2)
+ {
+ $method = 'index';
+ }
+
+ if ( ! class_exists($class))
+ {
+ if ( ! file_exists(APPPATH.'controllers/'.$class.'.php'))
+ {
+ show_404($class.'/'.$method);
+ }
+
+ include_once(APPPATH.'controllers/'.$class.'.php');
+ }
+ }
+
+ $params = array_slice($URI->rsegments, 2);
+ }
+
/*
* ------------------------------------------------------
* Is there a "pre_controller" hook?
@@ -317,45 +353,7 @@
* Call the requested method
* ------------------------------------------------------
*/
- // Is there a "remap" function? If so, we call it instead
- if (method_exists($CI, '_remap'))
- {
- $CI->_remap($method, array_slice($URI->rsegments, 2));
- }
- else
- {
- // is_callable() returns TRUE on some versions of PHP 5 for private and protected
- // methods, so we'll use this workaround for consistent behavior
- if ( ! in_array(strtolower($method), array_map('strtolower', get_class_methods($CI))))
- {
- // Check and see if we are using a 404 override and use it.
- if ( ! empty($RTR->routes['404_override']))
- {
- $x = explode('/', $RTR->routes['404_override'], 2);
- $class = $x[0];
- $method = isset($x[1]) ? $x[1] : 'index';
- if ( ! class_exists($class))
- {
- if ( ! file_exists(APPPATH.'controllers/'.$class.'.php'))
- {
- show_404($class.'/'.$method);
- }
-
- include_once(APPPATH.'controllers/'.$class.'.php');
- unset($CI);
- $CI = new $class();
- }
- }
- else
- {
- show_404($class.'/'.$method);
- }
- }
-
- // Call the requested method.
- // Any URI segments present (besides the class/function) will be passed to the method for convenience
- call_user_func_array(array(&$CI, $method), array_slice($URI->rsegments, 2));
- }
+ call_user_func_array(array(&$CI, $method), $params);
// Mark a benchmark end point
$BM->mark('controller_execution_time_( '.$class.' / '.$method.' )_end');
diff --git a/system/core/Common.php b/system/core/Common.php
index 2dd31d3e9..7feb16bfd 100644
--- a/system/core/Common.php
+++ b/system/core/Common.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Common Functions
@@ -419,7 +420,7 @@ if ( ! function_exists('log_message'))
return;
}
- $_log =& load_class('Log');
+ $_log =& load_class('Log', 'core');
$_log->write_log($level, $message, $php_error);
}
}
@@ -650,5 +651,52 @@ if ( ! function_exists('_stringify_attributes'))
}
}
+// ------------------------------------------------------------------------
+
+if ( ! function_exists('function_usable'))
+{
+ /**
+ * Function usable
+ *
+ * Executes a function_exists() check, and if the Suhosin PHP
+ * extension is loaded - checks whether the function that is
+ * checked might be disabled in there as well.
+ *
+ * This is useful as function_exists() will return FALSE for
+ * functions disabled via the *disable_functions* php.ini
+ * setting, but not for *suhosin.executor.func.blacklist* and
+ * *suhosin.executor.disable_eval*. These settings will just
+ * terminate script execution if a disabled function is executed.
+ *
+ * @link http://www.hardened-php.net/suhosin/
+ * @param string $function_name Function to check for
+ * @return bool TRUE if the function exists and is safe to call,
+ * FALSE otherwise.
+ */
+ function function_usable($function_name)
+ {
+ static $_suhosin_func_blacklist;
+
+ if (function_exists($function_name))
+ {
+ if ( ! isset($_suhosin_func_blacklist))
+ {
+ $_suhosin_func_blacklist = extension_loaded('suhosin')
+ ? array()
+ : explode(',', trim(@ini_get('suhosin.executor.func.blacklist')));
+
+ if ( ! in_array('eval', $_suhosin_func_blacklist, TRUE) && @ini_get('suhosin.executor.disable_eval'))
+ {
+ $_suhosin_func_blacklist[] = 'eval';
+ }
+ }
+
+ return in_array($function_name, $_suhosin_func_blacklist, TRUE);
+ }
+
+ return FALSE;
+ }
+}
+
/* End of file Common.php */
/* Location: ./system/core/Common.php */ \ No newline at end of file
diff --git a/system/core/Config.php b/system/core/Config.php
index 642cee798..8250b5b1a 100644
--- a/system/core/Config.php
+++ b/system/core/Config.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Config Class
diff --git a/system/core/Controller.php b/system/core/Controller.php
index 8c2ba893e..ee6fec8d5 100644
--- a/system/core/Controller.php
+++ b/system/core/Controller.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Application Controller Class
diff --git a/system/core/Exceptions.php b/system/core/Exceptions.php
index 556257729..ced65ece4 100644
--- a/system/core/Exceptions.php
+++ b/system/core/Exceptions.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Exceptions Class
diff --git a/system/core/Hooks.php b/system/core/Hooks.php
index d60e9ac5d..3c28ec9ba 100644
--- a/system/core/Hooks.php
+++ b/system/core/Hooks.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Hooks Class
diff --git a/system/core/Input.php b/system/core/Input.php
index f6213c34e..adc5f7ac0 100644
--- a/system/core/Input.php
+++ b/system/core/Input.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Input Class
@@ -99,6 +100,16 @@ class CI_Input {
protected $headers = array();
/**
+ * Input stream data
+ *
+ * Parsed from php://input at runtime
+ *
+ * @see CI_Input::input_stream()
+ * @var array
+ */
+ protected $_input_stream = NULL;
+
+ /**
* Class constructor
*
* Determines whether to globally enable the XSS processing
@@ -256,6 +267,37 @@ class CI_Input {
// ------------------------------------------------------------------------
/**
+ * Fetch an item from the php://input stream
+ *
+ * Useful when you need to access PUT, DELETE or PATCH request data.
+ *
+ * @param string $index Index for item to be fetched
+ * @param bool $xss_clean Whether to apply XSS filtering
+ * @return mixed
+ */
+ public function input_stream($index = '', $xss_clean = FALSE)
+ {
+ // The input stream can only be read once, so we'll need to check
+ // if we have already done that first.
+ if (is_array($this->_input_stream))
+ {
+ return $this->_fetch_from_array($this->_input_stream, $index, $xss_clean);
+ }
+
+ // Parse the input stream in our cache var
+ parse_str(file_get_contents('php://input'), $this->_input_stream);
+ if ( ! is_array($this->_input_stream))
+ {
+ $this->_input_stream = array();
+ return NULL;
+ }
+
+ return $this->_fetch_from_array($this->_input_stream, $index, $xss_clean);
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
* Set cookie
*
* Accepts an arbitrary number of parameters (up to 7) or an associative
@@ -355,11 +397,7 @@ class CI_Input {
// Some proxies typically list the whole chain of IP
// addresses through which the client has reached us.
// e.g. client_ip, proxy_ip1, proxy_ip2, etc.
- if (strpos($spoof, ',') !== FALSE)
- {
- $spoof = explode(',', $spoof, 2);
- $spoof = $spoof[0];
- }
+ sscanf($spoof, '%[^,]', $spoof);
if ( ! $this->valid_ip($spoof))
{
@@ -429,7 +467,7 @@ class CI_Input {
}
// Split the netmask length off the network address
- list($netaddr, $masklen) = explode('/', $proxy_ips[$i], 2);
+ sscanf($proxy_ips[$i], '%[^/]/%d', $netaddr, $masklen);
// Again, an IPv6 address is most likely in a compressed form
if ($separator === ':')
@@ -694,7 +732,7 @@ class CI_Input {
*/
protected function _clean_input_keys($str)
{
- if ( ! preg_match('/^[a-z0-9:_\/-]+$/i', $str))
+ if ( ! preg_match('/^[a-z0-9:_\/|-]+$/i', $str))
{
set_status_header(503);
exit('Disallowed Key Characters.');
diff --git a/system/core/Lang.php b/system/core/Lang.php
index 251cf6ef1..896385134 100644
--- a/system/core/Lang.php
+++ b/system/core/Lang.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Language Class
diff --git a/system/core/Loader.php b/system/core/Loader.php
index db56ab3ae..1e6eafe8a 100644
--- a/system/core/Loader.php
+++ b/system/core/Loader.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Loader Class
@@ -129,7 +130,7 @@ class CI_Loader {
/**
* Class constructor
*
- * Sets component load paths gets the initial output buffering level.
+ * Sets component load paths, gets the initial output buffering level.
*
* @return void
*/
@@ -147,21 +148,18 @@ class CI_Loader {
// --------------------------------------------------------------------
/**
- * Initialize the Loader
+ * Initializer
*
- * @used-by CI_Controller
+ * @todo Figure out a way to move this to the constructor
+ * without breaking *package_path*() methods.
* @uses CI_Loader::_ci_autoloader()
- * @return object $this
+ * @used-by CI_Controller::__construct()
+ * @return void
*/
public function initialize()
{
- $this->_ci_classes = array();
- $this->_ci_loaded_files = array();
- $this->_ci_models = array();
$this->_base_classes =& is_loaded();
-
$this->_ci_autoloader();
- return $this;
}
// --------------------------------------------------------------------
@@ -354,26 +352,30 @@ class CI_Loader {
/**
* Load the Database Utilities Class
*
- * @return void
+ * @param object $db Database object
+ * @param bool $return Whether to return the DB Forge class object or not
+ * @return void|object
*/
- public function dbutil()
+ public function dbutil($db = NULL, $return = FALSE)
{
- if ( ! class_exists('CI_DB'))
- {
- $this->database();
- }
-
$CI =& get_instance();
- // for backwards compatibility, load dbforge so we can extend dbutils off it
- // this use is deprecated and strongly discouraged
- $CI->load->dbforge();
+ if ( ! is_object($db) OR ! ($db instanceof CI_DB))
+ {
+ class_exists('CI_DB', FALSE) OR $this->database();
+ $db =& $CI->db;
+ }
require_once(BASEPATH.'database/DB_utility.php');
- require_once(BASEPATH.'database/drivers/'.$CI->db->dbdriver.'/'.$CI->db->dbdriver.'_utility.php');
- $class = 'CI_DB_'.$CI->db->dbdriver.'_utility';
+ require_once(BASEPATH.'database/drivers/'.$db->dbdriver.'/'.$db->dbdriver.'_utility.php');
+ $class = 'CI_DB_'.$db->dbdriver.'_utility';
- $CI->dbutil = new $class();
+ if ($return === TRUE)
+ {
+ return new $class($db);
+ }
+
+ $CI->dbutil = new $class($db);
}
// --------------------------------------------------------------------
@@ -381,22 +383,42 @@ class CI_Loader {
/**
* Load the Database Forge Class
*
- * @return void
+ * @param object $db Database object
+ * @param bool $return Whether to return the DB Forge class object or not
+ * @return void|object
*/
- public function dbforge()
+ public function dbforge($db = NULL, $return = FALSE)
{
- if ( ! class_exists('CI_DB'))
+ $CI =& get_instance();
+ if ( ! is_object($db) OR ! ($db instanceof CI_DB))
{
- $this->database();
+ class_exists('CI_DB', FALSE) OR $this->database();
+ $db =& $CI->db;
}
- $CI =& get_instance();
-
require_once(BASEPATH.'database/DB_forge.php');
- require_once(BASEPATH.'database/drivers/'.$CI->db->dbdriver.'/'.$CI->db->dbdriver.'_forge.php');
- $class = 'CI_DB_'.$CI->db->dbdriver.'_forge';
+ require_once(BASEPATH.'database/drivers/'.$db->dbdriver.'/'.$db->dbdriver.'_forge.php');
- $CI->dbforge = new $class();
+ if ( ! empty($db->subdriver))
+ {
+ $driver_path = BASEPATH.'database/drivers/'.$db->dbdriver.'/subdrivers/'.$db->dbdriver.'_'.$db->subdriver.'_forge.php';
+ if (file_exists($driver_path))
+ {
+ require_once($driver_path);
+ $class = 'CI_DB_'.$db->dbdriver.'_'.$db->subdriver.'_forge';
+ }
+ }
+ else
+ {
+ $class = 'CI_DB_'.$db->dbdriver.'_forge';
+ }
+
+ if ($return === TRUE)
+ {
+ return new $class($db);
+ }
+
+ $CI->dbforge = new $class($db);
}
// --------------------------------------------------------------------
@@ -510,27 +532,34 @@ class CI_Loader {
continue;
}
- $ext_helper = APPPATH.'helpers/'.config_item('subclass_prefix').$helper.'.php';
-
// Is this a helper extension request?
- if (file_exists($ext_helper))
+ $ext_helper = config_item('subclass_prefix').$helper;
+ $ext_loaded = FALSE;
+ foreach ($this->_ci_helper_paths as $path)
{
- $base_helper = BASEPATH.'helpers/'.$helper.'.php';
+ if (file_exists($path.'helpers/'.$ext_helper.'.php'))
+ {
+ include_once($path.'helpers/'.$ext_helper.'.php');
+ $ext_loaded = TRUE;
+ }
+ }
+ // If we have loaded extensions - check if the base one is here
+ if ($ext_loaded === TRUE)
+ {
+ $base_helper = BASEPATH.'helpers/'.$helper.'.php';
if ( ! file_exists($base_helper))
{
show_error('Unable to load the requested file: helpers/'.$helper.'.php');
}
- include_once($ext_helper);
include_once($base_helper);
-
$this->_ci_helpers[$helper] = TRUE;
log_message('debug', 'Helper loaded: '.$helper);
continue;
}
- // Try to load the helper
+ // No extensions found ... try loading regular helpers and/or overrides
foreach ($this->_ci_helper_paths as $path)
{
if (file_exists($path.'helpers/'.$helper.'.php'))
@@ -849,7 +878,9 @@ class CI_Loader {
// If the PHP installation does not support short tags we'll
// do a little string replacement, changing the short tags
// to standard PHP echo statements.
- if ( ! is_php('5.4') && (bool) @ini_get('short_open_tag') === FALSE && config_item('rewrite_short_tags') === TRUE)
+ if ( ! is_php('5.4') && (bool) @ini_get('short_open_tag') === FALSE
+ && config_item('rewrite_short_tags') === TRUE && function_usable('eval')
+ )
{
echo eval('?>'.preg_replace('/;*\s*\?>/', '; ?>', str_replace('<?=', '<?php echo ', file_get_contents($_ci_path))));
}
diff --git a/system/libraries/Log.php b/system/core/Log.php
index baac80121..e66270840 100644
--- a/system/libraries/Log.php
+++ b/system/core/Log.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Logging Class
@@ -151,7 +152,7 @@ class CI_Log {
if ( ! file_exists($filepath))
{
$newfile = TRUE;
- $message .= '<'."?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); ?".">\n\n";
+ $message .= '<'."?php defined('BASEPATH') OR exit('No direct script access allowed'); ?".">\n\n";
}
if ( ! $fp = @fopen($filepath, FOPEN_WRITE_CREATE))
diff --git a/system/core/Model.php b/system/core/Model.php
index 5a87ab153..28fdfbb69 100644
--- a/system/core/Model.php
+++ b/system/core/Model.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Model Class
diff --git a/system/core/Output.php b/system/core/Output.php
index 3bb8f8dc0..9300df356 100644
--- a/system/core/Output.php
+++ b/system/core/Output.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Output Class
diff --git a/system/core/Router.php b/system/core/Router.php
index a5e29f1a3..01f44bc83 100644
--- a/system/core/Router.php
+++ b/system/core/Router.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Router Class
@@ -53,13 +54,6 @@ class CI_Router {
public $routes = array();
/**
- * List of error routes
- *
- * @var array
- */
- public $error_routes = array();
-
- /**
* Current class name
*
* @var string
@@ -148,12 +142,12 @@ class CI_Router {
include(APPPATH.'config/routes.php');
}
- $this->routes = ( ! isset($route) OR ! is_array($route)) ? array() : $route;
+ $this->routes = (isset($route) && is_array($route)) ? $route : array();
unset($route);
// Set the default controller so we can display it in the event
// the URI doesn't correlated to a valid controller.
- $this->default_controller = empty($this->routes['default_controller']) ? FALSE : strtolower($this->routes['default_controller']);
+ $this->default_controller = empty($this->routes['default_controller']) ? FALSE : $this->routes['default_controller'];
// Were there any query string segments? If so, we'll validate them and bail out since we're done.
if (count($segments) > 0)
@@ -185,25 +179,21 @@ class CI_Router {
*/
protected function _set_default_controller()
{
- if ($this->default_controller === FALSE)
+ if (empty($this->default_controller))
{
show_error('Unable to determine what should be displayed. A default route has not been specified in the routing file.');
}
+
// Is the method being specified?
- if (strpos($this->default_controller, '/') !== FALSE)
- {
- $x = explode('/', $this->default_controller);
- $this->set_class($x[0]);
- $this->set_method($x[1]);
- $this->_set_request($x);
- }
- else
+ if (sscanf($this->default_controller, '%[^/]/%s', $class, $method) !== 2)
{
- $this->set_class($this->default_controller);
- $this->set_method('index');
- $this->_set_request(array($this->default_controller, 'index'));
+ $method = 'index';
}
+ $this->set_class($class);
+ $this->set_method($method);
+ $this->_set_request(array($class, $method));
+
// re-index the routed segments array so it starts with 1 rather than 0
$this->uri->_reindex_segments();
@@ -232,17 +222,8 @@ class CI_Router {
$this->set_class($segments[0]);
- if (isset($segments[1]))
- {
- // A standard method request
- $this->set_method($segments[1]);
- }
- else
- {
- // This lets the "routed" segment array identify that the default
- // index method is being used.
- $segments[1] = 'index';
- }
+ isset($segments[1]) OR $segments[1] = 'index';
+ $this->set_method($segments[1]);
// Update our "routed" segment array to contain the segments.
// Note: If there is no custom routing, this array will be
@@ -267,9 +248,13 @@ class CI_Router {
return $segments;
}
+ $temp = str_replace('-', '_', $segments[0]);
+
// Does the requested controller exist in the root folder?
- if (file_exists(APPPATH.'controllers/'.$segments[0].'.php'))
+ if (file_exists(APPPATH.'controllers/'.$temp.'.php'))
{
+ $segments[0] = $temp;
+ empty($segments[1]) OR $segments[1] = str_replace('-', '_', $segments[1]);
return $segments;
}
@@ -277,22 +262,19 @@ class CI_Router {
if (is_dir(APPPATH.'controllers/'.$segments[0]))
{
// Set the directory and remove it from the segment array
- $this->set_directory($segments[0]);
- $segments = array_slice($segments, 1);
-
+ $this->set_directory(array_shift($segments));
if (count($segments) > 0)
{
+ $segments[0] = str_replace('-', '_', $segments[0]);
+ empty($segments[1]) OR $segments[1] = str_replace('-', '_', $segments[1]);
+
// Does the requested controller exist in the sub-folder?
if ( ! file_exists(APPPATH.'controllers/'.$this->fetch_directory().$segments[0].'.php'))
{
if ( ! empty($this->routes['404_override']))
{
- $x = explode('/', $this->routes['404_override']);
- $this->set_directory('');
- $this->set_class($x[0]);
- $this->set_method(isset($x[1]) ? $x[1] : 'index');
-
- return $x;
+ $this->directory = '';
+ return explode('/', $this->routes['404_override'], 2);
}
else
{
@@ -303,40 +285,26 @@ class CI_Router {
else
{
// Is the method being specified in the route?
- if (strpos($this->default_controller, '/') !== FALSE)
- {
- $x = explode('/', $this->default_controller);
- $this->set_class($x[0]);
- $this->set_method($x[1]);
- }
- else
- {
- $this->set_class($this->default_controller);
- $this->set_method('index');
- }
-
- // Does the default controller exist in the sub-folder?
- if ( ! file_exists(APPPATH.'controllers/'.$this->fetch_directory().$this->default_controller.'.php'))
+ $segments = explode('/', $this->default_controller);
+ if ( ! file_exists(APPPATH.'controllers/'.$this->fetch_directory().$segments[0].'.php'))
{
$this->directory = '';
- return array();
}
-
}
return $segments;
}
-
// If we've gotten this far it means that the URI does not correlate to a valid
// controller class. We will now see if there is an override
if ( ! empty($this->routes['404_override']))
{
- $x = explode('/', $this->routes['404_override']);
- $this->set_class($x[0]);
- $this->set_method(isset($x[1]) ? $x[1] : 'index');
+ if (sscanf($this->routes['404_override'], '%[^/]/%s', $class, $method) !== 2)
+ {
+ $method = 'index';
+ }
- return $x;
+ return array($class, $method);
}
// Nothing else to do at this point but show a 404
@@ -359,7 +327,7 @@ class CI_Router {
$uri = implode('/', $this->uri->segments);
// Is there a literal match? If so we're done
- if (isset($this->routes[$uri]))
+ if (isset($this->routes[$uri]) && is_string($this->routes[$uri]))
{
return $this->_set_request(explode('/', $this->routes[$uri]));
}
@@ -371,10 +339,48 @@ class CI_Router {
$key = str_replace(array(':any', ':num'), array('[^/]+', '[0-9]+'), $key);
// Does the RegEx match?
- if (preg_match('#^'.$key.'$#', $uri))
+ if (preg_match('#^'.$key.'$#', $uri, $matches))
{
- // Do we have a back-reference?
- if (strpos($val, '$') !== FALSE && strpos($key, '(') !== FALSE)
+ // Are we using callbacks to process back-references?
+ if ( ! is_string($val) && is_callable($val))
+ {
+ // Remove the original string from the matches array.
+ array_shift($matches);
+
+ // Get the match count.
+ $match_count = count($matches);
+
+ // Determine how many parameters the callback has.
+ $reflection = new ReflectionFunction($val);
+ $param_count = $reflection->getNumberOfParameters();
+
+ // Are there more parameters than matches?
+ if ($param_count > $match_count)
+ {
+ // Any params without matches will be set to an empty string.
+ $matches = array_merge($matches, array_fill($match_count, $param_count - $match_count, ''));
+
+ $match_count = $param_count;
+ }
+
+ // Get the parameters so we can use their default values.
+ $params = $reflection->getParameters();
+
+ for ($m = 0; $m < $match_count; $m++)
+ {
+ // Is the match empty and does a default value exist?
+ if (empty($matches[$m]) && $params[$m]->isDefaultValueAvailable())
+ {
+ // Substitute the empty match for the default value.
+ $matches[$m] = $params[$m]->getDefaultValue();
+ }
+ }
+
+ // Execute the callback using the values in matches as its parameters.
+ $val = call_user_func_array($val, $matches);
+ }
+ // Are we using the default routing method for back-references?
+ elseif (strpos($val, '$') !== FALSE && strpos($key, '(') !== FALSE)
{
$val = preg_replace('#^'.$key.'$#', $val, $uri);
}
@@ -493,7 +499,7 @@ class CI_Router {
if (isset($routing['function']))
{
- $routing['function'] = ($routing['function'] == '') ? 'index' : $routing['function'];
+ $routing['function'] = empty($routing['function']) ? 'index' : $routing['function'];
$this->set_method($routing['function']);
}
}
diff --git a/system/core/Security.php b/system/core/Security.php
index 50d0ce052..b8e66c087 100644
--- a/system/core/Security.php
+++ b/system/core/Security.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Security Class
diff --git a/system/core/URI.php b/system/core/URI.php
index d67a35d4b..91740254c 100644
--- a/system/core/URI.php
+++ b/system/core/URI.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* URI Class
@@ -98,31 +99,28 @@ class CI_URI {
// Is the request coming from the command line?
if ($this->_is_cli_request())
{
- $this->_set_uri_string($this->_parse_cli_args());
+ $this->_set_uri_string($this->_parse_argv());
return;
}
- // Let's try the REQUEST_URI first, this will work in most situations
- if ($uri = $this->_detect_uri())
+ // Is there a PATH_INFO variable? This should be the easiest solution.
+ if (isset($_SERVER['PATH_INFO']))
{
- $this->_set_uri_string($uri);
+ $this->_set_uri_string($_SERVER['PATH_INFO']);
return;
}
- // Is there a PATH_INFO variable?
- // Note: some servers seem to have trouble with getenv() so we'll test it two ways
- $path = isset($_SERVER['PATH_INFO']) ? $_SERVER['PATH_INFO'] : @getenv('PATH_INFO');
- if (trim($path, '/') !== '' && $path !== '/'.SELF)
+ // Let's try REQUEST_URI then, this will work in most situations
+ if (($uri = $this->_parse_request_uri()) !== '')
{
- $this->_set_uri_string($path);
+ $this->_set_uri_string($uri);
return;
}
- // No PATH_INFO?... What about QUERY_STRING?
- $path = isset($_SERVER['QUERY_STRING']) ? $_SERVER['QUERY_STRING'] : @getenv('QUERY_STRING');
- if (trim($path, '/') !== '')
+ // No REQUEST_URI either?... What about QUERY_STRING?
+ if (($uri = $this->_parse_query_string()) !== '')
{
- $this->_set_uri_string($path);
+ $this->_set_uri_string($uri);
return;
}
@@ -140,19 +138,19 @@ class CI_URI {
$uri = strtoupper($this->config->item('uri_protocol'));
- if ($uri === 'REQUEST_URI')
+ if ($uri === 'CLI')
{
- $this->_set_uri_string($this->_detect_uri());
+ $this->_set_uri_string($this->_parse_argv());
return;
}
- elseif ($uri === 'CLI')
+ elseif (method_exists($this, ($method = '_parse_'.strtolower($uri))))
{
- $this->_set_uri_string($this->_parse_cli_args());
+ $this->_set_uri_string($this->$method());
return;
}
- $path = isset($_SERVER[$uri]) ? $_SERVER[$uri] : @getenv($uri);
- $this->_set_uri_string($path);
+ $uri = isset($_SERVER[$uri]) ? $_SERVER[$uri] : @getenv($uri);
+ $this->_set_uri_string($uri);
}
// --------------------------------------------------------------------
@@ -172,59 +170,54 @@ class CI_URI {
// --------------------------------------------------------------------
/**
- * Detects URI
+ * Parse REQUEST_URI
*
- * Will detect the URI automatically and fix the query string if necessary.
+ * Will parse REQUEST_URI and automatically detect the URI from it,
+ * while fixing the query string if necessary.
*
+ * @used-by CI_URI::_fetch_uri_string()
* @return string
*/
- protected function _detect_uri()
+ protected function _parse_request_uri()
{
if ( ! isset($_SERVER['REQUEST_URI'], $_SERVER['SCRIPT_NAME']))
{
return '';
}
- if (strpos($_SERVER['REQUEST_URI'], $_SERVER['SCRIPT_NAME']) === 0)
- {
- $uri = substr($_SERVER['REQUEST_URI'], strlen($_SERVER['SCRIPT_NAME']));
- }
- elseif (strpos($_SERVER['REQUEST_URI'], dirname($_SERVER['SCRIPT_NAME'])) === 0)
+ $uri = parse_url($_SERVER['REQUEST_URI']);
+ $query = isset($uri['query']) ? $uri['query'] : '';
+ $uri = isset($uri['path']) ? rawurldecode($uri['path']) : '';
+
+ if (strpos($uri, $_SERVER['SCRIPT_NAME']) === 0)
{
- $uri = substr($_SERVER['REQUEST_URI'], strlen(dirname($_SERVER['SCRIPT_NAME'])));
+ $uri = (string) substr($uri, strlen($_SERVER['SCRIPT_NAME']));
}
- else
+ elseif (strpos($uri, dirname($_SERVER['SCRIPT_NAME'])) === 0)
{
- $uri = $_SERVER['REQUEST_URI'];
+ $uri = (string) substr($uri, strlen(dirname($_SERVER['SCRIPT_NAME'])));
}
// This section ensures that even on servers that require the URI to be in the query string (Nginx) a correct
// URI is found, and also fixes the QUERY_STRING server var and $_GET array.
- if (strpos($uri, '?/') === 0)
+ if (trim($uri, '/') === '' && strncmp($query, '/', 1) === 0)
{
- $uri = substr($uri, 2);
- }
-
- $parts = explode('?', $uri, 2);
- $uri = $parts[0];
- if (isset($parts[1]))
- {
- $_SERVER['QUERY_STRING'] = $parts[1];
- parse_str($_SERVER['QUERY_STRING'], $_GET);
+ $query = explode('?', $query, 2);
+ $uri = rawurldecode($query[0]);
+ $_SERVER['QUERY_STRING'] = isset($query[1]) ? $query[1] : '';
}
else
{
- $_SERVER['QUERY_STRING'] = '';
- $_GET = array();
+ $_SERVER['QUERY_STRING'] = $query;
}
+ parse_str($_SERVER['QUERY_STRING'], $_GET);
+
if ($uri === '/' OR $uri === '')
{
return '/';
}
- $uri = parse_url('pseudo://hostname/'.$uri, PHP_URL_PATH);
-
// Do some final cleaning of the URI and return it
return str_replace(array('//', '../'), '/', trim($uri, '/'));
}
@@ -232,6 +225,36 @@ class CI_URI {
// --------------------------------------------------------------------
/**
+ * Parse QUERY_STRING
+ *
+ * Will parse QUERY_STRING and automatically detect the URI from it.
+ *
+ * @used-by CI_URI::_fetch_uri_string()
+ * @return string
+ */
+ protected function _parse_query_string()
+ {
+ $uri = isset($_SERVER['QUERY_STRING']) ? $_SERVER['QUERY_STRING'] : @getenv('QUERY_STRING');
+
+ if (trim($uri, '/') === '')
+ {
+ return '';
+ }
+ elseif (strncmp($uri, '/', 1) === 0)
+ {
+ $uri = explode('?', $uri, 2);
+ $_SERVER['QUERY_STRING'] = isset($uri[1]) ? $uri[1] : '';
+ $uri = rawurldecode($uri[0]);
+ }
+
+ parse_str($_SERVER['QUERY_STRING'], $_GET);
+
+ return str_replace(array('//', '../'), '/', trim($uri, '/'));
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
* Is CLI Request?
*
* Duplicate of method from the Input class to test to see if
@@ -255,10 +278,10 @@ class CI_URI {
*
* @return string
*/
- protected function _parse_cli_args()
+ protected function _parse_argv()
{
$args = array_slice($_SERVER['argv'], 1);
- return $args ? '/'.implode('/', $args) : '';
+ return $args ? implode('/', $args) : '';
}
// --------------------------------------------------------------------
@@ -278,7 +301,7 @@ class CI_URI {
{
// preg_quote() in PHP 5.3 escapes -, so the str_replace() and addition of - to preg_quote() is to maintain backwards
// compatibility as many are unaware of how characters in the permitted_uri_chars will be parsed as a regex pattern
- if ( ! preg_match('|^['.str_replace(array('\\-', '\-'), '-', preg_quote($this->config->item('permitted_uri_chars'), '-')).']+$|i', urldecode($str)))
+ if ( ! preg_match('|^['.str_replace(array('\\-', '\-'), '-', preg_quote($this->config->item('permitted_uri_chars'), '-')).']+$|i', $str))
{
show_error('The URI you submitted has disallowed characters.', 400);
}
@@ -673,7 +696,14 @@ class CI_URI {
*/
public function ruri_string()
{
- return implode('/', $this->rsegment_array());
+ global $RTR;
+
+ if (($dir = $RTR->fetch_directory()) === '/')
+ {
+ $dir = '';
+ }
+
+ return $dir.implode('/', $this->rsegment_array());
}
}
diff --git a/system/core/Utf8.php b/system/core/Utf8.php
index efe3c10dc..5bc2dd5c9 100644
--- a/system/core/Utf8.php
+++ b/system/core/Utf8.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 2.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Utf8 Class
diff --git a/system/database/DB.php b/system/database/DB.php
index d751325ce..f4062fa73 100644
--- a/system/database/DB.php
+++ b/system/database/DB.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Initialize the database
@@ -31,8 +32,10 @@
* @category Database
* @author EllisLab Dev Team
* @link http://codeigniter.com/user_guide/database/
- * @param string
- * @param bool Determines if query builder should be used or not
+ *
+ * @param string|string[] $params
+ * @param bool $query_builder_override
+ * Determines if query builder should be used or not
*/
function &DB($params = '', $query_builder_override = NULL)
{
@@ -47,18 +50,18 @@ function &DB($params = '', $query_builder_override = NULL)
}
include($file_path);
- //make packages contain database config files
- foreach(get_instance()->load->get_package_paths() as $path)
+ // Make packages contain database config files
+ foreach (get_instance()->load->get_package_paths() as $path)
{
if ($path !== APPPATH)
{
- if (file_exists ($file_path = $path.'config/'.ENVIRONMENT.'/database.php'))
+ if (file_exists($file_path = $path.'config/'.ENVIRONMENT.'/database.php'))
{
- include ($file_path);
+ include($file_path);
}
- elseif ( file_exists ($file_path = $path.'config/database.php'))
+ elseif (file_exists($file_path = $path.'config/database.php'))
{
- include ($file_path);
+ include($file_path);
}
}
}
@@ -82,12 +85,12 @@ function &DB($params = '', $query_builder_override = NULL)
}
elseif (is_string($params))
{
-
- /* parse the URL from the DSN string
- * Database settings can be passed as discreet
- * parameters or as a data source name in the first
- * parameter. DSNs must have this prototype:
- * $dsn = 'driver://username:password@hostname/database';
+ /**
+ * Parse the URL from the DSN string
+ * Database settings can be passed as discreet
+ * parameters or as a data source name in the first
+ * parameter. DSNs must have this prototype:
+ * $dsn = 'driver://username:password@hostname/database';
*/
if (($dsn = @parse_url($params)) === FALSE)
{
@@ -103,7 +106,7 @@ function &DB($params = '', $query_builder_override = NULL)
'database' => isset($dsn['path']) ? rawurldecode(substr($dsn['path'], 1)) : ''
);
- // were additional config items set?
+ // Were additional config items set?
if (isset($dsn['query']))
{
parse_str($dsn['query'], $extra);
@@ -148,11 +151,22 @@ function &DB($params = '', $query_builder_override = NULL)
require_once(BASEPATH.'database/DB_query_builder.php');
if ( ! class_exists('CI_DB'))
{
+ /**
+ * CI_DB
+ *
+ * Acts as an alias for both CI_DB_driver and CI_DB_query_builder.
+ *
+ * @see CI_DB_query_builder
+ * @see CI_DB_driver
+ */
class CI_DB extends CI_DB_query_builder { }
}
}
elseif ( ! class_exists('CI_DB'))
{
+ /**
+ * @ignore
+ */
class CI_DB extends CI_DB_driver { }
}
diff --git a/system/database/DB_cache.php b/system/database/DB_cache.php
index d07c755c6..1be80c5c7 100644
--- a/system/database/DB_cache.php
+++ b/system/database/DB_cache.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Database Cache Class
@@ -34,8 +35,24 @@
*/
class CI_DB_Cache {
+ /**
+ * CI Singleton
+ *
+ * @var object
+ */
public $CI;
- public $db; // allows passing of db object so that multiple database connections and returned db objects can be supported
+
+ /**
+ * Database object
+ *
+ * Allows passing of DB object so that multiple database connections
+ * and returned DB objects can be supported.
+ *
+ * @var object
+ */
+ public $db;
+
+ // --------------------------------------------------------------------
/**
* Constructor
@@ -58,7 +75,7 @@ class CI_DB_Cache {
/**
* Set Cache Directory Path
*
- * @param string the path to the cache directory
+ * @param string $path Path to the cache directory
* @return bool
*/
public function check_path($path = '')
@@ -94,7 +111,7 @@ class CI_DB_Cache {
* Retrieve a cached query
*
* The URI being requested will become the name of the cache sub-folder.
- * An MD5 hash of the SQL statement will become the cache file name
+ * An MD5 hash of the SQL statement will become the cache file name.
*
* @param string $sql
* @return string
@@ -153,8 +170,8 @@ class CI_DB_Cache {
/**
* Delete cache files within a particular directory
*
- * @param string $segment_one = ''
- * @param string $segment_two = ''
+ * @param string $segment_one
+ * @param string $segment_two
* @return void
*/
public function delete($segment_one = '', $segment_two = '')
@@ -182,7 +199,7 @@ class CI_DB_Cache {
*/
public function delete_all()
{
- delete_files($this->db->cachedir, TRUE, 0, TRUE);
+ delete_files($this->db->cachedir, TRUE, TRUE);
}
}
diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php
index e8286aaa1..dfaf0e0c1 100644
--- a/system/database/DB_driver.php
+++ b/system/database/DB_driver.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Database Driver Class
@@ -40,60 +41,314 @@
*/
abstract class CI_DB_driver {
+ /**
+ * Data Source Name / Connect string
+ *
+ * @var string
+ */
public $dsn;
+
+ /**
+ * Username
+ *
+ * @var string
+ */
public $username;
+
+ /**
+ * Password
+ *
+ * @var string
+ */
public $password;
+
+ /**
+ * Hostname
+ *
+ * @var string
+ */
public $hostname;
+
+ /**
+ * Database name
+ *
+ * @var string
+ */
public $database;
+
+ /**
+ * Database driver
+ *
+ * @var string
+ */
public $dbdriver = 'mysqli';
+
+ /**
+ * Sub-driver
+ *
+ * @used-by CI_DB_pdo_driver
+ * @var string
+ */
public $subdriver;
+
+ /**
+ * Table prefix
+ *
+ * @var string
+ */
public $dbprefix = '';
+
+ /**
+ * Character set
+ *
+ * @var string
+ */
public $char_set = 'utf8';
+
+ /**
+ * Collation
+ *
+ * @var string
+ */
public $dbcollat = 'utf8_general_ci';
- public $autoinit = TRUE; // Whether to automatically initialize the DB
+
+ /**
+ * Auto-init flag
+ *
+ * Whether to automatically initialize the DB connection.
+ *
+ * @var bool
+ */
+ public $autoinit = TRUE;
+
+ /**
+ * Encryption flag/data
+ *
+ * @var mixed
+ */
public $encrypt = FALSE;
+
+ /**
+ * Swap Prefix
+ *
+ * @var string
+ */
public $swap_pre = '';
+
+ /**
+ * Database port
+ *
+ * @var int
+ */
public $port = '';
+
+ /**
+ * Persistent connection flag
+ *
+ * @var bool
+ */
public $pconnect = FALSE;
+
+ /**
+ * Connection ID
+ *
+ * @var object|resource
+ */
public $conn_id = FALSE;
+
+ /**
+ * Result ID
+ *
+ * @var object|resource
+ */
public $result_id = FALSE;
+
+ /**
+ * Debug flag
+ *
+ * Whether to display error messages.
+ *
+ * @var bool
+ */
public $db_debug = FALSE;
+
+ /**
+ * Benchmark time
+ *
+ * @var int
+ */
public $benchmark = 0;
+
+ /**
+ * Executed queries count
+ *
+ * @var int
+ */
public $query_count = 0;
+
+ /**
+ * Bind marker
+ *
+ * Character used to identify values in a prepared statement.
+ *
+ * @var string
+ */
public $bind_marker = '?';
+
+ /**
+ * Save queries flag
+ *
+ * Whether to keep an in-memory history of queries for debugging purposes.
+ *
+ * @var bool
+ */
public $save_queries = TRUE;
+
+ /**
+ * Queries list
+ *
+ * @see CI_DB_driver::$save_queries
+ * @var string[]
+ */
public $queries = array();
+
+ /**
+ * Query times
+ *
+ * A list of times that queries took to execute.
+ *
+ * @var array
+ */
public $query_times = array();
+
+ /**
+ * Data cache
+ *
+ * An internal generic value cache.
+ *
+ * @var array
+ */
public $data_cache = array();
+ /**
+ * Transaction enabled flag
+ *
+ * @var bool
+ */
public $trans_enabled = TRUE;
+
+ /**
+ * Strict transaction mode flag
+ *
+ * @var bool
+ */
public $trans_strict = TRUE;
+
+ /**
+ * Transaction depth level
+ *
+ * @var int
+ */
protected $_trans_depth = 0;
- protected $_trans_status = TRUE; // Used with transactions to determine if a rollback should occur
+ /**
+ * Transaction status flag
+ *
+ * Used with transactions to determine if a rollback should occur.
+ *
+ * @var bool
+ */
+ protected $_trans_status = TRUE;
+
+ /**
+ * Cache On flag
+ *
+ * @var bool
+ */
public $cache_on = FALSE;
+
+ /**
+ * Cache directory path
+ *
+ * @var bool
+ */
public $cachedir = '';
+
+ /**
+ * Cache auto-delete flag
+ *
+ * @var bool
+ */
public $cache_autodel = FALSE;
- public $CACHE; // The cache class object
+ /**
+ * DB Cache object
+ *
+ * @see CI_DB_cache
+ * @var object
+ */
+ public $CACHE;
+
+ /**
+ * Protect identifiers flag
+ *
+ * @var bool
+ */
protected $_protect_identifiers = TRUE;
- protected $_reserved_identifiers = array('*'); // Identifiers that should NOT be escaped
- // clause and character used for LIKE escape sequences
+ /**
+ * List of reserved identifiers
+ *
+ * Identifiers that must NOT be escaped.
+ *
+ * @var string[]
+ */
+ protected $_reserved_identifiers = array('*');
+
+ /**
+ * Identifier escape character
+ *
+ * @var string
+ */
+ protected $_escape_char = '"';
+
+ /**
+ * ESCAPE statement string
+ *
+ * @var string
+ */
protected $_like_escape_str = " ESCAPE '%s' ";
+
+ /**
+ * ESCAPE character
+ *
+ * @var string
+ */
protected $_like_escape_chr = '!';
/**
- * The syntax to count rows is slightly different across different
- * database engines, so this string appears in each driver and is
- * used for the count_all() and count_all_results() functions.
+ * ORDER BY random keyword
+ *
+ * @var string
+ */
+ protected $_random_keyword = ' RAND()';
+
+ /**
+ * COUNT string
+ *
+ * @used-by CI_DB_driver::count_all()
+ * @used-by CI_DB_query_builder::count_all_results()
+ *
+ * @var string
*/
protected $_count_string = 'SELECT COUNT(*) AS ';
+ // --------------------------------------------------------------------
+
/**
- * Constructor
+ * Class constructor
*
- * @param array
+ * @param array $params
* @return void
*/
public function __construct($params)
@@ -981,7 +1236,7 @@ abstract class CI_DB_driver {
*/
public function escape_identifiers($item)
{
- if ($this->_escape_char === '' OR empty($item))
+ if ($this->_escape_char === '' OR empty($item) OR in_array($item, $this->_reserved_identifiers))
{
return $item;
}
@@ -1080,43 +1335,19 @@ abstract class CI_DB_driver {
*/
public function update_string($table, $data, $where)
{
- if ($where === '')
+ if (empty($where))
{
return FALSE;
}
+ $this->where($where);
+
$fields = array();
foreach ($data as $key => $val)
{
$fields[$this->protect_identifiers($key)] = $this->escape($val);
}
- if ( ! is_array($where))
- {
- $dest = array($where);
- }
- else
- {
- $dest = array();
- foreach ($where as $key => $val)
- {
- $prefix = (count($dest) === 0) ? '' : ' AND ';
- $key = $this->protect_identifiers($key);
-
- if ($val !== '')
- {
- if ( ! $this->_has_operator($key))
- {
- $key .= ' =';
- }
-
- $val = ' '.$this->escape($val);
- }
-
- $dest[] = $prefix.$key.$val;
- }
- }
-
return $this->_update($this->protect_identifiers($table, TRUE, NULL, FALSE), $fields, $dest);
}
@@ -1198,8 +1429,7 @@ abstract class CI_DB_driver {
/**
* Enables a native PHP function to be run, using a platform agnostic wrapper.
*
- * @param string $function the function name
- * @param mixed $param,... optional parameters needed by the function
+ * @param string $function Function name
* @return mixed
*/
public function call_function($function)
diff --git a/system/database/DB_forge.php b/system/database/DB_forge.php
index 119d78d38..21046012a 100644
--- a/system/database/DB_forge.php
+++ b/system/database/DB_forge.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Database Forge Class
@@ -34,27 +35,127 @@
*/
abstract class CI_DB_forge {
+ /**
+ * Database object
+ *
+ * @var object
+ */
+ protected $db;
+
+ /**
+ * Fields data
+ *
+ * @var array
+ */
public $fields = array();
+
+ /**
+ * Keys data
+ *
+ * @var array
+ */
public $keys = array();
+
+ /**
+ * Primary Keys data
+ *
+ * @var array
+ */
public $primary_keys = array();
+
+ /**
+ * Database character set
+ *
+ * @var string
+ */
public $db_char_set = '';
- // Platform specific SQL strings
+ // --------------------------------------------------------------------
+
+ /**
+ * CREATE DATABASE statement
+ *
+ * @var string
+ */
protected $_create_database = 'CREATE DATABASE %s';
+
+ /**
+ * DROP DATABASE statement
+ *
+ * @var string
+ */
protected $_drop_database = 'DROP DATABASE %s';
- protected $_drop_table = 'DROP TABLE IF EXISTS %s';
- protected $_rename_table = 'ALTER TABLE %s RENAME TO %s';
/**
- * Constructor
+ * CREATE TABLE statement
*
+ * @var string
+ */
+ protected $_create_table = "%s %s (%s\n)";
+
+ /**
+ * CREATE TABLE IF statement
+ *
+ * @var string
+ */
+ protected $_create_table_if = 'CREATE TABLE IF NOT EXISTS';
+
+ /**
+ * CREATE TABLE keys flag
+ *
+ * Whether table keys are created from within the
+ * CREATE TABLE statement.
+ *
+ * @var bool
+ */
+ protected $_create_table_keys = FALSE;
+
+ /**
+ * DROP TABLE IF EXISTS statement
+ *
+ * @var string
+ */
+ protected $_drop_table_if = 'DROP TABLE IF EXISTS';
+
+ /**
+ * RENAME TABLE statement
+ *
+ * @var string
+ */
+ protected $_rename_table = 'ALTER TABLE %s RENAME TO %s;';
+
+ /**
+ * UNSIGNED support
+ *
+ * @var bool|array
+ */
+ protected $_unsigned = TRUE;
+
+ /**
+ * NULL value representatin in CREATE/ALTER TABLE statements
+ *
+ * @var string
+ */
+ protected $_null = '';
+
+ /**
+ * DEFAULT value representation in CREATE/ALTER TABLE statements
+ *
+ * @var string
+ */
+ protected $_default = ' DEFAULT ';
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Class constructor
+ *
+ * @param object &$db Database object
* @return void
*/
- public function __construct()
+ public function __construct(&$db)
{
- // Assign the main database object to $this->db
- $CI =& get_instance();
- $this->db =& $CI->db;
+ $this->db =& $db;
log_message('debug', 'Database Forge Class Initialized');
}
@@ -63,14 +164,14 @@ abstract class CI_DB_forge {
/**
* Create database
*
- * @param string the database name
+ * @param string $db_name
* @return bool
*/
public function create_database($db_name)
{
if ($this->_create_database === FALSE)
{
- return ($this->db->db_debug) ? $this->db->display_error('db_unsuported_feature') : FALSE;
+ return ($this->db->db_debug) ? $this->db->display_error('db_unsupported_feature') : FALSE;
}
elseif ( ! $this->db->query(sprintf($this->_create_database, $db_name, $this->db->char_set, $this->db->dbcollat)))
{
@@ -90,7 +191,7 @@ abstract class CI_DB_forge {
/**
* Drop database
*
- * @param string the database name
+ * @param string $db_name
* @return bool
*/
public function drop_database($db_name)
@@ -102,7 +203,7 @@ abstract class CI_DB_forge {
}
elseif ($this->_drop_database === FALSE)
{
- return ($this->db->db_debug) ? $this->db->display_error('db_unsuported_feature') : FALSE;
+ return ($this->db->db_debug) ? $this->db->display_error('db_unsupported_feature') : FALSE;
}
elseif ( ! $this->db->query(sprintf($this->_drop_database, $db_name)))
{
@@ -126,25 +227,25 @@ abstract class CI_DB_forge {
/**
* Add Key
*
- * @param string key
- * @param string type
+ * @param string $key
+ * @param bool $primary
* @return object
*/
public function add_key($key = '', $primary = FALSE)
{
- if (is_array($key))
+ if (empty($key))
+ {
+ show_error('Key information is required for that operation.');
+ }
+
+ if ($primary === TRUE && is_array($key))
{
foreach ($key as $one)
{
$this->add_key($one, $primary);
}
- return;
- }
-
- if ($key === '')
- {
- show_error('Key information is required for that operation.');
+ return $this;
}
if ($primary === TRUE)
@@ -164,12 +265,12 @@ abstract class CI_DB_forge {
/**
* Add Field
*
- * @param string collation
+ * @param array $field
* @return object
*/
public function add_field($field = '')
{
- if ($field === '')
+ if (empty($field))
{
show_error('Field information is required.');
}
@@ -211,8 +312,8 @@ abstract class CI_DB_forge {
/**
* Create Table
*
- * @param string $table = ''
- * @param bool $if_not_exists = FALSE
+ * @param string $table Table name
+ * @param bool $if_not_exists Whether to add IF NOT EXISTS condition
* @return bool
*/
public function create_table($table = '', $if_not_exists = FALSE)
@@ -221,51 +322,129 @@ abstract class CI_DB_forge {
{
show_error('A table name is required for that operation.');
}
+ else
+ {
+ $table = $this->db->dbprefix.$table;
+ }
if (count($this->fields) === 0)
{
show_error('Field information is required.');
}
- $sql = $this->_create_table($this->db->dbprefix.$table, $this->fields, $this->primary_keys, $this->keys, $if_not_exists);
- $this->_reset();
+ $sql = $this->_create_table($table, $if_not_exists);
if (is_bool($sql))
{
- return $sql;
+ $this->_reset();
+ if ($sql === FALSE)
+ {
+ return ($this->db->db_debug) ? $this->db->display_error('db_unsupported_feature') : FALSE;
+ }
}
- if (($result = $this->db->query($sql)) !== FALSE && ! empty($this->db->data_cache['table_names']))
+ if (($result = $this->db->query($sql)) !== FALSE)
{
- $this->db->data_cache['table_names'][] = $this->db->dbprefix.$table;
+ empty($this->db->data_cache['table_names']) OR $this->db->data_cache['table_names'][] = $table;
+
+ // Most databases don't support creating indexes from within the CREATE TABLE statement
+ if ( ! empty($this->keys))
+ {
+ for ($i = 0, $sqls = $this->_process_indexes($table), $c = count($sqls); $i < $c; $i++)
+ {
+ $this->db->query($sqls[$i]);
+ }
+ }
}
+ $this->_reset();
return $result;
}
// --------------------------------------------------------------------
/**
+ * Create Table
+ *
+ * @param string $table Table name
+ * @param bool $if_not_exists Whether to add 'IF NOT EXISTS' condition
+ * @return mixed
+ */
+ protected function _create_table($table, $if_not_exists)
+ {
+ if ($if_not_exists === TRUE && $this->_create_table_if === FALSE)
+ {
+ if ($this->db->table_exists($table))
+ {
+ return TRUE;
+ }
+ else
+ {
+ $if_not_exists = FALSE;
+ }
+ }
+
+ $sql = ($if_not_exists)
+ ? sprintf($this->_create_table_if, $this->db->escape_identifiers($table))
+ : 'CREATE TABLE';
+
+ $columns = $this->_process_fields(TRUE);
+ for ($i = 0, $c = count($columns); $i < $c; $i++)
+ {
+ $columns[$i] = ($columns[$i]['_literal'] !== FALSE)
+ ? "\n\t".$columns[$i]['_literal']
+ : "\n\t".$this->_process_column($columns[$i]);
+ }
+
+ $columns = implode(',', $columns)
+ .$this->_process_primary_keys($table);
+
+ // Are indexes created from within the CREATE TABLE statement? (e.g. in MySQL)
+ if ($this->_create_table_keys === TRUE)
+ {
+ $columns .= $this->_process_indexes();
+ }
+
+ // _create_table will usually have the following format: "%s %s (%s\n)"
+ $sql = sprintf($this->_create_table.';',
+ $sql,
+ $this->db->escape_identifiers($table),
+ $columns
+ );
+
+ return $sql;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
* Drop Table
*
- * @param string the table name
+ * @param string $table_name Table name
+ * @param bool $if_exists Whether to add an IF EXISTS condition
* @return bool
*/
- public function drop_table($table_name)
+ public function drop_table($table_name, $if_exists = FALSE)
{
if ($table_name === '')
{
return ($this->db->db_debug) ? $this->db->display_error('db_table_name_required') : FALSE;
}
- elseif ($this->_drop_table === FALSE)
+
+ $query = $this->_drop_table($this->db->dbprefix.$table_name, $if_exists);
+ if ($query === FALSE)
{
- return ($this->db->db_debug) ? $this->db->display_error('db_unsuported_feature') : FALSE;
+ return ($this->db->db_debug) ? $this->db->display_error('db_unsupported_feature') : FALSE;
+ }
+ elseif ($query === TRUE)
+ {
+ return TRUE;
}
- $result = $this->db->query(sprintf($this->_drop_table, $this->db->escape_identifiers($this->db->dbprefix.$table_name)));
+ $query = $this->db->query($query);
// Update table list cache
- if ($result && ! empty($this->db->data_cache['table_names']))
+ if ($query && ! empty($this->db->data_cache['table_names']))
{
$key = array_search(strtolower($this->db->dbprefix.$table_name), array_map('strtolower', $this->db->data_cache['table_names']), TRUE);
if ($key !== FALSE)
@@ -274,7 +453,40 @@ abstract class CI_DB_forge {
}
}
- return $result;
+ return $query;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Drop Table
+ *
+ * Generates a platform-specific DROP TABLE string
+ *
+ * @param string $table Table name
+ * @param bool $if_exists Whether to add an IF EXISTS condition
+ * @return string
+ */
+ protected function _drop_table($table, $if_exists)
+ {
+ $sql = 'DROP TABLE';
+
+ if ($if_exists)
+ {
+ if ($this->_drop_table_if === FALSE)
+ {
+ if ( ! $this->db->table_exists($table))
+ {
+ return TRUE;
+ }
+ }
+ else
+ {
+ $sql = sprintf($this->_drop_table_if, $this->db->escape_identifiers($table));
+ }
+ }
+
+ return $sql.' '.$this->db->escape_identifiers($table);
}
// --------------------------------------------------------------------
@@ -282,8 +494,8 @@ abstract class CI_DB_forge {
/**
* Rename Table
*
- * @param string the old table name
- * @param string the new table name
+ * @param string $table_name Old table name
+ * @param string $new_table_name New table name
* @return bool
*/
public function rename_table($table_name, $new_table_name)
@@ -295,7 +507,7 @@ abstract class CI_DB_forge {
}
elseif ($this->_rename_table === FALSE)
{
- return ($this->db->db_debug) ? $this->db->display_error('db_unsuported_feature') : FALSE;
+ return ($this->db->db_debug) ? $this->db->display_error('db_unsupported_feature') : FALSE;
}
$result = $this->db->query(sprintf($this->_rename_table,
@@ -320,33 +532,46 @@ abstract class CI_DB_forge {
/**
* Column Add
*
- * @param string the table name
- * @param string the column name
- * @param string the column definition
+ * @todo Remove deprecated $_after option in 3.1+
+ * @param string $table Table name
+ * @param array $field Column definition
+ * @param string $_after Column for AFTER clause (deprecated)
* @return bool
*/
- public function add_column($table = '', $field = array(), $after_field = '')
+ public function add_column($table = '', $field = array(), $_after = NULL)
{
if ($table === '')
{
show_error('A table name is required for that operation.');
}
- // add field info into field array, but we can only do one at a time
- // so we cycle through
- foreach (array_keys($field) as $k)
+ // Work-around for literal column definitions
+ if ( ! is_array($field))
{
- $this->add_field(array($k => $field[$k]));
+ $field = array($field);
+ }
- if (count($this->fields) === 0)
+ foreach (array_keys($field) as $k)
+ {
+ // Backwards-compatibility work-around for MySQL/CUBRID AFTER clause (remove in 3.1+)
+ if ($_after !== NULL && is_array($field[$k]) && ! isset($field[$k]['after']))
{
- show_error('Field information is required.');
+ $field[$k]['after'] = $_after;
}
- $sql = $this->_alter_table('ADD', $this->db->dbprefix.$table, $this->fields, $after_field);
- $this->_reset();
+ $this->add_field(array($k => $field[$k]));
+ }
+
+ $sqls = $this->_alter_table('ADD', $this->db->dbprefix.$table, $this->_process_fields());
+ $this->_reset();
+ if ($sqls === FALSE)
+ {
+ return ($this->db->db_debug) ? $this->db->display_error('db_unsupported_feature') : FALSE;
+ }
- if ($this->db->query($sql) === FALSE)
+ for ($i = 0, $c = count($sqls); $i < $c; $i++)
+ {
+ if ($this->db->query($sqls[$i]) === FALSE)
{
return FALSE;
}
@@ -360,8 +585,8 @@ abstract class CI_DB_forge {
/**
* Column Drop
*
- * @param string the table name
- * @param string the column name
+ * @param string $table Table name
+ * @param string $column_name Column name
* @return bool
*/
public function drop_column($table = '', $column_name = '')
@@ -376,7 +601,13 @@ abstract class CI_DB_forge {
show_error('A column name is required for that operation.');
}
- return $this->db->query($this->_alter_table('DROP', $this->db->dbprefix.$table, $column_name));
+ $sql = $this->_alter_table('DROP', $this->db->dbprefix.$table, $column_name);
+ if ($sql === FALSE)
+ {
+ return ($this->db->db_debug) ? $this->db->display_error('db_unsupported_feature') : FALSE;
+ }
+
+ return $this->db->query($sql);
}
// --------------------------------------------------------------------
@@ -384,8 +615,8 @@ abstract class CI_DB_forge {
/**
* Column Modify
*
- * @param string $table = ''
- * @param string $field = array() column definition
+ * @param string $table Table name
+ * @param string $field Column definition
* @return bool
*/
public function modify_column($table = '', $field = array())
@@ -395,32 +626,363 @@ abstract class CI_DB_forge {
show_error('A table name is required for that operation.');
}
- // add field info into field array, but we can only do one at a time
- // so we cycle through
+ // Work-around for literal column definitions
+ if ( ! is_array($field))
+ {
+ $field = array($field);
+ }
+
foreach (array_keys($field) as $k)
{
- // If no name provided, use the current name
- if ( ! isset($field[$k]['name']))
+ $this->add_field(array($k => $field[$k]));
+ }
+
+ if (count($this->fields) === 0)
+ {
+ show_error('Field information is required.');
+ }
+
+ $sqls = $this->_alter_table('CHANGE', $this->db->dbprefix.$table, $this->fields);
+ $this->_reset();
+ if ($sqls === FALSE)
+ {
+ return ($this->db->db_debug) ? $this->db->display_error('db_unsupported_feature') : FALSE;
+ }
+
+ for ($i = 0, $c = count($sqls); $i < $c; $i++)
+ {
+ if ($this->db->query($sqls[$i]) === FALSE)
{
- $field[$k]['name'] = $k;
+ return FALSE;
}
+ }
- $this->add_field(array($k => $field[$k]));
- if (count($this->fields) === 0)
+ return TRUE;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * ALTER TABLE
+ *
+ * @param string $alter_type ALTER type
+ * @param string $table Table name
+ * @param mixed $field Column definition
+ * @return string|string[]
+ */
+ protected function _alter_table($alter_type, $table, $field)
+ {
+ $sql = 'ALTER TABLE '.$this->db->escape_identifiers($table).' ';
+
+ // DROP has everything it needs now.
+ if ($alter_type === 'DROP')
+ {
+ return $sql.'DROP COLUMN '.$this->db->escape_identifiers($field);
+ }
+
+ $sqls = array();
+ for ($i = 0, $c = count($field), $sql .= $alter_type.' COLUMN '; $i < $c; $i++)
+ {
+ $sqls[] = $sql
+ .($field[$i]['_literal'] !== FALSE ? $field[$i]['_literal'] : $this->_process_column($field[$i]));
+ }
+
+ return $sqls;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Process fields
+ *
+ * @param bool $create_table
+ * @return array
+ */
+ protected function _process_fields($create_table = FALSE)
+ {
+ $fields = array();
+
+ foreach ($this->fields as $key => $attributes)
+ {
+ if (is_int($key) && ! is_array($attributes))
{
- show_error('Field information is required.');
+ $fields[] = array('_literal' => $attributes);
+ continue;
}
- $sql = $this->_alter_table('CHANGE', $this->db->dbprefix.$table, $this->fields);
- $this->_reset();
+ $attributes = array_change_key_case($attributes, CASE_UPPER);
- if ($this->db->query($sql) === FALSE)
+ if ($create_table === TRUE && empty($attributes['TYPE']))
{
- return FALSE;
+ continue;
+ }
+
+ if (isset($attributes['TYPE']))
+ {
+ $this->_attr_type($attributes);
+ $this->_attr_unsigned($attributes, $field);
}
+
+ $field = array(
+ 'name' => $key,
+ 'new_name' => isset($attributes['NAME']) ? $attributes['NAME'] : NULL,
+ 'type' => isset($attributes['TYPE']) ? $attributes['TYPE'] : NULL,
+ 'length' => '',
+ 'unsigned' => '',
+ 'null' => '',
+ 'unique' => '',
+ 'default' => '',
+ 'auto_increment' => '',
+ '_literal' => FALSE
+ );
+
+ $this->_attr_default($attributes, $field);
+
+ if (isset($attributes['NULL']))
+ {
+ if ($attributes['NULL'] === TRUE)
+ {
+ $field['null'] = empty($this->_null) ? '' : ' '.$this->_null;
+ }
+ elseif ($create_table === TRUE)
+ {
+ $field['null'] = ' NOT NULL';
+ }
+ }
+
+ $this->_attr_auto_increment($attributes, $field);
+ $this->_attr_unique($attributes, $field);
+
+ if (isset($attributes['TYPE']) && ! empty($attributes['CONSTRAINT']))
+ {
+ switch (strtoupper($attributes['TYPE']))
+ {
+ case 'ENUM':
+ case 'SET':
+ $attributes['CONSTRAINT'] = $this->db->escape($attributes['CONSTRAINT']);
+ default:
+ $field['length'] = is_array($attributes['CONSTRAINT'])
+ ? '('.implode(',', $attributes['CONSTRAINT']).')'
+ : '('.$attributes['CONSTRAINT'].')';
+ break;
+ }
+ }
+
+ $fields[] = $field;
}
- return TRUE;
+ return $fields;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Process column
+ *
+ * @param array $field
+ * @return string
+ */
+ protected function _process_column($field)
+ {
+ return $this->db->escape_identifiers($field['name'])
+ .' '.$field['type'].$field['length']
+ .$field['unsigned']
+ .$field['default']
+ .$field['null']
+ .$field['auto_increment']
+ .$field['unique'];
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Field attribute TYPE
+ *
+ * Performs a data type mapping between different databases.
+ *
+ * @param array &$attributes
+ * @return void
+ */
+ protected function _attr_type(&$attributes)
+ {
+ // Usually overriden by drivers
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Field attribute UNSIGNED
+ *
+ * Depending on the _unsigned property value:
+ *
+ * - TRUE will always set $field['unsigned'] to 'UNSIGNED'
+ * - FALSE will always set $field['unsigned'] to ''
+ * - array(TYPE) will set $field['unsigned'] to 'UNSIGNED',
+ * if $attributes['TYPE'] is found in the array
+ * - array(TYPE => UTYPE) will change $field['type'],
+ * from TYPE to UTYPE in case of a match
+ *
+ * @param array &$attributes
+ * @param array &$field
+ * @return void
+ */
+ protected function _attr_unsigned(&$attributes, &$field)
+ {
+ if (empty($attributes['UNSIGNED']) OR $attributes['UNSIGNED'] !== TRUE)
+ {
+ return;
+ }
+
+ // Reset the attribute in order to avoid issues if we do type conversion
+ $attributes['UNSIGNED'] = FALSE;
+
+ if (is_array($this->_unsigned))
+ {
+ foreach (array_keys($this->_unsigned) as $key)
+ {
+ if (is_int($key) && strcasecmp($attributes['TYPE'], $this->_unsigned[$key]) === 0)
+ {
+ $field['unsigned'] = ' UNSIGNED';
+ return;
+ }
+ elseif (is_string($key) && strcasecmp($attributes['TYPE'], $key) === 0)
+ {
+ $field['type'] = $key;
+ return;
+ }
+ }
+
+ return;
+ }
+
+ $field['unsigned'] = ($this->_unsigned === TRUE) ? ' UNSIGNED' : '';
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Field attribute DEFAULT
+ *
+ * @param array &$attributes
+ * @param array &$field
+ * @return void
+ */
+ protected function _attr_default(&$attributes, &$field)
+ {
+ if ($this->_default === FALSE)
+ {
+ return;
+ }
+
+ if (array_key_exists('DEFAULT', $attributes))
+ {
+ if ($attributes['DEFAULT'] === NULL)
+ {
+ $field['default'] = empty($this->_null) ? '' : $this->_default.$this->_null;
+
+ // Override the NULL attribute if that's our default
+ $attributes['NULL'] = NULL;
+ $field['null'] = empty($this->_null) ? '' : ' '.$this->_null;
+ }
+ else
+ {
+ $field['default'] = $this->_default.$this->db->escape($attributes['DEFAULT']);
+ }
+ }
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Field attribute UNIQUE
+ *
+ * @param array &$attributes
+ * @param array &$field
+ * @return void
+ */
+ protected function _attr_unique(&$attributes, &$field)
+ {
+ if ( ! empty($attributes['UNIQUE']) && $attributes['UNIQUE'] === TRUE)
+ {
+ $field['unique'] = ' UNIQUE';
+ }
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Field attribute AUTO_INCREMENT
+ *
+ * @param array &$attributes
+ * @param array &$field
+ * @return void
+ */
+ protected function _attr_auto_increment(&$attributes, &$field)
+ {
+ if ( ! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === TRUE && stripos($field['type'], 'int') !== FALSE)
+ {
+ $field['auto_increment'] = ' AUTO_INCREMENT';
+ }
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Process primary keys
+ *
+ * @param string $table Table name
+ * @return string
+ */
+ protected function _process_primary_keys($table)
+ {
+ $sql = '';
+
+ for ($i = 0, $c = count($this->primary_keys); $i < $c; $i++)
+ {
+ if ( ! isset($this->fields[$this->primary_keys[$i]]))
+ {
+ unset($this->primary_keys[$i]);
+ }
+ }
+
+ if (count($this->primary_keys) > 0)
+ {
+ $sql .= ",\n\tCONSTRAINT ".$this->db->escape_identifiers('pk_'.$table)
+ .' PRIMARY KEY('.implode(', ', $this->db->escape_identifiers($this->primary_keys)).')';
+ }
+
+ return $sql;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Process indexes
+ *
+ * @param string $table
+ * @return string
+ */
+ protected function _process_indexes($table = NULL)
+ {
+ $table = $this->db->escape_identifiers($table);
+ $sqls = array();
+
+ for ($i = 0, $c = count($this->keys); $i < $c; $i++)
+ {
+ if ( ! isset($this->fields[$this->keys[$i]]))
+ {
+ unset($this->keys[$i]);
+ continue;
+ }
+
+ is_array($this->keys[$i]) OR $this->keys[$i] = array($this->keys[$i]);
+
+ $sqls[] = 'CREATE INDEX '.$this->db->escape_identifiers(implode('_', $this->keys[$i]))
+ .' ON '.$this->db->escape_identifiers($table)
+ .' ('.implode(', ', $this->db->escape_identifiers($this->keys[$i])).');';
+ }
+
+ return $sqls;
}
// --------------------------------------------------------------------
diff --git a/system/database/DB_query_builder.php b/system/database/DB_query_builder.php
index a3585586e..364397721 100644
--- a/system/database/DB_query_builder.php
+++ b/system/database/DB_query_builder.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Query Builder Class
@@ -39,42 +40,213 @@
abstract class CI_DB_query_builder extends CI_DB_driver {
+ /**
+ * Return DELETE SQL flag
+ *
+ * @var bool
+ */
protected $return_delete_sql = FALSE;
+
+ /**
+ * Reset DELETE data flag
+ *
+ * @var bool
+ */
protected $reset_delete_data = FALSE;
+ /**
+ * QB SELECT data
+ *
+ * @var array
+ */
protected $qb_select = array();
+
+ /**
+ * QB DISTINCT flag
+ *
+ * @var bool
+ */
protected $qb_distinct = FALSE;
+
+ /**
+ * QB FROM data
+ *
+ * @var array
+ */
protected $qb_from = array();
+
+ /**
+ * QB JOIN data
+ *
+ * @var array
+ */
protected $qb_join = array();
+
+ /**
+ * QB WHERE data
+ *
+ * @var array
+ */
protected $qb_where = array();
+
+ /**
+ * QB GROUP BY data
+ *
+ * @var array
+ */
protected $qb_groupby = array();
+
+ /**
+ * QB HAVING data
+ *
+ * @var array
+ */
protected $qb_having = array();
+
+ /**
+ * QB keys
+ *
+ * @var array
+ */
protected $qb_keys = array();
+
+ /**
+ * QB LIMIT data
+ *
+ * @var int
+ */
protected $qb_limit = FALSE;
+
+ /**
+ * QB OFFSET data
+ *
+ * @var int
+ */
protected $qb_offset = FALSE;
+
+ /**
+ * QB ORDER BY data
+ *
+ * @var array
+ */
protected $qb_orderby = array();
+
+ /**
+ * QB data sets
+ *
+ * @var array
+ */
protected $qb_set = array();
+
+ /**
+ * QB aliased tables list
+ *
+ * @var array
+ */
protected $qb_aliased_tables = array();
- protected $qb_store_array = array();
+
+ /**
+ * QB WHERE group started flag
+ *
+ * @var bool
+ */
protected $qb_where_group_started = FALSE;
+
+ /**
+ * QB WHERE group count
+ *
+ * @var int
+ */
protected $qb_where_group_count = 0;
// Query Builder Caching variables
+
+ /**
+ * QB Caching flag
+ *
+ * @var bool
+ */
protected $qb_caching = FALSE;
+
+ /**
+ * QB Cache exists list
+ *
+ * @var array
+ */
protected $qb_cache_exists = array();
+
+ /**
+ * QB Cache SELECT data
+ *
+ * @var array
+ */
protected $qb_cache_select = array();
+
+ /**
+ * QB Cache FROM data
+ *
+ * @var array
+ */
protected $qb_cache_from = array();
+
+ /**
+ * QB Cache JOIN data
+ *
+ * @var array
+ */
protected $qb_cache_join = array();
+
+ /**
+ * QB Cache WHERE data
+ *
+ * @var array
+ */
protected $qb_cache_where = array();
- protected $qb_cache_like = array();
+
+ /**
+ * QB Cache GROUP BY data
+ *
+ * @var array
+ */
protected $qb_cache_groupby = array();
+
+ /**
+ * QB Cache HAVING data
+ *
+ * @var array
+ */
protected $qb_cache_having = array();
+
+ /**
+ * QB Cache ORDER BY data
+ *
+ * @var array
+ */
protected $qb_cache_orderby = array();
+
+ /**
+ * QB Cache data sets
+ *
+ * @var array
+ */
protected $qb_cache_set = array();
+ /**
+ * QB No Escape data
+ *
+ * @var array
+ */
protected $qb_no_escape = array();
+
+ /**
+ * QB Cache No Escape data
+ *
+ * @var array
+ */
protected $qb_cache_no_escape = array();
+ // --------------------------------------------------------------------
+
/**
* Select
*
@@ -182,17 +354,16 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
// --------------------------------------------------------------------
/**
- * Processing Function for the following functions:
- *
- * select_max()
- * select_min()
- * select_avg()
- * select_sum()
+ * SELECT [MAX|MIN|AVG|SUM]()
*
+ * @used-by select_max()
+ * @used-by select_min()
+ * @used-by select_avg()
+ * @used-by select_sum()
*
- * @param string $select = '' field name
- * @param string $alias = ''
- * @param string $type = 'MAX'
+ * @param string $select Field name
+ * @param string $alias
+ * @param string $type
* @return object
*/
protected function _max_min_avg_sum($select = '', $alias = '', $type = 'MAX')
@@ -233,7 +404,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
/**
* Determines the alias name based on the table
*
- * @param string
+ * @param string $item
* @return string
*/
protected function _create_alias_from_table($item)
@@ -254,7 +425,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
*
* Sets a flag which tells the query string compiler to add DISTINCT
*
- * @param bool
+ * @param bool $val
* @return object
*/
public function distinct($val = TRUE)
@@ -270,7 +441,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
*
* Generates the FROM portion of the query
*
- * @param mixed can be a string or array
+ * @param mixed $from can be a string or array
* @return object
*/
public function from($from)
@@ -317,7 +488,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
// --------------------------------------------------------------------
/**
- * Join
+ * JOIN
*
* Generates the JOIN portion of the query
*
@@ -405,10 +576,10 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
// --------------------------------------------------------------------
/**
- * Where
+ * WHERE
*
- * Generates the WHERE portion of the query. Separates
- * multiple calls with AND
+ * Generates the WHERE portion of the query.
+ * Separates multiple calls with 'AND'.
*
* @param mixed
* @param mixed
@@ -423,10 +594,10 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
// --------------------------------------------------------------------
/**
- * OR Where
+ * OR WHERE
*
- * Generates the WHERE portion of the query. Separates
- * multiple calls with OR
+ * Generates the WHERE portion of the query.
+ * Separates multiple calls with 'OR'.
*
* @param mixed
* @param mixed
@@ -443,13 +614,16 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
/**
* WHERE, HAVING
*
- * Called by where(), or_where(), having(), or_having()
+ * @used-by where()
+ * @used-by or_where()
+ * @used-by having()
+ * @used-by or_having()
*
- * @param string 'qb_where' or 'qb_having'
- * @param mixed
- * @param mixed
- * @param string
- * @param bool
+ * @param string $qb_key 'qb_where' or 'qb_having'
+ * @param mixed $key
+ * @param mixed $value
+ * @param string $type
+ * @param bool $escape
* @return object
*/
protected function _wh($qb_key, $key, $value = NULL, $type = 'AND ', $escape = NULL)
@@ -504,14 +678,14 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
// --------------------------------------------------------------------
/**
- * Where_in
+ * WHERE IN
*
- * Generates a WHERE field IN('item', 'item') SQL query joined with
- * AND if appropriate
+ * Generates a WHERE field IN('item', 'item') SQL query,
+ * joined with 'AND' if appropriate.
*
- * @param string $key = NULL The field to search
- * @param array $values = NULL The values searched on
- * @param bool $escape = NULL
+ * @param string $key The field to search
+ * @param array $values The values searched on
+ * @param bool $escape
* @return object
*/
public function where_in($key = NULL, $values = NULL, $escape = NULL)
@@ -522,14 +696,14 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
// --------------------------------------------------------------------
/**
- * Or_where_in
+ * OR WHERE IN
*
- * Generates a WHERE field IN('item', 'item') SQL query joined with
- * OR if appropriate
+ * Generates a WHERE field IN('item', 'item') SQL query,
+ * joined with 'OR' if appropriate.
*
- * @param string $key = NULL The field to search
- * @param array $values = NULL The values searched on
- * @param bool $escape = NULL
+ * @param string $key The field to search
+ * @param array $values The values searched on
+ * @param bool $escape
* @return object
*/
public function or_where_in($key = NULL, $values = NULL, $escape = NULL)
@@ -540,14 +714,14 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
// --------------------------------------------------------------------
/**
- * Where_not_in
+ * WHERE NOT IN
*
- * Generates a WHERE field NOT IN('item', 'item') SQL query joined
- * with AND if appropriate
+ * Generates a WHERE field NOT IN('item', 'item') SQL query,
+ * joined with 'AND' if appropriate.
*
- * @param string $key = NULL The field to search
- * @param array $values = NULL The values searched on
- * @param bool $escape = NULL
+ * @param string $key The field to search
+ * @param array $values The values searched on
+ * @param bool $escape
* @return object
*/
public function where_not_in($key = NULL, $values = NULL, $escape = NULL)
@@ -558,14 +732,14 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
// --------------------------------------------------------------------
/**
- * Or_where_not_in
+ * OR WHERE NOT IN
*
- * Generates a WHERE field NOT IN('item', 'item') SQL query joined
- * with OR if appropriate
+ * Generates a WHERE field NOT IN('item', 'item') SQL query,
+ * joined with 'OR' if appropriate.
*
- * @param string $key = NULL The field to search
- * @param array $values = NULL The values searched on
- * @param bool $escape = NULL
+ * @param string $key The field to search
+ * @param array $values The values searched on
+ * @param bool $escape
* @return object
*/
public function or_where_not_in($key = NULL, $values = NULL, $escape = NULL)
@@ -576,15 +750,18 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
// --------------------------------------------------------------------
/**
- * Where_in
+ * Internal WHERE IN
*
- * Called by where_in(), or_where_in(), where_not_in(), or_where_not_in()
+ * @used-by where_in()
+ * @used-by or_where_in()
+ * @used-by where_not_in()
+ * @used-by or_where_not_in()
*
- * @param string $key = NULL The field to search
- * @param array $values = NULL The values searched on
- * @param bool $not = FALSE If the statement would be IN or NOT IN
- * @param string $type = 'AND '
- * @param bool $escape = NULL
+ * @param string $key The field to search
+ * @param array $values The values searched on
+ * @param bool $not If the statement would be IN or NOT IN
+ * @param string $type
+ * @param bool $escape
* @return object
*/
protected function _where_in($key = NULL, $values = NULL, $not = FALSE, $type = 'AND ', $escape = NULL)
@@ -628,15 +805,15 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
// --------------------------------------------------------------------
/**
- * Like
+ * LIKE
*
- * Generates a %LIKE% portion of the query. Separates
- * multiple calls with AND
+ * Generates a %LIKE% portion of the query.
+ * Separates multiple calls with 'AND'.
*
- * @param mixed
- * @param string
- * @param string
- * @param bool
+ * @param mixed $field
+ * @param string $match
+ * @param string $side
+ * @param bool $escape
* @return object
*/
public function like($field, $match = '', $side = 'both', $escape = NULL)
@@ -647,15 +824,15 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
// --------------------------------------------------------------------
/**
- * Not Like
+ * NOT LIKE
*
- * Generates a NOT LIKE portion of the query. Separates
- * multiple calls with AND
+ * Generates a NOT LIKE portion of the query.
+ * Separates multiple calls with 'AND'.
*
- * @param mixed
- * @param string
- * @param string
- * @param bool
+ * @param mixed $field
+ * @param string $match
+ * @param string $side
+ * @param bool $escape
* @return object
*/
public function not_like($field, $match = '', $side = 'both', $escape = NULL)
@@ -666,15 +843,15 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
// --------------------------------------------------------------------
/**
- * OR Like
+ * OR LIKE
*
- * Generates a %LIKE% portion of the query. Separates
- * multiple calls with OR
+ * Generates a %LIKE% portion of the query.
+ * Separates multiple calls with 'OR'.
*
- * @param mixed
- * @param string
- * @param string
- * @param bool
+ * @param mixed $field
+ * @param string $match
+ * @param string $side
+ * @param bool $escape
* @return object
*/
public function or_like($field, $match = '', $side = 'both', $escape = NULL)
@@ -685,15 +862,15 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
// --------------------------------------------------------------------
/**
- * OR Not Like
+ * OR NOT LIKE
*
- * Generates a NOT LIKE portion of the query. Separates
- * multiple calls with OR
+ * Generates a NOT LIKE portion of the query.
+ * Separates multiple calls with 'OR'.
*
- * @param mixed
- * @param string
- * @param string
- * @param bool
+ * @param mixed $field
+ * @param string $match
+ * @param string $side
+ * @param bool $escape
* @return object
*/
public function or_not_like($field, $match = '', $side = 'both', $escape = NULL)
@@ -704,16 +881,19 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
// --------------------------------------------------------------------
/**
- * Like
+ * Internal LIKE
*
- * Called by like(), or_like(), not_like, or_not_like()
+ * @used-by like()
+ * @used-by or_like()
+ * @used-by not_like()
+ * @used-by or_not_like()
*
- * @param mixed
- * @param string
- * @param string
- * @param string
- * @param string
- * @param bool
+ * @param mixed $field
+ * @param string $match
+ * @param string $type
+ * @param string $side
+ * @param string $not
+ * @param bool $escape
* @return object
*/
protected function _like($field, $match = '', $type = 'AND ', $side = 'both', $not = '', $escape = NULL)
@@ -770,8 +950,8 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
/**
* Starts a query group.
*
- * @param string (Internal use only)
- * @param string (Internal use only)
+ * @param string $not (Internal use only)
+ * @param string $type (Internal use only)
* @return object
*/
public function group_start($not = '', $type = 'AND ')
@@ -859,9 +1039,12 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
/**
* Group_get_type
*
- * Called by group_start(), _like(), _where() and _where_in()
+ * @used-by group_start()
+ * @used-by _like()
+ * @used-by _wh()
+ * @used-by _where_in()
*
- * @param string
+ * @param string $type
* @return string
*/
protected function _group_get_type($type)
@@ -880,8 +1063,8 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
/**
* GROUP BY
*
- * @param string
- * @param bool
+ * @param string $by
+ * @param bool $escape
* @return object
*/
public function group_by($by, $escape = NULL)
@@ -918,13 +1101,13 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
// --------------------------------------------------------------------
/**
- * Sets the HAVING value
+ * HAVING
*
- * Separates multiple calls with AND
+ * Separates multiple calls with 'AND'.
*
- * @param string
- * @param string
- * @param bool
+ * @param string $key
+ * @param string $value
+ * @param bool $escape
* @return object
*/
public function having($key, $value = NULL, $escape = NULL)
@@ -935,13 +1118,13 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
// --------------------------------------------------------------------
/**
- * Sets the OR HAVING value
+ * OR HAVING
*
- * Separates multiple calls with OR
+ * Separates multiple calls with 'OR'.
*
- * @param string
- * @param string
- * @param bool
+ * @param string $key
+ * @param string $value
+ * @param bool $escape
* @return object
*/
public function or_having($key, $value = NULL, $escape = NULL)
@@ -952,11 +1135,11 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
// --------------------------------------------------------------------
/**
- * Sets the ORDER BY value
+ * ORDER BY
*
- * @param string
- * @param string direction: ASC or DESC
- * @param bool enable field name escaping
+ * @param string $orderby
+ * @param string $direction ASC or DESC
+ * @param bool $escape
* @return object
*/
public function order_by($orderby, $direction = '', $escape = NULL)
@@ -1008,10 +1191,10 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
// --------------------------------------------------------------------
/**
- * Sets the LIMIT value
+ * LIMIT
*
- * @param int the limit value
- * @param int the offset value
+ * @param int $value LIMIT value
+ * @param int $offset OFFSET value
* @return object
*/
public function limit($value, $offset = FALSE)
@@ -1027,7 +1210,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
/**
* Sets the OFFSET value
*
- * @param int the offset value
+ * @param int $offset OFFSET value
* @return object
*/
public function offset($offset)
@@ -1039,11 +1222,11 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
// --------------------------------------------------------------------
/**
- * Limit string
+ * LIMIT string
*
- * Generates a platform-specific LIMIT clause
+ * Generates a platform-specific LIMIT clause.
*
- * @param string the sql query string
+ * @param string $sql SQL Query
* @return string
*/
protected function _limit($sql)
@@ -1183,10 +1366,10 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
*
* Allows the where clause, limit and offset to be added directly
*
- * @param string $table = ''
- * @param string $where = NULL
- * @param int $limit = NULL
- * @param int $offset = NULL
+ * @param string $table
+ * @param string $where
+ * @param int $limit
+ * @param int $offset
* @return object
*/
public function get_where($table = '', $where = NULL, $limit = NULL, $offset = NULL)
@@ -1218,15 +1401,16 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
*
* Compiles batch insert strings and runs the queries
*
- * @param string $table = '' table to insert into
- * @param array $set an associative array of insert values
- * @return int number of rows inserted or FALSE on failure
+ * @param string $table Table to insert into
+ * @param array $set An associative array of insert values
+ * @param bool $escape Whether to escape values and identifiers
+ * @return int Number of rows inserted or FALSE on failure
*/
- public function insert_batch($table = '', $set = NULL)
+ public function insert_batch($table = '', $set = NULL, $escape = NULL)
{
if ( ! is_null($set))
{
- $this->set_insert_batch($set);
+ $this->set_insert_batch($set, '', $escape);
}
if (count($this->qb_set) === 0)
@@ -1249,7 +1433,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
$affected_rows = 0;
for ($i = 0, $total = count($this->qb_set); $i < $total; $i += 100)
{
- $this->query($this->_insert_batch($this->protect_identifiers($table, TRUE, NULL, FALSE), $this->qb_keys, array_slice($this->qb_set, $i, 100)));
+ $this->query($this->_insert_batch($this->protect_identifiers($table, TRUE, $escape, FALSE), $this->qb_keys, array_slice($this->qb_set, $i, 100)));
$affected_rows += $this->affected_rows();
}
@@ -1260,13 +1444,13 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
// --------------------------------------------------------------------
/**
- * Insert_batch statement
+ * Insert batch statement
*
* Generates a platform-specific insert string from the supplied data.
*
- * @param string the table name
- * @param array the insert keys
- * @param array the insert values
+ * @param string $table Table name
+ * @param array $keys INSERT keys
+ * @param array $values INSERT values
* @return string
*/
protected function _insert_batch($table, $keys, $values)
@@ -1375,13 +1559,14 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
*
* @param string the table to insert data into
* @param array an associative array of insert values
+ * @param bool $escape Whether to escape values and identifiers
* @return object
*/
- public function insert($table = '', $set = NULL)
+ public function insert($table = '', $set = NULL, $escape = NULL)
{
if ( ! is_null($set))
{
- $this->set($set);
+ $this->set($set, '', $escape);
}
if ($this->_validate_insert($table) === FALSE)
@@ -1391,7 +1576,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
$sql = $this->_insert(
$this->protect_identifiers(
- $this->qb_from[0], TRUE, NULL, FALSE
+ $this->qb_from[0], TRUE, $escape, FALSE
),
array_keys($this->qb_set),
array_values($this->qb_set)
@@ -1539,14 +1724,14 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
// --------------------------------------------------------------------
/**
- * Update
+ * UPDATE
*
- * Compiles an update string and runs the query
+ * Compiles an update string and runs the query.
*
- * @param string $table = ''
- * @param array $set = NULL an associative array of update values
- * @param mixed $where = NULL
- * @param int $limit = NULL
+ * @param string $table
+ * @param array $set An associative array of update values
+ * @param mixed $where
+ * @param int $limit
* @return object
*/
public function update($table = '', $set = NULL, $where = NULL, $limit = NULL)
@@ -1575,7 +1760,6 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
}
$sql = $this->_update($this->protect_identifiers($this->qb_from[0], TRUE, NULL, FALSE), $this->qb_set);
-
$this->_reset_write();
return $this->query($sql);
}
@@ -1980,7 +2164,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
* Generates a query string based on which functions were used.
* Should not be called directly.
*
- * @param bool $select_override = FALSE
+ * @param bool $select_override
* @return string
*/
protected function _compile_select($select_override = FALSE)
@@ -2053,7 +2237,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
* where(), or_where(), having(), or_having are called prior to from(),
* join() and dbprefix is added only if needed.
*
- * @param string 'qb_where' or 'qb_having'
+ * @param string $qb_key 'qb_where' or 'qb_having'
* @return string SQL statement
*/
protected function _compile_wh($qb_key)
@@ -2291,7 +2475,6 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
'qb_cache_from' => array(),
'qb_cache_join' => array(),
'qb_cache_where' => array(),
- 'qb_cache_like' => array(),
'qb_cache_groupby' => array(),
'qb_cache_having' => array(),
'qb_cache_orderby' => array(),
@@ -2398,10 +2581,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
{
foreach ($qb_reset_items as $item => $default_value)
{
- if ( ! in_array($item, $this->qb_store_array))
- {
- $this->$item = $default_value;
- }
+ $this->$item = $default_value;
}
}
diff --git a/system/database/DB_result.php b/system/database/DB_result.php
index 76093f918..9d19075ba 100644
--- a/system/database/DB_result.php
+++ b/system/database/DB_result.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Database Result Class
@@ -38,19 +39,68 @@
*/
class CI_DB_result {
+ /**
+ * Connection ID
+ *
+ * @var resource|object
+ */
public $conn_id;
+
+ /**
+ * Result ID
+ *
+ * @var resource|object
+ */
public $result_id;
+
+ /**
+ * Result Array
+ *
+ * @var array[]
+ */
public $result_array = array();
+
+ /**
+ * Result Object
+ *
+ * @var object[]
+ */
public $result_object = array();
+
+ /**
+ * Custom Result Object
+ *
+ * @var object[]
+ */
public $custom_result_object = array();
+
+ /**
+ * Current Row index
+ *
+ * @var int
+ */
public $current_row = 0;
+
+ /**
+ * Number of rows
+ *
+ * @var int
+ */
public $num_rows;
+
+ /**
+ * Row data
+ *
+ * @var array
+ */
public $row_data;
+ // --------------------------------------------------------------------
+
/**
* Constructor
*
- * @param object
+ * @param object $driver_object
* @return void
*/
public function __construct(&$driver_object)
@@ -89,7 +139,7 @@ class CI_DB_result {
/**
* Query result. Acts as a wrapper function for the following functions.
*
- * @param string 'object', 'array' or a custom class name
+ * @param string $type 'object', 'array' or a custom class name
* @return array
*/
public function result($type = 'object')
@@ -113,8 +163,8 @@ class CI_DB_result {
/**
* Custom query result.
*
- * @param string A string that represents the type of object you want back
- * @return array of objects
+ * @param string $class_name
+ * @return array
*/
public function custom_result_object($class_name)
{
@@ -249,10 +299,12 @@ class CI_DB_result {
// --------------------------------------------------------------------
/**
- * Query result. Acts as a wrapper function for the following functions.
+ * Row
+ *
+ * A wrapper method.
*
- * @param mixed $n = 0
- * @param string $type = 'object' 'object' or 'array'
+ * @param mixed $n
+ * @param string $type 'object' or 'array'
* @return mixed
*/
public function row($n = 0, $type = 'object')
@@ -339,7 +391,7 @@ class CI_DB_result {
/**
* Returns a single result row - object version
*
- * @param int $n = 0
+ * @param int $n
* @return object
*/
public function row_object($n = 0)
@@ -363,7 +415,7 @@ class CI_DB_result {
/**
* Returns a single result row - array version
*
- * @param int $n = 0
+ * @param int $n
* @return array
*/
public function row_array($n = 0)
@@ -387,7 +439,7 @@ class CI_DB_result {
/**
* Returns the "first" row
*
- * @param string $type = 'object'
+ * @param string $type
* @return mixed
*/
public function first_row($type = 'object')
@@ -401,7 +453,7 @@ class CI_DB_result {
/**
* Returns the "last" row
*
- * @param string $type = 'object'
+ * @param string $type
* @return mixed
*/
public function last_row($type = 'object')
@@ -415,7 +467,7 @@ class CI_DB_result {
/**
* Returns the "next" row
*
- * @param string $type = 'object'
+ * @param string $type
* @return mixed
*/
public function next_row($type = 'object')
@@ -439,7 +491,7 @@ class CI_DB_result {
/**
* Returns the "previous" row
*
- * @param string $type = 'object'
+ * @param string $type
* @return mixed
*/
public function previous_row($type = 'object')
@@ -462,7 +514,7 @@ class CI_DB_result {
/**
* Returns an unbuffered row and move pointer to next row
*
- * @param string $type = 'object' 'array', 'object' or a custom class name
+ * @param string $type 'array', 'object' or a custom class name
* @return mixed
*/
public function unbuffered_row($type = 'object')
@@ -482,7 +534,7 @@ class CI_DB_result {
// --------------------------------------------------------------------
/**
- * The following functions are normally overloaded by the identically named
+ * The following methods are normally overloaded by the identically named
* methods in the platform-specific driver -- except when query caching
* is used. When caching is enabled we do not load the other driver.
* These functions are primarily here to prevent undefined function errors
@@ -490,13 +542,118 @@ class CI_DB_result {
* operational due to the unavailability of the database resource IDs with
* cached results.
*/
- public function num_fields() { return 0; }
- public function list_fields() { return array(); }
- public function field_data() { return array(); }
- public function free_result() { $this->result_id = FALSE; }
- protected function _data_seek() { return FALSE; }
- protected function _fetch_assoc() { return array(); }
- protected function _fetch_object() { return array(); }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Number of fields in the result set
+ *
+ * Overriden by driver result classes.
+ *
+ * @return int
+ */
+ public function num_fields()
+ {
+ return 0;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Fetch Field Names
+ *
+ * Generates an array of column names.
+ *
+ * Overriden by driver result classes.
+ *
+ * @return array
+ */
+ public function list_fields()
+ {
+ return array();
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Field data
+ *
+ * Generates an array of objects containing field meta-data.
+ *
+ * Overriden by driver result classes.
+ *
+ * @return array
+ */
+ public function field_data()
+ {
+ return array();
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Free the result
+ *
+ * Overriden by driver result classes.
+ *
+ * @return void
+ */
+ public function free_result()
+ {
+ $this->result_id = FALSE;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Data Seek
+ *
+ * Moves the internal pointer to the desired offset. We call
+ * this internally before fetching results to make sure the
+ * result set starts at zero.
+ *
+ * Overriden by driver result classes.
+ *
+ * @param int $n
+ * @return bool
+ */
+ protected function _data_seek($n = 0)
+ {
+ return FALSE;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Result - associative array
+ *
+ * Returns the result set as an array.
+ *
+ * Overriden by driver result classes.
+ *
+ * @return array
+ */
+ protected function _fetch_assoc()
+ {
+ return array();
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Result - object
+ *
+ * Returns the result set as an object.
+ *
+ * Overriden by driver result classes.
+ *
+ * @param string $class_name
+ * @return object
+ */
+ protected function _fetch_object($class_name = 'stdClass')
+ {
+ return array();
+ }
}
diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php
index 8078e2bf6..488ebf3ac 100644
--- a/system/database/DB_utility.php
+++ b/system/database/DB_utility.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Database Utility Class
@@ -32,25 +33,49 @@
* @author EllisLab Dev Team
* @link http://codeigniter.com/user_guide/database/
*/
-abstract class CI_DB_utility extends CI_DB_forge {
+abstract class CI_DB_utility {
- public $db;
+ /**
+ * Database object
+ *
+ * @var object
+ */
+ protected $db;
+
+ // --------------------------------------------------------------------
- // Platform specific SQL strings
- // Just setting those defaults to FALSE as they are mostly MySQL-specific
+ /**
+ * List databases statement
+ *
+ * @var string
+ */
+ protected $_list_databases = FALSE;
+
+ /**
+ * OPTIMIZE TABLE statement
+ *
+ * @var string
+ */
protected $_optimize_table = FALSE;
+
+ /**
+ * REPAIR TABLE statement
+ *
+ * @var string
+ */
protected $_repair_table = FALSE;
+ // --------------------------------------------------------------------
+
/**
- * Constructor
+ * Class constructor
*
+ * @param object &$db Database object
* @return void
*/
- public function __construct()
+ public function __construct(&$db)
{
- // Assign the main database object to $this->db
- $CI =& get_instance();
- $this->db =& $CI->db;
+ $this->db =& $db;
log_message('debug', 'Database Utility Class Initialized');
}
@@ -70,7 +95,7 @@ abstract class CI_DB_utility extends CI_DB_forge {
}
elseif ($this->_list_databases === FALSE)
{
- return ($this->db->db_debug) ? $this->db->display_error('db_unsuported_feature') : FALSE;
+ return ($this->db->db_debug) ? $this->db->display_error('db_unsupported_feature') : FALSE;
}
$this->db->data_cache['db_names'] = array();
@@ -94,7 +119,7 @@ abstract class CI_DB_utility extends CI_DB_forge {
/**
* Determine if a particular database exists
*
- * @param string
+ * @param string $database_name
* @return bool
*/
public function database_exists($database_name)
@@ -107,14 +132,14 @@ abstract class CI_DB_utility extends CI_DB_forge {
/**
* Optimize Table
*
- * @param string the table name
+ * @param string $table_name
* @return mixed
*/
public function optimize_table($table_name)
{
if ($this->_optimize_table === FALSE)
{
- return ($this->db->db_debug) ? $this->db->display_error('db_unsuported_feature') : FALSE;
+ return ($this->db->db_debug) ? $this->db->display_error('db_unsupported_feature') : FALSE;
}
$query = $this->db->query(sprintf($this->_optimize_table, $this->db->escape_identifiers($table_name)));
@@ -138,7 +163,7 @@ abstract class CI_DB_utility extends CI_DB_forge {
{
if ($this->_optimize_table === FALSE)
{
- return ($this->db->db_debug) ? $this->db->display_error('db_unsuported_feature') : FALSE;
+ return ($this->db->db_debug) ? $this->db->display_error('db_unsupported_feature') : FALSE;
}
$result = array();
@@ -168,14 +193,14 @@ abstract class CI_DB_utility extends CI_DB_forge {
/**
* Repair Table
*
- * @param string the table name
+ * @param string $table_name
* @return mixed
*/
public function repair_table($table_name)
{
if ($this->_repair_table === FALSE)
{
- return ($this->db->db_debug) ? $this->db->display_error('db_unsuported_feature') : FALSE;
+ return ($this->db->db_debug) ? $this->db->display_error('db_unsupported_feature') : FALSE;
}
$query = $this->db->query(sprintf($this->_repair_table, $this->db->escape_identifiers($table_name)));
@@ -193,10 +218,10 @@ abstract class CI_DB_utility extends CI_DB_forge {
/**
* Generate CSV from a query result object
*
- * @param object The query result object
- * @param string The delimiter - comma by default
- * @param string The newline character - \n by default
- * @param string The enclosure - double quote by default
+ * @param object $query Query result object
+ * @param string $delim Delimiter (default: ,)
+ * @param string $newline Newline character (default: \n)
+ * @param string $enclosure Enclosure (default: ")
* @return string
*/
public function csv_from_result($query, $delim = ',', $newline = "\n", $enclosure = '"')
@@ -233,8 +258,8 @@ abstract class CI_DB_utility extends CI_DB_forge {
/**
* Generate XML data from a query result object
*
- * @param object The query result object
- * @param array Any preferences
+ * @param object $query Query result object
+ * @param array $params Any preferences
* @return string
*/
public function xml_from_result($query, $params = array())
@@ -280,7 +305,7 @@ abstract class CI_DB_utility extends CI_DB_forge {
/**
* Database Backup
*
- * @param array $params = array()
+ * @param array $params
* @return void
*/
public function backup($params = array())
@@ -293,8 +318,6 @@ abstract class CI_DB_utility extends CI_DB_forge {
$params = array('tables' => $params);
}
- // ------------------------------------------------------
-
// Set up our default preferences
$prefs = array(
'tables' => array(),
@@ -338,7 +361,7 @@ abstract class CI_DB_utility extends CI_DB_forge {
{
if ($this->db->db_debug)
{
- return $this->db->display_error('db_unsuported_compression');
+ return $this->db->display_error('db_unsupported_compression');
}
$prefs['format'] = 'txt';
diff --git a/system/database/drivers/cubrid/cubrid_driver.php b/system/database/drivers/cubrid/cubrid_driver.php
index 8e77d8396..c89a924d3 100644
--- a/system/database/drivers/cubrid/cubrid_driver.php
+++ b/system/database/drivers/cubrid/cubrid_driver.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 2.1
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* CUBRID Database Adapter Class
@@ -40,18 +41,33 @@
*/
class CI_DB_cubrid_driver extends CI_DB {
+ /**
+ * Database driver
+ *
+ * @var string
+ */
public $dbdriver = 'cubrid';
- // The character used for escaping - no need in CUBRID
- protected $_escape_char = '`';
+ /**
+ * Auto-commit flag
+ *
+ * @var bool
+ */
+ public $auto_commit = TRUE;
- protected $_random_keyword = ' RAND()'; // database specific random keyword
+ // --------------------------------------------------------------------
- // CUBRID-specific properties
- public $auto_commit = TRUE;
+ /**
+ * Identifier escape character
+ *
+ * @var string
+ */
+ protected $_escape_char = '`';
+
+ // --------------------------------------------------------------------
/**
- * Constructor
+ * Class constructor
*
* @param array $params
* @return void
@@ -113,7 +129,7 @@ class CI_DB_cubrid_driver extends CI_DB {
* Except for determining if a persistent connection should be used,
* the rest of the logic is the same for db_connect() and db_pconnect().
*
- * @param bool
+ * @param bool $persistent
* @return resource
*/
protected function _cubrid_connect($persistent = FALSE)
@@ -163,9 +179,18 @@ class CI_DB_cubrid_driver extends CI_DB {
*/
public function version()
{
- return isset($this->data_cache['version'])
- ? $this->data_cache['version']
- : $this->data_cache['version'] = cubrid_get_server_info($this->conn_id);
+ if (isset($this->data_cache['version']))
+ {
+ return $this->data_cache['version'];
+ }
+ elseif ( ! $this->conn_id)
+ {
+ $this->initialize();
+ }
+
+ return ( ! $this->conn_id OR ($version = cubrid_get_server_info($this->conn_id)) === FALSE)
+ ? FALSE
+ : $this->data_cache['version'] = $version;
}
// --------------------------------------------------------------------
@@ -173,7 +198,7 @@ class CI_DB_cubrid_driver extends CI_DB {
/**
* Execute the query
*
- * @param string an SQL query
+ * @param string $sql an SQL query
* @return resource
*/
protected function _execute($sql)
@@ -186,7 +211,7 @@ class CI_DB_cubrid_driver extends CI_DB {
/**
* Begin Transaction
*
- * @param bool $test_mode = FALSE
+ * @param bool $test_mode
* @return bool
*/
public function trans_begin($test_mode = FALSE)
@@ -265,8 +290,8 @@ class CI_DB_cubrid_driver extends CI_DB {
/**
* Escape String
*
- * @param string
- * @param bool whether or not the string will be used in a LIKE condition
+ * @param string $str
+ * @param bool $like Whether or not the string will be used in a LIKE condition
* @return string
*/
public function escape_str($str, $like = FALSE)
@@ -332,7 +357,7 @@ class CI_DB_cubrid_driver extends CI_DB {
*
* Generates a platform-specific query string so that the table names can be fetched
*
- * @param bool
+ * @param bool $prefix_limit
* @return string
*/
protected function _list_tables($prefix_limit = FALSE)
@@ -354,7 +379,7 @@ class CI_DB_cubrid_driver extends CI_DB {
*
* Generates a platform-specific query string so that the column names can be fetched
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _list_columns($table = '')
@@ -369,7 +394,7 @@ class CI_DB_cubrid_driver extends CI_DB {
*
* Generates a platform-specific query so that the column data can be retrieved
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _field_data($table)
@@ -399,9 +424,9 @@ class CI_DB_cubrid_driver extends CI_DB {
*
* Generates a platform-specific batch update string from the supplied data
*
- * @param string the table name
- * @param array the update data
- * @param string the where key
+ * @param string $table Table name
+ * @param array $values Update data
+ * @param string $index WHERE key
* @return string
*/
protected function _update_batch($table, $values, $index)
diff --git a/system/database/drivers/cubrid/cubrid_forge.php b/system/database/drivers/cubrid/cubrid_forge.php
index d328aa241..05762ba5a 100644
--- a/system/database/drivers/cubrid/cubrid_forge.php
+++ b/system/database/drivers/cubrid/cubrid_forge.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 2.1
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* CUBRID Forge Class
@@ -34,181 +35,175 @@
*/
class CI_DB_cubrid_forge extends CI_DB_forge {
+ /**
+ * CREATE DATABASE statement
+ *
+ * @var string
+ */
protected $_create_database = FALSE;
+
+ /**
+ * CREATE TABLE keys flag
+ *
+ * Whether table keys are created from within the
+ * CREATE TABLE statement.
+ *
+ * @var bool
+ */
+ protected $_create_table_keys = TRUE;
+
+ /**
+ * DROP DATABASE statement
+ *
+ * @var string
+ */
protected $_drop_database = FALSE;
/**
- * Process Fields
+ * CREATE TABLE IF statement
*
- * @param mixed the fields
- * @return string
+ * @var string
+ */
+ protected $_create_table_if = FALSE;
+
+ /**
+ * UNSIGNED support
+ *
+ * @var array
+ */
+ protected $_unsigned = array(
+ 'SHORT' => 'INTEGER',
+ 'SMALLINT' => 'INTEGER',
+ 'INT' => 'BIGINT',
+ 'INTEGER' => 'BIGINT',
+ 'BIGINT' => 'NUMERIC',
+ 'FLOAT' => 'DOUBLE',
+ 'REAL' => 'DOUBLE'
+ );
+
+ // --------------------------------------------------------------------
+
+ /**
+ * ALTER TABLE
+ *
+ * @param string $alter_type ALTER type
+ * @param string $table Table name
+ * @param mixed $field Column definition
+ * @return string|string[]
*/
- protected function _process_fields($fields)
+ protected function _alter_table($alter_type, $table, $field)
{
- $current_field_count = 0;
- $sql = '';
+ if (in_array($alter_type, array('DROP', 'ADD'), TRUE))
+ {
+ return parent::_alter_table($alter_type, $table, $field);
+ }
- foreach ($fields as $field => $attributes)
+ $sql = 'ALTER TABLE '.$this->db->escape_identifiers($table);
+ $sqls = array();
+ for ($i = 0, $c = count($field); $i < $c; $i++)
{
- // Numeric field names aren't allowed in databases, so if the key is
- // numeric, we know it was assigned by PHP and the developer manually
- // entered the field information, so we'll simply add it to the list
- if (is_numeric($field))
+ if ($field[$i]['_literal'] !== FALSE)
{
- $sql .= "\n\t".$attributes;
+ $sqls[] = $sql.' CHANGE '.$field[$i]['_literal'];
}
else
{
- $attributes = array_change_key_case($attributes, CASE_UPPER);
-
- $sql .= "\n\t".$this->db->escape_identifiers($field);
-
- empty($attributes['NAME']) OR $sql .= ' '.$this->db->escape_identifiers($attributes['NAME']).' ';
-
- if ( ! empty($attributes['TYPE']))
- {
- $sql .= ' '.$attributes['TYPE'];
-
- if ( ! empty($attributes['CONSTRAINT']))
- {
- switch (strtolower($attributes['TYPE']))
- {
- case 'decimal':
- case 'float':
- case 'numeric':
- $sql .= '('.implode(',', $attributes['CONSTRAINT']).')';
- break;
- case 'enum':
- // Will be supported in the future as part a part of
- // MySQL compatibility features.
- break;
- case 'set':
- $sql .= '("'.implode('","', $attributes['CONSTRAINT']).'")';
- break;
- default:
- $sql .= '('.$attributes['CONSTRAINT'].')';
- }
- }
- }
-
- /* As of version 8.4.1 CUBRID does not support UNSIGNED INTEGER data type.
- * Will be supported in the next release as a part of MySQL Compatibility.
- *
- if (isset($attributes['UNSIGNED']) && $attributes['UNSIGNED'] === TRUE)
- {
- $sql .= ' UNSIGNED';
- }
- */
-
- if (isset($attributes['DEFAULT']))
- {
- $sql .= " DEFAULT '".$attributes['DEFAULT']."'";
- }
-
- $sql .= ( ! empty($attributes['NULL']) && $attributes['NULL'] === TRUE)
- ? ' NULL' : ' NOT NULL';
-
- if ( ! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === TRUE)
+ $sqls[] = $sql.' CHANGE '.$this->_process_column($field[$i]);
+ if ( ! empty($field[$i]['new_name']))
{
- $sql .= ' AUTO_INCREMENT';
+ $sqls[] = $sql.' RENAME COLUMN '.$this->db->escape_identifiers($field[$i]['name'])
+ .' AS '.$this->db->escape_identifiers($field[$i]['name']);
}
-
- if ( ! empty($attributes['UNIQUE']) && $attributes['UNIQUE'] === TRUE)
- {
- $sql .= ' UNIQUE';
- }
- }
-
- // don't add a comma on the end of the last field
- if (++$current_field_count < count($fields))
- {
- $sql .= ',';
}
}
- return $sql;
+ return $sqls;
}
// --------------------------------------------------------------------
/**
- * Create Table
+ * Process column
*
- * @param string the table name
- * @param mixed the fields
- * @param mixed primary key(s)
- * @param mixed key(s)
- * @param bool should 'IF NOT EXISTS' be added to the SQL
- * @return bool
+ * @param array $field
+ * @return string
*/
- protected function _create_table($table, $fields, $primary_keys, $keys, $if_not_exists)
+ protected function _process_column($field)
{
- $sql = 'CREATE TABLE ';
+ $extra_clause = isset($field['after'])
+ ? ' AFTER '.$this->db->escape_identifiers($field['after']) : '';
- /* As of version 8.4.1 CUBRID does not support this SQL syntax.
- if ($if_not_exists === TRUE)
+ if (empty($extra_clause) && isset($field['first']) && $field['first'] === TRUE)
{
- $sql .= 'IF NOT EXISTS ';
+ $extra_clause = ' FIRST';
}
- */
- $sql .= $this->db->escape_identifiers($table).' ('.$this->_process_fields($fields);
+ return $this->db->escape_identifiers($field['name'])
+ .(empty($field['new_name']) ? '' : $this->db->escape_identifiers($field['new_name']))
+ .' '.$field['type'].$field['length']
+ .$field['unsigned']
+ .$field['null']
+ .$field['default']
+ .$field['auto_increment']
+ .$field['unique']
+ .$extra_clause;
+ }
- // If there is a PK defined
- if (count($primary_keys) > 0)
- {
- $key_name = $this->db->escape_identifiers('pk_'.$table.'_'.implode('_', $primary_keys));
- $sql .= ",\n\tCONSTRAINT ".$key_name.' PRIMARY KEY('.implode(', ', $this->db->escape_identifiers($primary_keys)).')';
- }
+ // --------------------------------------------------------------------
- if (is_array($keys) && count($keys) > 0)
+ /**
+ * Field attribute TYPE
+ *
+ * Performs a data type mapping between different databases.
+ *
+ * @param array &$attributes
+ * @return void
+ */
+ protected function _attr_type(&$attributes)
+ {
+ switch (strtoupper($attributes['TYPE']))
{
- foreach ($keys as $key)
- {
- if (is_array($key))
- {
- $key_name = $this->db->escape_identifiers('idx_'.$table.implode('_', $key));
- $key = $this->db->escape_identifiers($key);
- }
- else
- {
- $key_name = $this->db->escape_identifiers('idx_'.$table.$key);
- $key = array($key_name);
- }
-
- $sql .= ",\n\tKEY ".$key_name.' ('.implode(', ', $key).')';
- }
+ case 'TINYINT':
+ $attributes['TYPE'] = 'SMALLINT';
+ $attributes['UNSIGNED'] = FALSE;
+ return;
+ case 'MEDIUMINT':
+ $attributes['TYPE'] = 'INTEGER';
+ $attributes['UNSIGNED'] = FALSE;
+ return;
+ default: return;
}
-
- return $sql."\n);";
}
// --------------------------------------------------------------------
/**
- * Alter table query
- *
- * Generates a platform-specific query so that a table can be altered
- * Called by add_column(), drop_column(), and column_alter(),
+ * Process indexes
*
- * @param string the ALTER type (ADD, DROP, CHANGE)
- * @param string the column name
- * @param array fields
- * @param string the field after which we should add the new field
+ * @param string $table (ignored)
* @return string
*/
- protected function _alter_table($alter_type, $table, $fields, $after_field = '')
+ protected function _process_indexes($table = NULL)
{
- $sql = 'ALTER TABLE '.$this->db->escape_identifiers($table).' '.$alter_type.' ';
+ $sql = '';
- // DROP has everything it needs now.
- if ($alter_type === 'DROP')
+ for ($i = 0, $c = count($this->keys); $i < $c; $i++)
{
- return $sql.$this->db->escape_identifiers($fields);
+ if ( ! isset($this->fields[$this->keys[$i]]))
+ {
+ unset($this->keys[$i]);
+ continue;
+ }
+
+ is_array($this->keys[$i]) OR $this->keys[$i] = array($this->keys[$i]);
+
+ $sql .= ",\n\tKEY ".$this->db->escape_identifiers(implode('_', $this->keys[$i]))
+ .' ('.implode(', ', $this->db->escape_identifiers($this->keys[$i])).')';
}
- return $sql.$this->_process_fields($fields)
- .($after_field !== '' ? ' AFTER '.$this->db->escape_identifiers($after_field) : '');
+ $this->keys = array();
+
+ return $sql;
}
}
diff --git a/system/database/drivers/cubrid/cubrid_result.php b/system/database/drivers/cubrid/cubrid_result.php
index 360c50dc2..30aed38d9 100644
--- a/system/database/drivers/cubrid/cubrid_result.php
+++ b/system/database/drivers/cubrid/cubrid_result.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 2.1
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* CUBRID Result Class
@@ -130,9 +131,9 @@ class CI_DB_cubrid_result extends CI_DB_result {
*
* Moves the internal pointer to the desired offset. We call
* this internally before fetching results to make sure the
- * result set starts at zero
+ * result set starts at zero.
*
- * @param int $n = 0
+ * @param int $n
* @return bool
*/
protected function _data_seek($n = 0)
@@ -161,7 +162,7 @@ class CI_DB_cubrid_result extends CI_DB_result {
*
* Returns the result set as an object
*
- * @param string
+ * @param string $class_name
* @return object
*/
protected function _fetch_object($class_name = 'stdClass')
diff --git a/system/database/drivers/cubrid/cubrid_utility.php b/system/database/drivers/cubrid/cubrid_utility.php
index ea8feb4e2..d76eca432 100644
--- a/system/database/drivers/cubrid/cubrid_utility.php
+++ b/system/database/drivers/cubrid/cubrid_utility.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 2.1
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* CUBRID Utility Class
@@ -62,7 +63,7 @@ class CI_DB_cubrid_utility extends CI_DB_utility {
// No SQL based support in CUBRID as of version 8.4.0. Database or
// table backup can be performed using CUBRID Manager
// database administration tool.
- return $this->db->display_error('db_unsuported_feature');
+ return $this->db->display_error('db_unsupported_feature');
}
}
diff --git a/system/database/drivers/ibase/ibase_driver.php b/system/database/drivers/ibase/ibase_driver.php
index c3be519bf..fc1c28f31 100644
--- a/system/database/drivers/ibase/ibase_driver.php
+++ b/system/database/drivers/ibase/ibase_driver.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 3.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Firebird/Interbase Database Adapter Class
@@ -40,15 +41,30 @@
*/
class CI_DB_ibase_driver extends CI_DB {
+ /**
+ * Database driver
+ *
+ * @var string
+ */
public $dbdriver = 'ibase';
- // The character used to escape with
- protected $_escape_char = '"';
+ // --------------------------------------------------------------------
+
+ /**
+ * ORDER BY random keyword
+ *
+ * @var string
+ */
+ protected $_random_keyword = ' Random()';
- protected $_random_keyword = ' Random()'; // database specific random keyword
+ /**
+ * IBase Transaction status flag
+ *
+ * @var resource
+ */
+ protected $_ibase_trans;
- // Keeps track of the resource for the current transaction
- protected $trans;
+ // --------------------------------------------------------------------
/**
* Non-persistent database connection
@@ -103,7 +119,7 @@ class CI_DB_ibase_driver extends CI_DB {
/**
* Execute the query
*
- * @param string an SQL query
+ * @param string $sql an SQL query
* @return resource
*/
protected function _execute($sql)
@@ -116,7 +132,7 @@ class CI_DB_ibase_driver extends CI_DB {
/**
* Begin Transaction
*
- * @param bool $test_mode = FALSE
+ * @param bool $test_mode
* @return bool
*/
public function trans_begin($test_mode = FALSE)
@@ -132,7 +148,7 @@ class CI_DB_ibase_driver extends CI_DB {
// even if the queries produce a successful result.
$this->_trans_failure = ($test_mode === TRUE);
- $this->trans = @ibase_trans($this->conn_id);
+ $this->_ibase_trans = @ibase_trans($this->conn_id);
return TRUE;
}
@@ -152,7 +168,7 @@ class CI_DB_ibase_driver extends CI_DB {
return TRUE;
}
- return @ibase_commit($this->trans);
+ return @ibase_commit($this->_ibase_trans);
}
// --------------------------------------------------------------------
@@ -170,7 +186,7 @@ class CI_DB_ibase_driver extends CI_DB {
return TRUE;
}
- return @ibase_rollback($this->trans);
+ return @ibase_rollback($this->_ibase_trans);
}
// --------------------------------------------------------------------
@@ -178,8 +194,8 @@ class CI_DB_ibase_driver extends CI_DB {
/**
* Escape String
*
- * @param string
- * @param bool whether or not the string will be used in a LIKE condition
+ * @param string $str
+ * @param bool $like Whether or not the string will be used in a LIKE condition
* @return string
*/
public function escape_str($str, $like = FALSE)
@@ -239,7 +255,7 @@ class CI_DB_ibase_driver extends CI_DB {
*
* Generates a platform-specific query string so that the table names can be fetched
*
- * @param bool
+ * @param bool $prefix_limit
* @return string
*/
protected function _list_tables($prefix_limit = FALSE)
@@ -262,7 +278,7 @@ class CI_DB_ibase_driver extends CI_DB {
*
* Generates a platform-specific query string so that the column names can be fetched
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _list_columns($table = '')
@@ -277,7 +293,7 @@ class CI_DB_ibase_driver extends CI_DB {
*
* Generates a platform-specific query so that the column data can be retrieved
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _field_data($table)
@@ -310,8 +326,8 @@ class CI_DB_ibase_driver extends CI_DB {
*
* Generates a platform-specific update string from the supplied data
*
- * @param string the table name
- * @param array the update data
+ * @param string $table
+ * @param array $values
* @return string
*/
protected function _update($table, $values)
@@ -327,10 +343,10 @@ class CI_DB_ibase_driver extends CI_DB {
*
* Generates a platform-specific truncate string from the supplied data
*
- * If the database does not support the truncate() command,
+ * If the database does not support the TRUNCATE statement,
* then this method maps to 'DELETE FROM table'
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _truncate($table)
@@ -345,7 +361,7 @@ class CI_DB_ibase_driver extends CI_DB {
*
* Generates a platform-specific delete string from the supplied data
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _delete($table)
@@ -357,11 +373,11 @@ class CI_DB_ibase_driver extends CI_DB {
// --------------------------------------------------------------------
/**
- * Limit string
+ * LIMIT
*
* Generates a platform-specific LIMIT clause
*
- * @param string the sql query string
+ * @param string $sql SQL Query
* @return string
*/
protected function _limit($sql)
diff --git a/system/database/drivers/ibase/ibase_forge.php b/system/database/drivers/ibase/ibase_forge.php
index da75eb9c3..a0c4e6563 100644
--- a/system/database/drivers/ibase/ibase_forge.php
+++ b/system/database/drivers/ibase/ibase_forge.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 3.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Interbase/Firebird Forge Class
@@ -34,12 +35,51 @@
*/
class CI_DB_ibase_forge extends CI_DB_forge {
- protected $_drop_table = 'DROP TABLE %s';
+ /**
+ * CREATE TABLE IF statement
+ *
+ * @var string
+ */
+ protected $_create_table_if = FALSE;
+
+ /**
+ * RENAME TABLE statement
+ *
+ * @var string
+ */
+ protected $_rename_table = FALSE;
+
+ /**
+ * DROP TABLE IF statement
+ *
+ * @var string
+ */
+ protected $_drop_table_if = FALSE;
+
+ /**
+ * UNSIGNED support
+ *
+ * @var array
+ */
+ protected $_unsigned = array(
+ 'SMALLINT' => 'INTEGER',
+ 'INTEGER' => 'INT64',
+ 'FLOAT' => 'DOUBLE PRECISION'
+ );
+
+ /**
+ * NULL value representation in CREATE/ALTER TABLE statements
+ *
+ * @var string
+ */
+ protected $_null = 'NULL';
+
+ // --------------------------------------------------------------------
/**
* Create database
*
- * @param string the database name
+ * @param string $db_name
* @return string
*/
public function create_database($db_name)
@@ -57,8 +97,7 @@ class CI_DB_ibase_forge extends CI_DB_forge {
/**
* Drop database
*
- * @param string the database name
- * - not used in this driver, the current db is dropped
+ * @param string $db_name (ignored)
* @return bool
*/
public function drop_database($db_name = '')
@@ -82,110 +121,119 @@ class CI_DB_ibase_forge extends CI_DB_forge {
// --------------------------------------------------------------------
/**
- * Create Table
+ * ALTER TABLE
*
- * @param string the table name
- * @param array the fields
- * @param mixed primary key(s)
- * @param mixed key(s)
- * @param bool should 'IF NOT EXISTS' be added to the SQL
- * @return string
+ * @param string $alter_type ALTER type
+ * @param string $table Table name
+ * @param mixed $field Column definition
+ * @return string|string[]
*/
- protected function _create_table($table, $fields, $primary_keys, $keys, $if_not_exists)
- {
- $sql = 'CREATE TABLE ';
-
- $sql .= $this->db->escape_identifiers($table).'(';
- $current_field_count = 0;
+ protected function _alter_table($alter_type, $table, $field)
+ {
+ if (in_array($alter_type, array('DROP', 'ADD'), TRUE))
+ {
+ return parent::_alter_table($alter_type, $table, $field);
+ }
- foreach ($fields as $field => $attributes)
+ $sql = 'ALTER TABLE '.$this->db->escape_identifiers($table);
+ $sqls = array();
+ for ($i = 0, $c = count($field), $sql .= $alter_type.' '; $i < $c; $i++)
{
- // Numeric field names aren't allowed in databases, so if the key is
- // numeric, we know it was assigned by PHP and the developer manually
- // entered the field information, so we'll simply add it to the list
- if (is_numeric($field))
+ if ($field[$i]['_literal'] !== FALSE)
{
- $sql .= "\n\t".$attributes;
+ return FALSE;
}
- else
- {
- $attributes = array_change_key_case($attributes, CASE_UPPER);
-
- $sql .= "\n\t".$this->db->escape_identifiers($field).' '.$attributes['TYPE'];
-
- empty($attributes['CONSTRAINT']) OR $sql .= '('.$attributes['CONSTRAINT'].')';
-
- if ( ! empty($attributes['UNSIGNED']) && $attributes['UNSIGNED'] === TRUE)
- {
- $sql .= ' UNSIGNED';
- }
- if (isset($attributes['DEFAULT']))
- {
- $sql .= " DEFAULT '".$attributes['DEFAULT']."'";
- }
-
- $sql .= ( ! empty($attributes['NULL']) && $attributes['NULL'] === TRUE)
- ? ' NULL' : ' NOT NULL';
-
- if ( ! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === TRUE)
- {
- $sql .= ' AUTO_INCREMENT';
- }
+ if (isset($field[$i]['type']))
+ {
+ $sqls[] = $sql.' TYPE '.$field[$i]['type'].$field[$i]['length'];
}
- // don't add a comma on the end of the last field
- if (++$current_field_count < count($fields))
+ if ( ! empty($field[$i]['default']))
{
- $sql .= ',';
+ $sqls[] = $sql.' ALTER '.$this->db->escape_identifiers($field[$i]['name'])
+ .' SET '.$field[$i]['default'];
}
- }
- if (count($primary_keys) > 0)
- {
- $primary_keys = $this->db->escape_identifiers($primary_keys);
- $sql .= ",\n\tPRIMARY KEY (".implode(', ', $primary_keys).')';
- }
-
- if (is_array($keys) && count($keys) > 0)
- {
- foreach ($keys as $key)
+ if (isset($field[$i]['null']))
{
- $key = is_array($key)
- ? $this->db->escape_identifiers($key)
- : array($this->db->escape_identifiers($key));
+ $sqls[] = 'UPDATE "RDB$RELATION_FIELDS" SET "RDB$NULL_FLAG" = '
+ .($field[$i]['null'] === TRUE ? 'NULL' : '1')
+ .' WHERE "RDB$FIELD_NAME" = '.$this->db->escape($field[$i]['name'])
+ .' AND "RDB$RELATION_NAME" = '.$this->db->escape($table);
+ }
- $sql .= ",\n\tUNIQUE (".implode(', ', $key).')';
+ if ( ! empty($field[$i]['new_name']))
+ {
+ $sqls[] = $sql.' ALTER '.$this->db->escape_identifiers($field[$i]['name'])
+ .' TO '.$this->db->escape_identifiers($field[$i]['new_name']);
}
}
- return $sql."\n)";
+ return $sqls;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Process column
+ *
+ * @param array $field
+ * @return string
+ */
+ protected function _process_column($field)
+ {
+ return $this->db->escape_identifiers($field['name'])
+ .' '.$field['type'].$field['length']
+ .$field['null']
+ .$field['unique']
+ .$field['default'];
}
// --------------------------------------------------------------------
/**
- * Alter table query
+ * Field attribute TYPE
*
- * Generates a platform-specific query so that a table can be altered
- * Called by add_column(), drop_column(), and column_alter(),
+ * Performs a data type mapping between different databases.
*
- * @param string the ALTER type (ADD, DROP, CHANGE)
- * @param string the column name
- * @param string the table name
- * @param string the column definition
- * @param string the default value
- * @param bool should 'NOT NULL' be added
- * @param string the field after which we should add the new field
- * @return string
+ * @param array &$attributes
+ * @return void
+ */
+ protected function _attr_type(&$attributes)
+ {
+ switch (strtoupper($attributes['TYPE']))
+ {
+ case 'TINYINT':
+ $attributes['TYPE'] = 'SMALLINT';
+ $attributes['UNSIGNED'] = FALSE;
+ return;
+ case 'MEDIUMINT':
+ $attributes['TYPE'] = 'INTEGER';
+ $attributes['UNSIGNED'] = FALSE;
+ return;
+ case 'INT':
+ $attributes['TYPE'] = 'INTEGER';
+ return;
+ case 'BIGINT':
+ $attributes['TYPE'] = 'INT64';
+ return;
+ default: return;
+ }
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Field attribute AUTO_INCREMENT
+ *
+ * @param array &$attributes
+ * @param array &$field
+ * @return void
*/
- protected function _alter_table($alter_type, $table, $column_name, $column_definition = '', $default_value = '', $null = '', $after_field = '')
+ protected function _attr_auto_increment(&$attributes, &$field)
{
- return 'ALTER TABLE '.$this->db->escape_identifiers($table).' '.$alter_type.' '.$this->db->escape_identifiers($column_name)
- .' '.$column_definition
- .($default_value !== '' ? ' DEFAULT "'.$default_value.'"' : '')
- .($null === NULL ? ' NULL' : ' NOT NULL')
- .($after_field !== '' ? ' AFTER '.$this->db->escape_identifiers($after_field) : '');
+ // Not supported
}
}
diff --git a/system/database/drivers/ibase/ibase_result.php b/system/database/drivers/ibase/ibase_result.php
index 95e55710b..bbad9d895 100644
--- a/system/database/drivers/ibase/ibase_result.php
+++ b/system/database/drivers/ibase/ibase_result.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Interbase/Firebird Result Class
@@ -128,7 +129,7 @@ class CI_DB_ibase_result extends CI_DB_result {
*
* Returns the result set as an object
*
- * @param string
+ * @param string $class_name
* @return object
*/
protected function _fetch_object($class_name = 'stdClass')
diff --git a/system/database/drivers/ibase/ibase_utility.php b/system/database/drivers/ibase/ibase_utility.php
index d0e84a7b2..5eb209ae1 100644
--- a/system/database/drivers/ibase/ibase_utility.php
+++ b/system/database/drivers/ibase/ibase_utility.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 3.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Interbase/Firebird Utility Class
@@ -34,10 +35,8 @@
*/
class CI_DB_ibase_utility extends CI_DB_utility {
- protected $_list_databases = FALSE;
-
/**
- * Interbase/Firebird Export
+ * Export
*
* @param string $filename
* @return mixed
diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php
index 2063dad90..a9d53fb57 100644
--- a/system/database/drivers/mssql/mssql_driver.php
+++ b/system/database/drivers/mssql/mssql_driver.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* MS SQL Database Adapter Class
@@ -40,18 +41,36 @@
*/
class CI_DB_mssql_driver extends CI_DB {
+ /**
+ * Database driver
+ *
+ * @var string
+ */
public $dbdriver = 'mssql';
- // The character used for escaping
- protected $_escape_char = '"';
+ // --------------------------------------------------------------------
+ /**
+ * ORDER BY random keyword
+ *
+ * @var string
+ */
protected $_random_keyword = ' NEWID()';
- // MSSQL-specific properties
+ /**
+ * Quoted identifier flag
+ *
+ * Whether to use SQL-92 standard quoted identifier
+ * (double quotes) or brackets for identifier escaping.
+ *
+ * @var bool
+ */
protected $_quoted_identifier = TRUE;
+ // --------------------------------------------------------------------
+
/**
- * Constructor
+ * Class constructor
*
* Appends the port number to the hostname, if needed.
*
@@ -73,7 +92,7 @@ class CI_DB_mssql_driver extends CI_DB {
/**
* Non-persistent database connection
*
- * @param bool
+ * @param bool $persistent
* @return resource
*/
public function db_connect($persistent = FALSE)
@@ -113,7 +132,7 @@ class CI_DB_mssql_driver extends CI_DB {
/**
* Select the database
*
- * @param string database name
+ * @param string $database
* @return bool
*/
public function db_select($database = '')
@@ -139,7 +158,7 @@ class CI_DB_mssql_driver extends CI_DB {
/**
* Execute the query
*
- * @param string an SQL query
+ * @param string $sql an SQL query
* @return mixed resource if rows are returned, bool otherwise
*/
protected function _execute($sql)
@@ -152,7 +171,7 @@ class CI_DB_mssql_driver extends CI_DB {
/**
* Begin Transaction
*
- * @param bool $test_mode = FALSE
+ * @param bool $test_mode
* @return bool
*/
public function trans_begin($test_mode = FALSE)
@@ -212,8 +231,8 @@ class CI_DB_mssql_driver extends CI_DB {
/**
* Escape String
*
- * @param string
- * @param bool whether or not the string will be used in a LIKE condition
+ * @param string $str
+ * @param bool $like Whether or not the string will be used in a LIKE condition
* @return string
*/
public function escape_str($str, $like = FALSE)
@@ -295,7 +314,7 @@ class CI_DB_mssql_driver extends CI_DB {
*
* Generates a platform-specific query string so that the table names can be fetched
*
- * @param bool
+ * @param bool $prefix_limit
* @return string
*/
protected function _list_tables($prefix_limit = FALSE)
@@ -320,7 +339,7 @@ class CI_DB_mssql_driver extends CI_DB {
*
* Generates a platform-specific query string so that the column names can be fetched
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _list_columns($table = '')
@@ -335,7 +354,7 @@ class CI_DB_mssql_driver extends CI_DB {
*
* Generates a platform-specific query so that the column data can be retrieved
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _field_data($table)
@@ -367,8 +386,8 @@ class CI_DB_mssql_driver extends CI_DB {
*
* Generates a platform-specific update string from the supplied data
*
- * @param string the table name
- * @param array the update data
+ * @param string $table
+ * @param array $values
* @return string
*/
protected function _update($table, $values)
@@ -385,10 +404,10 @@ class CI_DB_mssql_driver extends CI_DB {
*
* Generates a platform-specific truncate string from the supplied data
*
- * If the database does not support the truncate() command,
+ * If the database does not support the TRUNCATE statement,
* then this method maps to 'DELETE FROM table'
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _truncate($table)
@@ -403,7 +422,7 @@ class CI_DB_mssql_driver extends CI_DB {
*
* Generates a platform-specific delete string from the supplied data
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _delete($table)
@@ -419,11 +438,11 @@ class CI_DB_mssql_driver extends CI_DB {
// --------------------------------------------------------------------
/**
- * Limit string
+ * LIMIT
*
* Generates a platform-specific LIMIT clause
*
- * @param string the sql query string
+ * @param string $sql SQL Query
* @return string
*/
protected function _limit($sql)
@@ -470,6 +489,29 @@ class CI_DB_mssql_driver extends CI_DB {
// --------------------------------------------------------------------
/**
+ * Insert batch statement
+ *
+ * Generates a platform-specific insert string from the supplied data.
+ *
+ * @param string $table Table name
+ * @param array $keys INSERT keys
+ * @param array $values INSERT values
+ * @return string|bool
+ */
+ protected function _insert_batch($table, $keys, $values)
+ {
+ // Multiple-value inserts are only supported as of SQL Server 2008
+ if (version_compare($this->version(), '10', '>='))
+ {
+ return parent::_insert_batch($table, $keys, $values);
+ }
+
+ return ($this->db->db_debug) ? $this->db->display_error('db_unsupported_feature') : FALSE;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
* Close DB Connection
*
* @return void
diff --git a/system/database/drivers/mssql/mssql_forge.php b/system/database/drivers/mssql/mssql_forge.php
index 3a3528f7b..5eebedbf7 100644
--- a/system/database/drivers/mssql/mssql_forge.php
+++ b/system/database/drivers/mssql/mssql_forge.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* MS SQL Forge Class
@@ -34,124 +35,99 @@
*/
class CI_DB_mssql_forge extends CI_DB_forge {
- protected $_drop_table = 'DROP TABLE %s';
-
/**
- * Create Table
+ * CREATE TABLE IF statement
*
- * @param string the table name
- * @param array the fields
- * @param mixed primary key(s)
- * @param mixed key(s)
- * @param bool should 'IF NOT EXISTS' be added to the SQL
- * @return string
+ * @var string
*/
- protected function _create_table($table, $fields, $primary_keys, $keys, $if_not_exists)
- {
- $sql = ($if_not_exists === TRUE)
- ? "IF NOT EXISTS (SELECT * FROM sysobjects WHERE ID = object_id(N'".$table."') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)\n"
- : '';
-
- $sql .= 'CREATE TABLE '.$this->db->escape_identifiers($table).' (';
-
- $current_field_count = 0;
- foreach ($fields as $field => $attributes)
- {
- // Numeric field names aren't allowed in databases, so if the key is
- // numeric, we know it was assigned by PHP and the developer manually
- // entered the field information, so we'll simply add it to the list
- if (is_numeric($field))
- {
- $sql .= "\n\t".$attributes;
- }
- else
- {
- $attributes = array_change_key_case($attributes, CASE_UPPER);
-
- $sql .= "\n\t".$this->db->escape_identifiers($field).' '.$attributes['TYPE'];
-
- if (stripos($attributes['TYPE'], 'INT') === FALSE && ! empty($attributes['CONSTRAINT']))
- {
- $sql .= '('.$attributes['CONSTRAINT'].')';
- }
-
- if ( ! empty($attributes['UNSIGNED']) && $attributes['UNSIGNED'] === TRUE)
- {
- $sql .= ' UNSIGNED';
- }
+ protected $_create_table_if = "IF NOT EXISTS (SELECT * FROM sysobjects WHERE ID = object_id(N'%s') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)\nCREATE TABLE";
- if (isset($attributes['DEFAULT']))
- {
- $sql .= " DEFAULT '".$attributes['DEFAULT']."'";
- }
-
- $sql .= ( ! empty($attributes['NULL']) && $attributes['NULL'] === TRUE)
- ? ' NULL' : ' NOT NULL';
+ /**
+ * DROP TABLE IF statement
+ *
+ * @var string
+ */
+ protected $_drop_table_if = "IF EXISTS (SELECT * FROM sysobjects WHERE ID = object_id(N'%s') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)\nDROP TABLE";
- if ( ! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === TRUE)
- {
- $sql .= ' AUTO_INCREMENT';
- }
- }
+ /**
+ * UNSIGNED support
+ *
+ * @var array
+ */
+ protected $_unsigned = array(
+ 'TINYINT' => 'SMALLINT',
+ 'SMALLINT' => 'INT',
+ 'INT' => 'BIGINT',
+ 'REAL' => 'FLOAT'
+ );
- // don't add a comma on the end of the last field
- if (++$current_field_count < count($fields))
- {
- $sql .= ',';
- }
- }
+ // --------------------------------------------------------------------
- if (count($primary_keys) > 0)
+ /**
+ * ALTER TABLE
+ *
+ * @param string $alter_type ALTER type
+ * @param string $table Table name
+ * @param mixed $field Column definition
+ * @return string|string[]
+ */
+ protected function _alter_table($alter_type, $table, $field)
+ {
+ if (in_array($alter_type, array('ADD', 'DROP'), TRUE))
{
- $sql .= ",\n\tPRIMARY KEY (".implode(', ', $this->db->escape_identifiers($primary_keys)).')';
+ return parent::_alter_table($alter_type, $table, $field);
}
- if (is_array($keys) && count($keys) > 0)
+ $sql = 'ALTER TABLE '.$this->db->escape_identifiers($table).' ALTER COLUMN ';
+ $sqls = array();
+ for ($i = 0, $c = count($field); $i < $c; $i++)
{
- foreach ($keys as $key)
- {
- $key = is_array($key)
- ? $this->db->escape_identifiers($key)
- : array($this->db->escape_identifiers($key));
-
- $sql .= ",\n\tFOREIGN KEY (".implode(', ', $key).')';
- }
+ $sqls[] = $sql.$this->_process_column($field[$i]);
}
- return $sql."\n)";
+ return $sqls;
}
// --------------------------------------------------------------------
/**
- * Alter table query
+ * Field attribute TYPE
*
- * Generates a platform-specific query so that a table can be altered
- * Called by add_column(), drop_column(), and column_alter(),
+ * Performs a data type mapping between different databases.
*
- * @param string the ALTER type (ADD, DROP, CHANGE)
- * @param string the column name
- * @param string the table name
- * @param string the column definition
- * @param string the default value
- * @param bool should 'NOT NULL' be added
- * @param string the field after which we should add the new field
- * @return string
+ * @param array &$attributes
+ * @return void
*/
- protected function _alter_table($alter_type, $table, $column_name, $column_definition = '', $default_value = '', $null = '', $after_field = '')
+ protected function _attr_type(&$attributes)
{
- $sql = 'ALTER TABLE '.$this->db->escape_identifiers($table).' '.$alter_type.' '.$this->db->escape_identifiers($column_name);
-
- // DROP has everything it needs now.
- if ($alter_type === 'DROP')
+ switch (strtoupper($attributes['TYPE']))
{
- return $sql;
+ case 'MEDIUMINT':
+ $attributes['TYPE'] = 'INTEGER';
+ $attributes['UNSIGNED'] = FALSE;
+ return;
+ case 'INTEGER':
+ $attributes['TYPE'] = 'INT';
+ return;
+ default: return;
}
+ }
- return $sql.' '.$column_definition
- .($default_value != '' ? ' DEFAULT "'.$default_value.'"' : '')
- .($null === NULL ? ' NULL' : ' NOT NULL')
- .($after_field != '' ? ' AFTER '.$this->db->escape_identifiers($after_field) : '');
+ // --------------------------------------------------------------------
+
+ /**
+ * Field attribute AUTO_INCREMENT
+ *
+ * @param array &$attributes
+ * @param array &$field
+ * @return void
+ */
+ protected function _attr_auto_increment(&$attributes, &$field)
+ {
+ if ( ! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === TRUE && stripos($field['type'], 'int') !== FALSE)
+ {
+ $field['auto_increment'] = ' IDENTITY(1,1)';
+ }
}
}
diff --git a/system/database/drivers/mssql/mssql_result.php b/system/database/drivers/mssql/mssql_result.php
index 84d2814f1..c74c70abf 100644
--- a/system/database/drivers/mssql/mssql_result.php
+++ b/system/database/drivers/mssql/mssql_result.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* MSSQL Result Class
@@ -131,9 +132,9 @@ class CI_DB_mssql_result extends CI_DB_result {
*
* Moves the internal pointer to the desired offset. We call
* this internally before fetching results to make sure the
- * result set starts at zero
+ * result set starts at zero.
*
- * @param int $n = 0
+ * @param int $n
* @return bool
*/
protected function _data_seek($n = 0)
@@ -162,7 +163,7 @@ class CI_DB_mssql_result extends CI_DB_result {
*
* Returns the result set as an object
*
- * @param string
+ * @param string $class_name
* @return object
*/
protected function _fetch_object($class_name = 'stdClass')
diff --git a/system/database/drivers/mssql/mssql_utility.php b/system/database/drivers/mssql/mssql_utility.php
index 69fcec5f6..76c7cb9c2 100644
--- a/system/database/drivers/mssql/mssql_utility.php
+++ b/system/database/drivers/mssql/mssql_utility.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* MS SQL Utility Class
@@ -34,19 +35,30 @@
*/
class CI_DB_mssql_utility extends CI_DB_utility {
+ /**
+ * List databases statement
+ *
+ * @var string
+ */
protected $_list_databases = 'EXEC sp_helpdb'; // Can also be: EXEC sp_databases
+
+ /**
+ * OPTIMIZE TABLE statement
+ *
+ * @var string
+ */
protected $_optimize_table = 'ALTER INDEX all ON %s REORGANIZE';
/**
- * MSSQL Export
+ * Export
*
- * @param array Preferences
+ * @param array $params Preferences
* @return bool
*/
protected function _backup($params = array())
{
// Currently unsupported
- return $this->db->display_error('db_unsuported_feature');
+ return $this->db->display_error('db_unsupported_feature');
}
}
diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php
index f82e775e6..b1edc2925 100644
--- a/system/database/drivers/mysql/mysql_driver.php
+++ b/system/database/drivers/mysql/mysql_driver.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* MySQL Database Adapter Class
@@ -40,25 +41,46 @@
*/
class CI_DB_mysql_driver extends CI_DB {
+ /**
+ * Database driver
+ *
+ * @var string
+ */
public $dbdriver = 'mysql';
- public $compress = FALSE;
- // The character used for escaping
- protected $_escape_char = '`';
-
- protected $_random_keyword = ' RAND()'; // database specific random keyword
+ /**
+ * Compression flag
+ *
+ * @var bool
+ */
+ public $compress = FALSE;
/**
+ * DELETE hack flag
+ *
* Whether to use the MySQL "delete hack" which allows the number
* of affected rows to be shown. Uses a preg_replace when enabled,
* adding a bit more processing to all queries.
+ *
+ * @var bool
*/
public $delete_hack = TRUE;
+ // --------------------------------------------------------------------
+
/**
- * Constructor
+ * Identifier escape character
*
- * @param array
+ * @var string
+ */
+ protected $_escape_char = '`';
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Class constructor
+ *
+ * @param array $params
* @return void
*/
public function __construct($params)
@@ -76,7 +98,7 @@ class CI_DB_mysql_driver extends CI_DB {
/**
* Non-persistent database connection
*
- * @param bool
+ * @param bool $persistent
* @return resource
*/
public function db_connect($persistent = FALSE)
@@ -128,7 +150,7 @@ class CI_DB_mysql_driver extends CI_DB {
/**
* Select the database
*
- * @param string database name
+ * @param string $database
* @return bool
*/
public function db_select($database = '')
@@ -152,7 +174,7 @@ class CI_DB_mysql_driver extends CI_DB {
/**
* Set client character set
*
- * @param string
+ * @param string $charset
* @return bool
*/
protected function _db_set_charset($charset)
@@ -169,9 +191,21 @@ class CI_DB_mysql_driver extends CI_DB {
*/
public function version()
{
- return isset($this->data_cache['version'])
- ? $this->data_cache['version']
- : $this->data_cache['version'] = @mysql_get_server_info($this->conn_id);
+ if (isset($this->data_cache['version']))
+ {
+ return $this->data_cache['version'];
+ }
+ elseif ( ! $this->conn_id)
+ {
+ $this->initialize();
+ }
+
+ if ( ! $this->conn_id OR ($version = @mysql_get_server_info($this->conn_id)) === FALSE)
+ {
+ return FALSE;
+ }
+
+ return $this->data_cache['version'] = $version;
}
// --------------------------------------------------------------------
@@ -179,7 +213,7 @@ class CI_DB_mysql_driver extends CI_DB {
/**
* Execute the query
*
- * @param string an SQL query
+ * @param string $sql an SQL query
* @return mixed
*/
protected function _execute($sql)
@@ -194,7 +228,7 @@ class CI_DB_mysql_driver extends CI_DB {
*
* If needed, each database adapter can prep the query string
*
- * @param string an SQL query
+ * @param string $sql an SQL query
* @return string
*/
protected function _prep_query($sql)
@@ -214,7 +248,7 @@ class CI_DB_mysql_driver extends CI_DB {
/**
* Begin Transaction
*
- * @param bool $test_mode = FALSE
+ * @param bool $test_mode
* @return bool
*/
public function trans_begin($test_mode = FALSE)
@@ -280,8 +314,8 @@ class CI_DB_mysql_driver extends CI_DB {
/**
* Escape String
*
- * @param string
- * @param bool whether or not the string will be used in a LIKE condition
+ * @param string $str
+ * @param bool $like Whether or not the string will be used in a LIKE condition
* @return string
*/
public function escape_str($str, $like = FALSE)
@@ -340,7 +374,7 @@ class CI_DB_mysql_driver extends CI_DB {
*
* Generates a platform-specific query string so that the table names can be fetched
*
- * @param bool
+ * @param bool $prefix_limit
* @return string
*/
protected function _list_tables($prefix_limit = FALSE)
@@ -362,7 +396,7 @@ class CI_DB_mysql_driver extends CI_DB {
*
* Generates a platform-specific query string so that the column names can be fetched
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _list_columns($table = '')
@@ -375,7 +409,7 @@ class CI_DB_mysql_driver extends CI_DB {
/**
* Returns an object with field data
*
- * @param string the table name
+ * @param string $table
* @return object
*/
public function field_data($table = '')
@@ -426,9 +460,9 @@ class CI_DB_mysql_driver extends CI_DB {
*
* Generates a platform-specific batch update string from the supplied data
*
- * @param string the table name
- * @param array the update data
- * @param string the where key
+ * @param string $table Table name
+ * @param array $values Update data
+ * @param string $index WHERE key
* @return string
*/
protected function _update_batch($table, $values, $index)
diff --git a/system/database/drivers/mysql/mysql_forge.php b/system/database/drivers/mysql/mysql_forge.php
index 2ac75bad2..6c5dfc665 100644
--- a/system/database/drivers/mysql/mysql_forge.php
+++ b/system/database/drivers/mysql/mysql_forge.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* MySQL Forge Class
@@ -34,165 +35,167 @@
*/
class CI_DB_mysql_forge extends CI_DB_forge {
+ /**
+ * CREATE DATABASE statement
+ *
+ * @var string
+ */
protected $_create_database = 'CREATE DATABASE %s CHARACTER SET %s COLLATE %s';
/**
- * Process Fields
+ * CREATE TABLE keys flag
*
- * @param mixed the fields
- * @return string
+ * Whether table keys are created from within the
+ * CREATE TABLE statement.
+ *
+ * @var bool
*/
- protected function _process_fields($fields)
- {
- $current_field_count = 0;
- $sql = '';
-
- foreach ($fields as $field => $attributes)
- {
- // Numeric field names aren't allowed in databases, so if the key is
- // numeric, we know it was assigned by PHP and the developer manually
- // entered the field information, so we'll simply add it to the list
- if (is_numeric($field))
- {
- $sql .= "\n\t".$attributes;
- }
- else
- {
- $attributes = array_change_key_case($attributes, CASE_UPPER);
-
- $sql .= "\n\t".$this->db->escape_identifiers($field);
-
- empty($attributes['NAME']) OR $sql .= ' '.$this->db->escape_identifiers($attributes['NAME']).' ';
-
- if ( ! empty($attributes['TYPE']))
- {
- $sql .= ' '.$attributes['TYPE'];
-
- if ( ! empty($attributes['CONSTRAINT']))
- {
- switch (strtolower($attributes['TYPE']))
- {
- case 'decimal':
- case 'float':
- case 'numeric':
- $sql .= '('.implode(',', $attributes['CONSTRAINT']).')';
- break;
- case 'enum':
- case 'set':
- $sql .= '("'.implode('","', $attributes['CONSTRAINT']).'")';
- break;
- default:
- $sql .= '('.$attributes['CONSTRAINT'].')';
- }
- }
- }
+ protected $_create_table_keys = TRUE;
- if ( ! empty($attributes['UNSIGNED']) && $attributes['UNSIGNED'] === TRUE)
- {
- $sql .= ' UNSIGNED';
- }
-
- if (isset($attributes['DEFAULT']))
- {
- $sql .= " DEFAULT '".$attributes['DEFAULT']."'";
- }
+ /**
+ * UNSIGNED support
+ *
+ * @var array
+ */
+ protected $_unsigned = array(
+ 'TINYINT',
+ 'SMALLINT',
+ 'MEDIUMINT',
+ 'INT',
+ 'INTEGER',
+ 'BIGINT',
+ 'REAL',
+ 'DOUBLE',
+ 'DOUBLE PRECISION',
+ 'FLOAT',
+ 'DECIMAL',
+ 'NUMERIC'
+ );
- $sql .= ( ! empty($attributes['NULL']) && $attributes['NULL'] === TRUE)
- ? ' NULL' : ' NOT NULL';
+ /**
+ * NULL value representation in CREATE/ALTER TABLE statements
+ *
+ * @var string
+ */
+ protected $_null = 'NULL';
- if ( ! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === TRUE)
- {
- $sql .= ' AUTO_INCREMENT';
- }
- }
+ // --------------------------------------------------------------------
- // don't add a comma on the end of the last field
- if (++$current_field_count < count($fields))
- {
- $sql .= ',';
- }
- }
+ /**
+ * Class constructor
+ *
+ * @param object &$db Database object
+ * @return void
+ */
+ public function __construct(&$db)
+ {
+ parent::__construct($db);
- return $sql;
+ $this->_create_table .= ' DEFAULT CHARSET '.$this->db->char_set.' COLLATE '.$this->db->dbcollat;
}
// --------------------------------------------------------------------
/**
- * Create Table
+ * ALTER TABLE
*
- * @param string the table name
- * @param mixed the fields
- * @param mixed primary key(s)
- * @param mixed key(s)
- * @param bool should 'IF NOT EXISTS' be added to the SQL
- * @return bool
+ * @param string $alter_type ALTER type
+ * @param string $table Table name
+ * @param mixed $field Column definition
+ * @return string|string[]
*/
- protected function _create_table($table, $fields, $primary_keys, $keys, $if_not_exists)
+ protected function _alter_table($alter_type, $table, $field)
{
- $sql = 'CREATE TABLE ';
-
- if ($if_not_exists === TRUE)
- {
- $sql .= 'IF NOT EXISTS ';
- }
-
- $sql .= $this->db->escape_identifiers($table).' ('.$this->_process_fields($fields);
-
- if (count($primary_keys) > 0)
+ if ($alter_type === 'DROP')
{
- $key_name = $this->db->escape_identifiers(implode('_', $primary_keys));
- $sql .= ",\n\tPRIMARY KEY ".$key_name.' ('.implode(', ', $this->db->escape_identifiers($primary_keys)).')';
+ return parent::_alter_table($alter_type, $table, $field);
}
- if (is_array($keys) && count($keys) > 0)
+ $sql = 'ALTER TABLE '.$this->db->escape_identifiers($table);
+ for ($i = 0, $c = count($field); $i < $c; $i++)
{
- foreach ($keys as $key)
+ if ($field[$i]['_literal'] !== FALSE)
{
- if (is_array($key))
+ $field[$i] = ($alter_type === 'ADD')
+ ? "\n\tADD ".$field[$i]['_literal']
+ : "\n\tMODIFY ".$field[$i]['_literal'];
+ }
+ else
+ {
+ if ($alter_type === 'ADD')
{
- $key_name = $this->db->escape_identifiers(implode('_', $key));
- $key = $this->db->escape_identifiers($key);
+ $field[$i]['_literal'] = "\n\tADD ";
}
else
{
- $key_name = $this->db->escape_identifiers($key);
- $key = array($key_name);
+ $field[$i]['_literal'] = empty($field[$i]['new_name']) ? "\n\tMODIFY " : "\n\tCHANGE ";
}
- $sql .= ",\n\tKEY ".$key_name.' ('.implode(', ', $key).')';
+ $field[$i] = $field[$i]['_literal'].$this->_process_column($field[$i]);
}
}
- return $sql."\n) DEFAULT CHARACTER SET ".$this->db->char_set.' COLLATE '.$this->db->dbcollat.';';
+ return array($sql.implode(',', $field));
}
// --------------------------------------------------------------------
/**
- * Alter table query
+ * Process column
*
- * Generates a platform-specific query so that a table can be altered
- * Called by add_column(), drop_column() and column_alter()
+ * @param array $field
+ * @return string
+ */
+ protected function _process_column($field)
+ {
+ $extra_clause = isset($field['after'])
+ ? ' AFTER '.$this->db->escape_identifiers($field['after']) : '';
+
+ if (empty($extra_clause) && isset($field['first']) && $field['first'] === TRUE)
+ {
+ $extra_clause = ' FIRST';
+ }
+
+ return $this->db->escape_identifiers($field['name'])
+ .(empty($field['new_name']) ? '' : $this->db->escape_identifiers($field['new_name']))
+ .' '.$field['type'].$field['length']
+ .$field['unsigned']
+ .$field['null']
+ .$field['default']
+ .$field['auto_increment']
+ .$field['unique']
+ .$extra_clause;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Process indexes
*
- * @param string the ALTER type (ADD, DROP, CHANGE)
- * @param string the column name
- * @param array fields
- * @param string the field after which we should add the new field
+ * @param string $table (ignored)
* @return string
*/
- protected function _alter_table($alter_type, $table, $fields, $after_field = '')
+ protected function _process_indexes($table = NULL)
{
- $sql = 'ALTER TABLE '.$this->db->escape_identifiers($table).' '.$alter_type.' ';
+ $sql = '';
- // DROP has everything it needs now.
- if ($alter_type === 'DROP')
+ for ($i = 0, $c = count($this->keys); $i < $c; $i++)
{
- return $sql.$this->db->escape_identifiers($fields);
+ if ( ! isset($this->fields[$this->keys[$i]]))
+ {
+ unset($this->keys[$i]);
+ continue;
+ }
+
+ is_array($this->keys[$i]) OR $this->keys[$i] = array($this->keys[$i]);
+
+ $sql .= ",\n\tKEY ".$this->db->escape_identifiers(implode('_', $this->keys[$i]))
+ .' ('.implode(', ', $this->db->escape_identifiers($this->keys[$i])).')';
}
- return $sql.$this->_process_fields($fields)
- .($after_field !== '' ? ' AFTER '.$this->db->escape_identifiers($after_field) : '');
+ $this->keys = array();
+
+ return $sql;
}
}
diff --git a/system/database/drivers/mysql/mysql_result.php b/system/database/drivers/mysql/mysql_result.php
index b3f669e40..4bfa0ae35 100644
--- a/system/database/drivers/mysql/mysql_result.php
+++ b/system/database/drivers/mysql/mysql_result.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* MySQL Result Class
@@ -38,9 +39,9 @@
class CI_DB_mysql_result extends CI_DB_result {
/**
- * Constructor
+ * Class constructor
*
- * @param object
+ * @param object &$driver_object
* @return void
*/
public function __construct(&$driver_object)
@@ -144,9 +145,9 @@ class CI_DB_mysql_result extends CI_DB_result {
*
* Moves the internal pointer to the desired offset. We call
* this internally before fetching results to make sure the
- * result set starts at zero
+ * result set starts at zero.
*
- * @param int $n = 0
+ * @param int $n
* @return bool
*/
protected function _data_seek($n = 0)
@@ -177,7 +178,7 @@ class CI_DB_mysql_result extends CI_DB_result {
*
* Returns the result set as an object
*
- * @param string
+ * @param string $class_name
* @return object
*/
protected function _fetch_object($class_name = 'stdClass')
diff --git a/system/database/drivers/mysql/mysql_utility.php b/system/database/drivers/mysql/mysql_utility.php
index f0bbc665e..8aa051755 100644
--- a/system/database/drivers/mysql/mysql_utility.php
+++ b/system/database/drivers/mysql/mysql_utility.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* MySQL Utility Class
@@ -34,14 +35,33 @@
*/
class CI_DB_mysql_utility extends CI_DB_utility {
+ /**
+ * List databases statement
+ *
+ * @var string
+ */
protected $_list_databases = 'SHOW DATABASES';
+
+ /**
+ * OPTIMIZE TABLE statement
+ *
+ * @var string
+ */
protected $_optimize_table = 'OPTIMIZE TABLE %s';
+
+ /**
+ * REPAIR TABLE statement
+ *
+ * @var string
+ */
protected $_repair_table = 'REPAIR TABLE %s';
+ // --------------------------------------------------------------------
+
/**
- * MySQL Export
+ * Export
*
- * @param array Preferences
+ * @param array $params Preferences
* @return mixed
*/
protected function _backup($params = array())
diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php
index 6c4f87513..ae17703ac 100644
--- a/system/database/drivers/mysqli/mysqli_driver.php
+++ b/system/database/drivers/mysqli/mysqli_driver.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* MySQLi Database Adapter Class
@@ -40,25 +41,46 @@
*/
class CI_DB_mysqli_driver extends CI_DB {
+ /**
+ * Database driver
+ *
+ * @var string
+ */
public $dbdriver = 'mysqli';
- public $compress = FALSE;
- // The character used for escaping
- protected $_escape_char = '`';
-
- protected $_random_keyword = ' RAND()'; // database specific random keyword
+ /**
+ * Compression flag
+ *
+ * @var bool
+ */
+ public $compress = FALSE;
/**
+ * DELETE hack flag
+ *
* Whether to use the MySQL "delete hack" which allows the number
* of affected rows to be shown. Uses a preg_replace when enabled,
* adding a bit more processing to all queries.
+ *
+ * @var bool
*/
public $delete_hack = TRUE;
+ // --------------------------------------------------------------------
+
/**
- * Non-persistent database connection
+ * Identifier escape character
*
- * @param bool
+ * @var string
+ */
+ protected $_escape_char = '`';
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Database connection
+ *
+ * @param bool $persistent
* @return object
* @todo SSL support
*/
@@ -110,7 +132,7 @@ class CI_DB_mysqli_driver extends CI_DB {
/**
* Select the database
*
- * @param string database name
+ * @param string $database
* @return bool
*/
public function db_select($database = '')
@@ -134,7 +156,7 @@ class CI_DB_mysqli_driver extends CI_DB {
/**
* Set client character set
*
- * @param string
+ * @param string $charset
* @return bool
*/
protected function _db_set_charset($charset)
@@ -151,9 +173,16 @@ class CI_DB_mysqli_driver extends CI_DB {
*/
public function version()
{
- return isset($this->data_cache['version'])
- ? $this->data_cache['version']
- : $this->data_cache['version'] = $this->conn_id->server_info;
+ if (isset($this->data_cache['version']))
+ {
+ return $this->data_cache['version'];
+ }
+ elseif ( ! $this->conn_id)
+ {
+ $this->initialize();
+ }
+
+ return $this->data_cache['version'] = $this->conn_id->server_info;
}
// --------------------------------------------------------------------
@@ -161,7 +190,7 @@ class CI_DB_mysqli_driver extends CI_DB {
/**
* Execute the query
*
- * @param string an SQL query
+ * @param string $sql an SQL query
* @return mixed
*/
protected function _execute($sql)
@@ -176,7 +205,7 @@ class CI_DB_mysqli_driver extends CI_DB {
*
* If needed, each database adapter can prep the query string
*
- * @param string an SQL query
+ * @param string $sql an SQL query
* @return string
*/
protected function _prep_query($sql)
@@ -196,7 +225,7 @@ class CI_DB_mysqli_driver extends CI_DB {
/**
* Begin Transaction
*
- * @param bool $test_mode = FALSE
+ * @param bool $test_mode
* @return bool
*/
public function trans_begin($test_mode = FALSE)
@@ -262,8 +291,8 @@ class CI_DB_mysqli_driver extends CI_DB {
/**
* Escape String
*
- * @param string
- * @param bool whether or not the string will be used in a LIKE condition
+ * @param string $str
+ * @param bool $like Whether or not the string will be used in a LIKE condition
* @return string
*/
public function escape_str($str, $like = FALSE)
@@ -322,7 +351,7 @@ class CI_DB_mysqli_driver extends CI_DB {
*
* Generates a platform-specific query string so that the table names can be fetched
*
- * @param bool
+ * @param bool $prefix_limit
* @return string
*/
protected function _list_tables($prefix_limit = FALSE)
@@ -344,7 +373,7 @@ class CI_DB_mysqli_driver extends CI_DB {
*
* Generates a platform-specific query string so that the column names can be fetched
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _list_columns($table = '')
@@ -357,7 +386,7 @@ class CI_DB_mysqli_driver extends CI_DB {
/**
* Returns an object with field data
*
- * @param string the table name
+ * @param string $table
* @return object
*/
public function field_data($table = '')
@@ -416,9 +445,9 @@ class CI_DB_mysqli_driver extends CI_DB {
*
* Generates a platform-specific batch update string from the supplied data
*
- * @param string the table name
- * @param array the update data
- * @param string the where key
+ * @param string $table Table name
+ * @param array $values Update data
+ * @param string $index WHERE key
* @return string
*/
protected function _update_batch($table, $values, $index)
diff --git a/system/database/drivers/mysqli/mysqli_forge.php b/system/database/drivers/mysqli/mysqli_forge.php
index b74c775b2..a70eef88f 100644
--- a/system/database/drivers/mysqli/mysqli_forge.php
+++ b/system/database/drivers/mysqli/mysqli_forge.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* MySQLi Forge Class
@@ -34,165 +35,167 @@
*/
class CI_DB_mysqli_forge extends CI_DB_forge {
+ /**
+ * CREATE DATABASE statement
+ *
+ * @var string
+ */
protected $_create_database = 'CREATE DATABASE %s CHARACTER SET %s COLLATE %s';
/**
- * Process Fields
+ * CREATE TABLE keys flag
*
- * @param mixed the fields
- * @return string
+ * Whether table keys are created from within the
+ * CREATE TABLE statement.
+ *
+ * @var bool
*/
- protected function _process_fields($fields)
- {
- $current_field_count = 0;
- $sql = '';
-
- foreach ($fields as $field => $attributes)
- {
- // Numeric field names aren't allowed in databases, so if the key is
- // numeric, we know it was assigned by PHP and the developer manually
- // entered the field information, so we'll simply add it to the list
- if (is_numeric($field))
- {
- $sql .= "\n\t".$attributes;
- }
- else
- {
- $attributes = array_change_key_case($attributes, CASE_UPPER);
-
- $sql .= "\n\t".$this->db->escape_identifiers($field);
-
- empty($attributes['NAME']) OR $sql .= ' '.$this->db->escape_identifiers($attributes['NAME']).' ';
-
- if ( ! empty($attributes['TYPE']))
- {
- $sql .= ' '.$attributes['TYPE'];
-
- if ( ! empty($attributes['CONSTRAINT']))
- {
- switch (strtolower($attributes['TYPE']))
- {
- case 'decimal':
- case 'float':
- case 'numeric':
- $sql .= '('.implode(',', $attributes['CONSTRAINT']).')';
- break;
- case 'enum':
- case 'set':
- $sql .= '("'.implode('","', $attributes['CONSTRAINT']).'")';
- break;
- default:
- $sql .= '('.$attributes['CONSTRAINT'].')';
- }
- }
- }
+ protected $_create_table_keys = TRUE;
- if ( ! empty($attributes['UNSIGNED']) && $attributes['UNSIGNED'] === TRUE)
- {
- $sql .= ' UNSIGNED';
- }
-
- if (isset($attributes['DEFAULT']))
- {
- $sql .= " DEFAULT '".$attributes['DEFAULT']."'";
- }
+ /**
+ * UNSIGNED support
+ *
+ * @var array
+ */
+ protected $_unsigned = array(
+ 'TINYINT',
+ 'SMALLINT',
+ 'MEDIUMINT',
+ 'INT',
+ 'INTEGER',
+ 'BIGINT',
+ 'REAL',
+ 'DOUBLE',
+ 'DOUBLE PRECISION',
+ 'FLOAT',
+ 'DECIMAL',
+ 'NUMERIC'
+ );
- $sql .= ( ! empty($attributes['NULL']) && $attributes['NULL'] === TRUE)
- ? ' NULL' : ' NOT NULL';
+ /**
+ * NULL value representation in CREATE/ALTER TABLE statements
+ *
+ * @var string
+ */
+ protected $_null = 'NULL';
- if ( ! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === TRUE)
- {
- $sql .= ' AUTO_INCREMENT';
- }
- }
+ // --------------------------------------------------------------------
- // don't add a comma on the end of the last field
- if (++$current_field_count < count($fields))
- {
- $sql .= ',';
- }
- }
+ /**
+ * Class constructor
+ *
+ * @param object &$db Database object
+ * @return void
+ */
+ public function __construct(&$db)
+ {
+ parent::__construct($db);
- return $sql;
+ $this->_create_table .= ' DEFAULT CHARSET '.$this->db->char_set.' COLLATE '.$this->db->dbcollat;
}
// --------------------------------------------------------------------
/**
- * Create Table
+ * ALTER TABLE
*
- * @param string the table name
- * @param mixed the fields
- * @param mixed primary key(s)
- * @param mixed key(s)
- * @param bool should 'IF NOT EXISTS' be added to the SQL
- * @return bool
+ * @param string $alter_type ALTER type
+ * @param string $table Table name
+ * @param mixed $field Column definition
+ * @return string|string[]
*/
- protected function _create_table($table, $fields, $primary_keys, $keys, $if_not_exists)
+ protected function _alter_table($alter_type, $table, $field)
{
- $sql = 'CREATE TABLE ';
-
- if ($if_not_exists === TRUE)
- {
- $sql .= 'IF NOT EXISTS ';
- }
-
- $sql .= $this->db->escape_identifiers($table).' ('.$this->_process_fields($fields);
-
- if (count($primary_keys) > 0)
+ if ($alter_type === 'DROP')
{
- $key_name = $this->db->escape_identifiers(implode('_', $primary_keys));
- $sql .= ",\n\tPRIMARY KEY ".$key_name.' ('.implode(', ', $this->db->escape_identifiers($primary_keys)).')';
+ return parent::_alter_table($alter_type, $table, $field);
}
- if (is_array($keys) && count($keys) > 0)
+ $sql = 'ALTER TABLE '.$this->db->escape_identifiers($table);
+ for ($i = 0, $c = count($field); $i < $c; $i++)
{
- foreach ($keys as $key)
+ if ($field[$i]['_literal'] !== FALSE)
{
- if (is_array($key))
+ $field[$i] = ($alter_type === 'ADD')
+ ? "\n\tADD ".$field[$i]['_literal']
+ : "\n\tMODIFY ".$field[$i]['_literal'];
+ }
+ else
+ {
+ if ($alter_type === 'ADD')
{
- $key_name = $this->db->escape_identifiers(implode('_', $key));
- $key = $this->db->escape_identifiers($key);
+ $field[$i]['_literal'] = "\n\tADD ";
}
else
{
- $key_name = $this->db->escape_identifiers($key);
- $key = array($key_name);
+ $field[$i]['_literal'] = empty($field[$i]['new_name']) ? "\n\tMODIFY " : "\n\tCHANGE ";
}
- $sql .= ",\n\tKEY ".$key_name.' ('.implode(', ', $key).')';
+ $field[$i] = $field[$i]['_literal'].$this->_process_column($field[$i]);
}
}
- return $sql."\n) DEFAULT CHARACTER SET ".$this->db->char_set.' COLLATE '.$this->db->dbcollat.';';
+ return array($sql.implode(',', $field));
}
// --------------------------------------------------------------------
/**
- * Alter table query
+ * Process column
*
- * Generates a platform-specific query so that a table can be altered
- * Called by add_column(), drop_column(), and column_alter(),
+ * @param array $field
+ * @return string
+ */
+ protected function _process_column($field)
+ {
+ $extra_clause = isset($field['after'])
+ ? ' AFTER '.$this->db->escape_identifiers($field['after']) : '';
+
+ if (empty($extra_clause) && isset($field['first']) && $field['first'] === TRUE)
+ {
+ $extra_clause = ' FIRST';
+ }
+
+ return $this->db->escape_identifiers($field['name'])
+ .(empty($field['new_name']) ? '' : $this->db->escape_identifiers($field['new_name']))
+ .' '.$field['type'].$field['length']
+ .$field['unsigned']
+ .$field['null']
+ .$field['default']
+ .$field['auto_increment']
+ .$field['unique']
+ .$extra_clause;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Process indexes
*
- * @param string the ALTER type (ADD, DROP, CHANGE)
- * @param string the column name
- * @param array fields
- * @param string the field after which we should add the new field
+ * @param string $table (ignored)
* @return string
*/
- protected function _alter_table($alter_type, $table, $fields, $after_field = '')
+ protected function _process_indexes($table = NULL)
{
- $sql = 'ALTER TABLE '.$this->db->escape_identifiers($table).' '.$alter_type.' ';
+ $sql = '';
- // DROP has everything it needs now.
- if ($alter_type === 'DROP')
+ for ($i = 0, $c = count($this->keys); $i < $c; $i++)
{
- return $sql.$this->db->escape_identifiers($fields);
+ if ( ! isset($this->fields[$this->keys[$i]]))
+ {
+ unset($this->keys[$i]);
+ continue;
+ }
+
+ is_array($this->keys[$i]) OR $this->keys[$i] = array($this->keys[$i]);
+
+ $sql .= ",\n\tKEY ".$this->db->escape_identifiers(implode('_', $this->keys[$i]))
+ .' ('.implode(', ', $this->db->escape_identifiers($this->keys[$i])).')';
}
- return $sql.$this->_process_fields($fields)
- .($after_field !== '' ? ' AFTER '.$this->db->escape_identifiers($after_field) : '');
+ $this->keys = array();
+
+ return $sql;
}
}
diff --git a/system/database/drivers/mysqli/mysqli_result.php b/system/database/drivers/mysqli/mysqli_result.php
index f036302bb..15e15cd5f 100644
--- a/system/database/drivers/mysqli/mysqli_result.php
+++ b/system/database/drivers/mysqli/mysqli_result.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* MySQLi Result Class
@@ -130,9 +131,9 @@ class CI_DB_mysqli_result extends CI_DB_result {
*
* Moves the internal pointer to the desired offset. We call
* this internally before fetching results to make sure the
- * result set starts at zero
+ * result set starts at zero.
*
- * @param int $n = 0
+ * @param int $n
* @return bool
*/
protected function _data_seek($n = 0)
@@ -161,7 +162,7 @@ class CI_DB_mysqli_result extends CI_DB_result {
*
* Returns the result set as an object
*
- * @param string
+ * @param string $class_name
* @return object
*/
protected function _fetch_object($class_name = 'stdClass')
diff --git a/system/database/drivers/mysqli/mysqli_utility.php b/system/database/drivers/mysqli/mysqli_utility.php
index 5d2bdbce0..345691e84 100644
--- a/system/database/drivers/mysqli/mysqli_utility.php
+++ b/system/database/drivers/mysqli/mysqli_utility.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* MySQLi Utility Class
@@ -34,14 +35,33 @@
*/
class CI_DB_mysqli_utility extends CI_DB_utility {
+ /**
+ * List databases statement
+ *
+ * @var string
+ */
protected $_list_databases = 'SHOW DATABASES';
+
+ /**
+ * OPTIMIZE TABLE statement
+ *
+ * @var string
+ */
protected $_optimize_table = 'OPTIMIZE TABLE %s';
+
+ /**
+ * REPAIR TABLE statement
+ *
+ * @var string
+ */
protected $_repair_table = 'REPAIR TABLE %s';
+ // --------------------------------------------------------------------
+
/**
- * MySQLi Export
+ * Export
*
- * @param array Preferences
+ * @param array $params Preferences
* @return mixed
*/
protected function _backup($params = array())
diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php
index 81d73d073..eb01dd17e 100644
--- a/system/database/drivers/oci8/oci8_driver.php
+++ b/system/database/drivers/oci8/oci8_driver.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* oci8 Database Adapter Class
@@ -49,34 +50,76 @@
*/
class CI_DB_oci8_driver extends CI_DB {
+ /**
+ * Database driver
+ *
+ * @var string
+ */
public $dbdriver = 'oci8';
- // The character used for excaping
- protected $_escape_char = '"';
+ /**
+ * Statement ID
+ *
+ * @var resource
+ */
+ public $stmt_id;
/**
- * The syntax to count rows is slightly different across different
- * database engines, so this string appears in each driver and is
- * used for the count_all() and count_all_results() functions.
+ * Cursor ID
+ *
+ * @var resource
*/
- protected $_count_string = 'SELECT COUNT(1) AS ';
- protected $_random_keyword = ' ASC'; // not currently supported
+ public $curs_id;
+
+ /**
+ * Commit mode flag
+ *
+ * @var int
+ */
+ public $commit_mode = OCI_COMMIT_ON_SUCCESS;
+ /**
+ * Limit used flag
+ *
+ * If we use LIMIT, we'll add a field that will
+ * throw off num_fields later.
+ *
+ * @var bool
+ */
+ public $limit_used;
+
+ // --------------------------------------------------------------------
+
+ /**
+ * List of reserved identifiers
+ *
+ * Identifiers that must NOT be escaped.
+ *
+ * @var string[]
+ */
protected $_reserved_identifiers = array('*', 'rownum');
- // Set "auto commit" by default
- public $commit_mode = OCI_COMMIT_ON_SUCCESS;
+ /**
+ * ORDER BY random keyword
+ *
+ * @var string
+ */
+ protected $_random_keyword = ' ASC'; // not currently supported
- // need to track statement id and cursor id
- public $stmt_id;
- public $curs_id;
+ /**
+ * COUNT string
+ *
+ * @used-by CI_DB_driver::count_all()
+ * @used-by CI_DB_query_builder::count_all_results()
+ *
+ * @var string
+ */
+ protected $_count_string = 'SELECT COUNT(1) AS ';
- // if we use a limit, we will add a field that will
- // throw off num_fields later
- public $limit_used;
+ // --------------------------------------------------------------------
/**
- * Constructor
+ * Class constructor
*
* @param array $params
* @return void
@@ -197,9 +240,21 @@ class CI_DB_oci8_driver extends CI_DB {
*/
public function version()
{
- return isset($this->data_cache['version'])
- ? $this->data_cache['version']
- : $this->data_cache['version'] = oci_server_version($this->conn_id);
+ if (isset($this->data_cache['version']))
+ {
+ return $this->data_cache['version'];
+ }
+ elseif ( ! $this->conn_id)
+ {
+ $this->initialize();
+ }
+
+ if ( ! $this->conn_id OR ($version = oci_server_version($this->conn_id)) === FALSE)
+ {
+ return FALSE;
+ }
+
+ return $this->data_cache['version'] = $version;
}
// --------------------------------------------------------------------
@@ -207,7 +262,7 @@ class CI_DB_oci8_driver extends CI_DB {
/**
* Execute the query
*
- * @param string an SQL query
+ * @param string $sql an SQL query
* @return resource
*/
protected function _execute($sql)
@@ -226,7 +281,7 @@ class CI_DB_oci8_driver extends CI_DB {
/**
* Generate a statement ID
*
- * @param string an SQL query
+ * @param string $sql an SQL query
* @return void
*/
protected function _set_stmt_id($sql)
@@ -306,7 +361,7 @@ class CI_DB_oci8_driver extends CI_DB {
/**
* Bind parameters
*
- * @param array
+ * @param array $params
* @return void
*/
protected function _bind_params($params)
@@ -335,7 +390,7 @@ class CI_DB_oci8_driver extends CI_DB {
/**
* Begin Transaction
*
- * @param bool
+ * @param bool $test_mode
* @return bool
*/
public function trans_begin($test_mode = FALSE)
@@ -408,8 +463,8 @@ class CI_DB_oci8_driver extends CI_DB {
/**
* Escape String
*
- * @param string
- * @param bool whether or not the string will be used in a LIKE condition
+ * @param string $str
+ * @param bool $like Whether or not the string will be used in a LIKE condition
* @return string
*/
public function escape_str($str, $like = FALSE)
@@ -469,7 +524,7 @@ class CI_DB_oci8_driver extends CI_DB {
*
* Generates a platform-specific query string so that the table names can be fetched
*
- * @param bool
+ * @param bool $prefix_limit
* @return string
*/
protected function _list_tables($prefix_limit = FALSE)
@@ -492,7 +547,7 @@ class CI_DB_oci8_driver extends CI_DB {
*
* Generates a platform-specific query string so that the column names can be fetched
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _list_columns($table = '')
@@ -507,7 +562,7 @@ class CI_DB_oci8_driver extends CI_DB {
*
* Generates a platform-specific query so that the column data can be retrieved
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _field_data($table)
@@ -549,13 +604,13 @@ class CI_DB_oci8_driver extends CI_DB {
// --------------------------------------------------------------------
/**
- * Insert_batch statement
+ * Insert batch statement
*
* Generates a platform-specific insert string from the supplied data
*
- * @param string the table name
- * @param array the insert keys
- * @param array the insert values
+ * @param string $table Table name
+ * @param array $keys INSERT keys
+ * @param array $values INSERT values
* @return string
*/
protected function _insert_batch($table, $keys, $values)
@@ -578,10 +633,10 @@ class CI_DB_oci8_driver extends CI_DB {
*
* Generates a platform-specific truncate string from the supplied data
*
- * If the database does not support the truncate() command,
+ * If the database does not support the TRUNCATE statement,
* then this method maps to 'DELETE FROM table'
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _truncate($table)
@@ -596,7 +651,7 @@ class CI_DB_oci8_driver extends CI_DB {
*
* Generates a platform-specific delete string from the supplied data
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _delete($table)
@@ -613,11 +668,11 @@ class CI_DB_oci8_driver extends CI_DB {
// --------------------------------------------------------------------
/**
- * Limit string
+ * LIMIT
*
* Generates a platform-specific LIMIT clause
*
- * @param string the sql query string
+ * @param string $sql SQL Query
* @return string
*/
protected function _limit($sql)
diff --git a/system/database/drivers/oci8/oci8_forge.php b/system/database/drivers/oci8/oci8_forge.php
index 92e8c02ed..bd9d2df3c 100644
--- a/system/database/drivers/oci8/oci8_forge.php
+++ b/system/database/drivers/oci8/oci8_forge.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Oracle Forge Class
@@ -34,122 +35,96 @@
*/
class CI_DB_oci8_forge extends CI_DB_forge {
+ /**
+ * CREATE DATABASE statement
+ *
+ * @var string
+ */
protected $_create_database = FALSE;
+
+ /**
+ * DROP DATABASE statement
+ *
+ * @var string
+ */
protected $_drop_database = FALSE;
- protected $_drop_table = 'DROP TABLE %s';
/**
- * Create Table
+ * DROP TABLE IF statement
*
- * @param string the table name
- * @param array the fields
- * @param mixed primary key(s)
- * @param mixed key(s)
- * @param bool should 'IF NOT EXISTS' be added to the SQL
- * @return string
+ * @var string
*/
- protected function _create_table($table, $fields, $primary_keys, $keys, $if_not_exists)
- {
- $sql = 'CREATE TABLE ';
+ protected $_drop_table_if = FALSE;
+
+ /**
+ * UNSIGNED support
+ *
+ * @var bool|array
+ */
+ protected $_unsigned = FALSE;
- if ($if_not_exists === TRUE)
+ // --------------------------------------------------------------------
+
+ /**
+ * ALTER TABLE
+ *
+ * @param string $alter_type ALTER type
+ * @param string $table Table name
+ * @param mixed $field Column definition
+ * @return string|string[]
+ */
+ protected function _alter_table($alter_type, $table, $field)
+ {
+ if ($alter_type === 'DROP')
{
- $sql .= 'IF NOT EXISTS ';
+ return parent::_alter_table($alter_type, $table, $field);
+ }
+ elseif ($alter_type === 'CHANGE')
+ {
+ $alter_type = 'MODIFY';
}
- $sql .= $this->db->escape_identifiers($table).' (';
- $current_field_count = 0;
-
- foreach ($fields as $field => $attributes)
+ $sql = 'ALTER TABLE '.$this->db->escape_identifiers($table);
+ $sqls = array();
+ for ($i = 0, $c = count($field); $i < $c; $i++)
{
- // Numeric field names aren't allowed in databases, so if the key is
- // numeric, we know it was assigned by PHP and the developer manually
- // entered the field information, so we'll simply add it to the list
- if (is_numeric($field))
+ if ($field[$i]['_literal'] !== FALSE)
{
- $sql .= "\n\t".$attributes;
+ $field[$i] = "\n\t".$field[$i]['_literal'];
}
else
{
- $attributes = array_change_key_case($attributes, CASE_UPPER);
-
- $sql .= "\n\t".$this->db->escape_identifiers($field).' '.$attributes['TYPE'];
-
- if (isset($attributes['UNSINGED']) && $attributes['UNSIGNED'] === TRUE)
+ $field[$i]['_literal'] = "\n\t".$this->_process_column($field[$i]);
+ if ($alter_type === 'MODIFY' && ! empty($field[$i]['new_name']))
{
- $sql .= ' UNSIGNED';
+ $sqls[] = $sql.' RENAME COLUMN '.$this->db->escape_identifiers($field[$i]['name'])
+ .' '.$this->db->escape_identifiers($field[$i]['new_name']);
}
-
- if (isset($attributes['DEFAULT']))
- {
- $sql .= " DEFAULT '".$attributes['DEFAULT']."'";
- }
-
- $sql .= (isset($attributes['NULL']) && $attributes['NULL'] === TRUE)
- ? '' : ' NOT NULL';
-
- empty($attributes['CONSTRAINT']) OR ' CONSTRAINT '.$attributes['CONSTRAINT'];
- }
-
- // don't add a comma on the end of the last field
- if (++$current_field_count < count($fields))
- {
- $sql .= ',';
}
}
- if (count($primary_keys) > 0)
- {
- $sql .= ",\n\tCONSTRAINT ".$table.' PRIMARY KEY ('.implode(', ', $this->db->escape_identifiers($primary_keys)).')';
- }
+ $sql .= ' '.$alter_type.' ';
+ $sql .= (count($field) === 1)
+ ? $fields[0]
+ : '('.implode(',', $field).')';
- if (is_array($keys) && count($keys) > 0)
- {
- foreach ($keys as $key)
- {
- $key = is_array($key)
- ? $this->db->escape_identifiers($key)
- : array($this->db->escape_identifiers($key));
-
- $sql .= ",\n\tUNIQUE COLUMNS (".implode(', ', $key).')';
- }
- }
-
- return $sql."\n)";
+ // RENAME COLUMN must be executed after MODIFY
+ array_unshift($sqls, $sql);
+ return $sql;
}
// --------------------------------------------------------------------
/**
- * Alter table query
- *
- * Generates a platform-specific query so that a table can be altered
- * Called by add_column(), drop_column(), and column_alter(),
+ * Field attribute AUTO_INCREMENT
*
- * @param string the ALTER type (ADD, DROP, CHANGE)
- * @param string the column name
- * @param string the table name
- * @param string the column definition
- * @param string the default value
- * @param bool should 'NOT NULL' be added
- * @param string the field after which we should add the new field
- * @return string
+ * @param array &$attributes
+ * @param array &$field
+ * @return void
*/
- protected function _alter_table($alter_type, $table, $column_name, $column_definition = '', $default_value = '', $null = '', $after_field = '')
+ protected function _attr_auto_increment(&$attributes, &$field)
{
- $sql = 'ALTER TABLE '.$this->db->escape_identifiers($table).' '.$alter_type.' '.$this->db->escape_identifiers($column_name);
-
- // DROP has everything it needs now.
- if ($alter_type === 'DROP')
- {
- return $sql;
- }
-
- return $sql.' '.$column_definition
- .($default_value !== '' ? ' DEFAULT "'.$default_value.'"' : '')
- .($null === NULL ? ' NULL' : ' NOT NULL')
- .($after_field !== '' ? ' AFTER '.$this->db->escape_identifiers($after_field) : '');
-
+ // Not supported - sequences and triggers must be used instead
}
}
diff --git a/system/database/drivers/oci8/oci8_result.php b/system/database/drivers/oci8/oci8_result.php
index ade186be7..7d5bf5172 100644
--- a/system/database/drivers/oci8/oci8_result.php
+++ b/system/database/drivers/oci8/oci8_result.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* oci8 Result Class
@@ -37,15 +38,40 @@
*/
class CI_DB_oci8_result extends CI_DB_result {
+ /**
+ * Statement ID
+ *
+ * @var resource
+ */
public $stmt_id;
+
+ /**
+ * Cursor ID
+ *
+ * @var resource
+ */
public $curs_id;
+
+ /**
+ * Limit used flag
+ *
+ * @var bool
+ */
public $limit_used;
+
+ /**
+ * Commit mode flag
+ *
+ * @var int
+ */
public $commit_mode;
+ // --------------------------------------------------------------------
+
/**
- * Constructor
+ * Class constructor
*
- * @param object
+ * @param object &$driver_object
* @return void
*/
public function __construct(&$driver_object)
@@ -167,7 +193,7 @@ class CI_DB_oci8_result extends CI_DB_result {
*
* Returns the result set as an object
*
- * @param string
+ * @param string $class_name
* @return object
*/
protected function _fetch_object($class_name = 'stdClass')
@@ -211,9 +237,10 @@ class CI_DB_oci8_result extends CI_DB_result {
* some point in the future, but it will only work for resetting the
* pointer to zero.
*
+ * @param int $n (ignored)
* @return bool
*/
- protected function _data_seek()
+ protected function _data_seek($n = 0)
{
/* The PHP manual says that if OCI_NO_AUTO_COMMIT mode
* is used, and oci_rollback() and/or oci_commit() are
diff --git a/system/database/drivers/oci8/oci8_utility.php b/system/database/drivers/oci8/oci8_utility.php
index 0183eda26..d15537fdf 100644
--- a/system/database/drivers/oci8/oci8_utility.php
+++ b/system/database/drivers/oci8/oci8_utility.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Oracle Utility Class
@@ -34,18 +35,23 @@
*/
class CI_DB_oci8_utility extends CI_DB_utility {
+ /**
+ * List databases statement
+ *
+ * @var string
+ */
protected $_list_databases = 'SELECT username FROM dba_users'; // Schemas are actual usernames
/**
- * Oracle Export
+ * Export
*
- * @param array Preferences
+ * @param array $params Preferences
* @return mixed
*/
protected function _backup($params = array())
{
// Currently unsupported
- return $this->db->display_error('db_unsuported_feature');
+ return $this->db->display_error('db_unsupported_feature');
}
}
diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php
index f6ea412ad..1710aafae 100644
--- a/system/database/drivers/odbc/odbc_driver.php
+++ b/system/database/drivers/odbc/odbc_driver.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* ODBC Database Adapter Class
@@ -40,24 +41,42 @@
*/
class CI_DB_odbc_driver extends CI_DB {
+ /**
+ * Database driver
+ *
+ * @var string
+ */
public $dbdriver = 'odbc';
- // the character used to excape - not necessary for ODBC
- protected $_escape_char = '';
+ /**
+ * Database schema
+ *
+ * @var string
+ */
+ public $schema = 'public';
- protected $_like_escape_str = " {escape '%s'} ";
+ // --------------------------------------------------------------------
- protected $_random_keyword;
+ /**
+ * Identifier escape character
+ *
+ * Must be empty for ODBC.
+ *
+ * @var string
+ */
+ protected $_escape_char = '';
/**
- * Database schema
+ * ESCAPE statement string
*
* @var string
*/
- public $schema = 'public';
+ protected $_like_escape_str = " {escape '%s'} ";
+
+ // --------------------------------------------------------------------
/**
- * Constructor
+ * Class constructor
*
* @param array $params
* @return void
@@ -104,7 +123,7 @@ class CI_DB_odbc_driver extends CI_DB {
/**
* Execute the query
*
- * @param string an SQL query
+ * @param string $sql an SQL query
* @return resource
*/
protected function _execute($sql)
@@ -117,7 +136,7 @@ class CI_DB_odbc_driver extends CI_DB {
/**
* Begin Transaction
*
- * @param bool $test_mode = FALSE
+ * @param bool $test_mode
* @return bool
*/
public function trans_begin($test_mode = FALSE)
@@ -181,8 +200,8 @@ class CI_DB_odbc_driver extends CI_DB {
/**
* Escape String
*
- * @param string
- * @param bool whether or not the string will be used in a LIKE condition
+ * @param string $str
+ * @param bool $like Whether or not the string will be used in a LIKE condition
* @return string
*/
public function escape_str($str, $like = FALSE)
@@ -231,7 +250,7 @@ class CI_DB_odbc_driver extends CI_DB {
*/
public function insert_id()
{
- return ($this->db->db_debug) ? $this->db->display_error('db_unsuported_feature') : FALSE;
+ return ($this->db->db_debug) ? $this->db->display_error('db_unsupported_feature') : FALSE;
}
// --------------------------------------------------------------------
@@ -241,7 +260,7 @@ class CI_DB_odbc_driver extends CI_DB {
*
* Generates a platform-specific query string so that the table names can be fetched
*
- * @param bool $prefix_limit = FALSE
+ * @param bool $prefix_limit
* @return string
*/
protected function _list_tables($prefix_limit = FALSE)
@@ -264,7 +283,7 @@ class CI_DB_odbc_driver extends CI_DB {
*
* Generates a platform-specific query string so that the column names can be fetched
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _list_columns($table = '')
@@ -279,7 +298,7 @@ class CI_DB_odbc_driver extends CI_DB {
*
* Generates a platform-specific query so that the column data can be retrieved
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _field_data($table)
@@ -309,8 +328,8 @@ class CI_DB_odbc_driver extends CI_DB {
*
* Generates a platform-specific update string from the supplied data
*
- * @param string the table name
- * @param array the update data
+ * @param string $table
+ * @param array $values
* @return string
*/
protected function _update($table, $values)
@@ -327,10 +346,10 @@ class CI_DB_odbc_driver extends CI_DB {
*
* Generates a platform-specific truncate string from the supplied data
*
- * If the database does not support the truncate() command,
+ * If the database does not support the TRUNCATE statement,
* then this method maps to 'DELETE FROM table'
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _truncate($table)
@@ -345,7 +364,7 @@ class CI_DB_odbc_driver extends CI_DB {
*
* Generates a platform-specific delete string from the supplied data
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _delete($table)
diff --git a/system/database/drivers/odbc/odbc_forge.php b/system/database/drivers/odbc/odbc_forge.php
index d17b046ee..fb16ca5cf 100644
--- a/system/database/drivers/odbc/odbc_forge.php
+++ b/system/database/drivers/odbc/odbc_forge.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* ODBC Forge Class
@@ -34,124 +35,39 @@
*/
class CI_DB_odbc_forge extends CI_DB_forge {
- protected $_drop_table = 'DROP TABLE %s';
-
/**
- * Create Table
+ * CREATE TABLE IF statement
*
- * @param string the table name
- * @param array the fields
- * @param mixed primary key(s)
- * @param mixed key(s)
- * @param bool should 'IF NOT EXISTS' be added to the SQL
- * @return bool
+ * @var string
*/
- protected function _create_table($table, $fields, $primary_keys, $keys, $if_not_exists)
- {
- $sql = 'CREATE TABLE ';
-
- if ($if_not_exists === TRUE)
- {
- $sql .= 'IF NOT EXISTS ';
- }
-
- $sql .= $this->db->escape_identifiers($table).' (';
- $current_field_count = 0;
-
- foreach ($fields as $field => $attributes)
- {
- // Numeric field names aren't allowed in databases, so if the key is
- // numeric, we know it was assigned by PHP and the developer manually
- // entered the field information, so we'll simply add it to the list
- if (is_numeric($field))
- {
- $sql .= "\n\t".$attributes;
- }
- else
- {
- $attributes = array_change_key_case($attributes, CASE_UPPER);
-
- $sql .= "\n\t".$this->db->escape_identifiers($field).' '.$attributes['TYPE'];
-
- empty($attributes['CONSTRAINT']) OR $sql .= '('.$attributes['CONSTRAINT'].')';
-
- if ( ! empty($attributes['UNSIGNED']) && $attributes['UNSIGNED'] === TRUE)
- {
- $sql .= ' UNSIGNED';
- }
-
- if (isset($attributes['DEFAULT']))
- {
- $sql .= " DEFAULT '".$attributes['DEFAULT']."'";
- }
-
- $sql .= ( ! empty($attributes['NULL']) && $attributes['NULL'] === TRUE)
- ? ' NULL' : ' NOT NULL';
-
- if ( ! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === TRUE)
- {
- $sql .= ' AUTO_INCREMENT';
- }
- }
-
- // don't add a comma on the end of the last field
- if (++$current_field_count < count($fields))
- {
- $sql .= ',';
- }
- }
+ protected $_create_table_if = FALSE;
- if (count($primary_keys) > 0)
- {
- $sql .= ",\n\tPRIMARY KEY (".implode(', ', $this->escape_identifiers($primary_keys)).')';
- }
-
- if (is_array($keys) && count($keys) > 0)
- {
- foreach ($keys as $key)
- {
- $key = is_array($key)
- ? $this->db->escape_identifiers($key)
- : array($this->db->escape_identifiers($key));
-
- $sql .= ",\n\tFOREIGN KEY (".implode(', ', $key).')';
- }
- }
+ /**
+ * DROP TABLE IF statement
+ *
+ * @var string
+ */
+ protected $_drop_table_if = FALSE;
- return $sql."\n)";
- }
+ /**
+ * UNSIGNED support
+ *
+ * @var bool|array
+ */
+ protected $_unsigned = FALSE;
// --------------------------------------------------------------------
/**
- * Alter table query
+ * Field attribute AUTO_INCREMENT
*
- * Generates a platform-specific query so that a table can be altered
- * Called by add_column(), drop_column(), and column_alter(),
- *
- * @param string the ALTER type (ADD, DROP, CHANGE)
- * @param string the column name
- * @param string the table name
- * @param string the column definition
- * @param string the default value
- * @param bool should 'NOT NULL' be added
- * @param string the field after which we should add the new field
- * @return string
+ * @param array &$attributes
+ * @param array &$field
+ * @return void
*/
- protected function _alter_table($alter_type, $table, $column_name, $column_definition = '', $default_value = '', $null = '', $after_field = '')
+ protected function _attr_auto_increment(&$attributes, &$field)
{
- $sql = 'ALTER TABLE '.$this->db->escape_identifiers($table).' '.$alter_type.' '.$this->db->escape_identifiers($column_name);
-
- // DROP has everything it needs now.
- if ($alter_type === 'DROP')
- {
- return $sql;
- }
-
- return $sql.' '.$column_definition
- .($default_value != '' ? ' DEFAULT "'.$default_value.'"' : '')
- .($null === NULL ? ' NULL' : ' NOT NULL')
- .($after_field != '' ? ' AFTER '.$this->db->escape_identifiers($after_field) : '');
+ // Not supported (in most databases at least)
}
}
diff --git a/system/database/drivers/odbc/odbc_result.php b/system/database/drivers/odbc/odbc_result.php
index 48dc48dd9..2c50c255b 100644
--- a/system/database/drivers/odbc/odbc_result.php
+++ b/system/database/drivers/odbc/odbc_result.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* ODBC Result Class
@@ -165,7 +166,7 @@ class CI_DB_odbc_result extends CI_DB_result {
*
* Returns the result set as an object
*
- * @param string
+ * @param string $class_name
* @return object
*/
protected function _fetch_object($class_name = 'stdClass')
@@ -198,11 +199,11 @@ if ( ! function_exists('odbc_fetch_array'))
* Emulates the native odbc_fetch_array() function when
* it is not available (odbc_fetch_array() requires unixODBC)
*
- * @param resource
- * @param int
+ * @param resource &$result
+ * @param int $rownumber
* @return array
*/
- function odbc_fetch_array(& $result, $rownumber = 1)
+ function odbc_fetch_array(&$result, $rownumber = 1)
{
$rs = array();
if ( ! odbc_fetch_into($result, $rs, $rownumber))
@@ -231,11 +232,11 @@ if ( ! function_exists('odbc_fetch_object'))
* Emulates the native odbc_fetch_object() function when
* it is not available.
*
- * @param resource
- * @param int
+ * @param resource &$result
+ * @param int $rownumber
* @return object
*/
- function odbc_fetch_object(& $result, $rownumber = 1)
+ function odbc_fetch_object(&$result, $rownumber = 1)
{
$rs = array();
if ( ! odbc_fetch_into($result, $rs, $rownumber))
diff --git a/system/database/drivers/odbc/odbc_utility.php b/system/database/drivers/odbc/odbc_utility.php
index 224d48d2b..908674a9d 100644
--- a/system/database/drivers/odbc/odbc_utility.php
+++ b/system/database/drivers/odbc/odbc_utility.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* ODBC Utility Class
@@ -34,18 +35,16 @@
*/
class CI_DB_odbc_utility extends CI_DB_utility {
- protected $_list_databases = FALSE;
-
/**
- * ODBC Export
+ * Export
*
- * @param array Preferences
+ * @param array $params Preferences
* @return mixed
*/
protected function _backup($params = array())
{
// Currently unsupported
- return $this->db->display_error('db_unsuported_feature');
+ return $this->db->display_error('db_unsupported_feature');
}
}
diff --git a/system/database/drivers/pdo/pdo_driver.php b/system/database/drivers/pdo/pdo_driver.php
index 32a9e7509..923f0e125 100644
--- a/system/database/drivers/pdo/pdo_driver.php
+++ b/system/database/drivers/pdo/pdo_driver.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 2.1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* PDO Database Adapter Class
@@ -40,22 +41,33 @@
*/
class CI_DB_pdo_driver extends CI_DB {
+ /**
+ * Database driver
+ *
+ * @var string
+ */
public $dbdriver = 'pdo';
- // The character used to escaping
- protected $_escape_char = '"';
-
- protected $_random_keyword;
-
+ /**
+ * Transaction enabled flag
+ *
+ * @var bool
+ */
public $trans_enabled = FALSE;
- // need to track the PDO options
+ /**
+ * PDO Options
+ *
+ * @var array
+ */
public $options = array();
+ // --------------------------------------------------------------------
+
/**
- * Constructor
+ * Class constructor
*
- * Validates the DSN string and/or detects the subdriver
+ * Validates the DSN string and/or detects the subdriver.
*
* @param array $params
* @return void
@@ -103,9 +115,9 @@ class CI_DB_pdo_driver extends CI_DB {
// --------------------------------------------------------------------
/**
- * Non-persistent database connection
+ * Database connection
*
- * @param bool
+ * @param bool $persistent
* @return object
*/
public function db_connect($persistent = FALSE)
@@ -153,6 +165,10 @@ class CI_DB_pdo_driver extends CI_DB {
{
return $this->data_cache['version'];
}
+ elseif ( ! $this->conn_id)
+ {
+ $this->initialize();
+ }
// Not all subdrivers support the getAttribute() method
try
@@ -170,7 +186,7 @@ class CI_DB_pdo_driver extends CI_DB {
/**
* Execute the query
*
- * @param string an SQL query
+ * @param string $sql SQL query
* @return mixed
*/
protected function _execute($sql)
@@ -183,7 +199,7 @@ class CI_DB_pdo_driver extends CI_DB {
/**
* Begin Transaction
*
- * @param bool $test_mode = FALSE
+ * @param bool $test_mode
* @return bool
*/
public function trans_begin($test_mode = FALSE)
@@ -243,8 +259,8 @@ class CI_DB_pdo_driver extends CI_DB {
/**
* Escape String
*
- * @param string
- * @param bool whether or not the string will be used in a LIKE condition
+ * @param string $str
+ * @param bool $like Whether or not the string will be used in a LIKE condition
* @return string
*/
public function escape_str($str, $like = FALSE)
@@ -296,7 +312,7 @@ class CI_DB_pdo_driver extends CI_DB {
/**
* Insert ID
*
- * @param string
+ * @param string $name
* @return int
*/
public function insert_id($name = NULL)
@@ -311,7 +327,7 @@ class CI_DB_pdo_driver extends CI_DB {
*
* Generates a platform-specific query so that the column data can be retrieved
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _field_data($table)
@@ -355,9 +371,9 @@ class CI_DB_pdo_driver extends CI_DB {
*
* Generates a platform-specific batch update string from the supplied data
*
- * @param string the table name
- * @param array the update data
- * @param string the where key
+ * @param string $table Table name
+ * @param array $values Update data
+ * @param string $index WHERE key
* @return string
*/
protected function _update_batch($table, $values, $index)
@@ -401,10 +417,10 @@ class CI_DB_pdo_driver extends CI_DB {
*
* Generates a platform-specific truncate string from the supplied data
*
- * If the database does not support the truncate() command,
+ * If the database does not support the TRUNCATE statement,
* then this method maps to 'DELETE FROM table'
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _truncate($table)
@@ -415,4 +431,4 @@ class CI_DB_pdo_driver extends CI_DB {
}
/* End of file pdo_driver.php */
-/* Location: ./system/database/drivers/pdo/pdo_driver.php */
+/* Location: ./system/database/drivers/pdo/pdo_driver.php */ \ No newline at end of file
diff --git a/system/database/drivers/pdo/pdo_forge.php b/system/database/drivers/pdo/pdo_forge.php
index 34a6ee44e..130d3667e 100644
--- a/system/database/drivers/pdo/pdo_forge.php
+++ b/system/database/drivers/pdo/pdo_forge.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 2.1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* PDO Forge Class
@@ -34,133 +35,19 @@
*/
class CI_DB_pdo_forge extends CI_DB_forge {
- protected $_drop_table = 'DROP TABLE %s';
-
/**
- * Create Table
+ * CREATE TABLE IF statement
*
- * @param string the table name
- * @param array the fields
- * @param mixed primary key(s)
- * @param mixed key(s)
- * @param bool should 'IF NOT EXISTS' be added to the SQL
- * @return bool
+ * @var string
*/
- protected function _create_table($table, $fields, $primary_keys, $keys, $if_not_exists)
- {
- $sql = 'CREATE TABLE ';
-
- if ($if_not_exists === TRUE)
- {
- $sql .= 'IF NOT EXISTS ';
- }
-
- $sql .= $this->db->escape_identifiers($table).' (';
- $current_field_count = 0;
-
- foreach ($fields as $field => $attributes)
- {
- // Numeric field names aren't allowed in databases, so if the key is
- // numeric, we know it was assigned by PHP and the developer manually
- // entered the field information, so we'll simply add it to the list
- if (is_numeric($field))
- {
- $sql .= "\n\t".$attributes;
- }
- else
- {
- $attributes = array_change_key_case($attributes, CASE_UPPER);
- $numeric = array('SERIAL', 'INTEGER');
-
- $sql .= "\n\t".$this->db->escape_identifiers($field).' '.$attributes['TYPE'];
-
- if ( ! empty($attributes['CONSTRAINT']))
- {
- // Exception for Postgre numeric which not too happy with constraint within those type
- if ( ! ($this->db->subdriver === 'pgsql' && in_array($attributes['TYPE'], $numeric)))
- {
- $sql .= '('.$attributes['CONSTRAINT'].')';
- }
- }
-
- if ( ! empty($attributes['UNSIGNED']) && $attributes['UNSIGNED'] === TRUE)
- {
- $sql .= ' UNSIGNED';
- }
-
- if (isset($attributes['DEFAULT']))
- {
- $sql .= " DEFAULT '".$attributes['DEFAULT']."'";
- }
-
- $sql .= ( ! empty($attributes['NULL']) && $attributes['NULL'] === TRUE)
- ? ' NULL' : ' NOT NULL';
-
- if ( ! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === TRUE)
- {
- $sql .= ' AUTO_INCREMENT';
- }
- }
-
- // don't add a comma on the end of the last field
- if (++$current_field_count < count($fields))
- {
- $sql .= ',';
- }
- }
-
- if (count($primary_keys) > 0)
- {
- $sql .= ",\n\tPRIMARY KEY (".implode(', ', $this->db->escape_identifiers($primary_keys)).')';
- }
-
- if (is_array($keys) && count($keys) > 0)
- {
- foreach ($keys as $key)
- {
- $key = is_array($key)
- ? $this->db->escape_identifiers($key)
- : array($this->db->escape_identifiers($key));
-
- $sql .= ",\n\tFOREIGN KEY (".implode(', ', $key).')';
- }
- }
-
- return $sql."\n)";
- }
-
- // --------------------------------------------------------------------
+ protected $_create_table_if = FALSE;
/**
- * Alter table query
- *
- * Generates a platform-specific query so that a table can be altered
- * Called by add_column(), drop_column(), and column_alter(),
+ * DROP TABLE IF statement
*
- * @param string the ALTER type (ADD, DROP, CHANGE)
- * @param string the column name
- * @param string the table name
- * @param string the column definition
- * @param string the default value
- * @param bool should 'NOT NULL' be added
- * @param string the field after which we should add the new field
- * @return string
+ * @var string
*/
- protected function _alter_table($alter_type, $table, $column_name, $column_definition = '', $default_value = '', $null = '', $after_field = '')
- {
- $sql = 'ALTER TABLE '.$this->db->escape_identifiers($table).' '.$alter_type.' '.$this->db->escape_identifiers($column_name);
-
- // DROP has everything it needs now.
- if ($alter_type === 'DROP')
- {
- return $sql;
- }
-
- return $sql .' '.$column_definition
- .($default_value !== '' ? " DEFAULT '".$default_value."'" : '')
- .($null === NULL ? ' NULL' : ' NOT NULL')
- .($after_field !== '' ? ' AFTER '.$this->db->escape_identifiers($after_field) : '');
- }
+ protected $_drop_table_if = FALSE;
}
diff --git a/system/database/drivers/pdo/pdo_result.php b/system/database/drivers/pdo/pdo_result.php
index 444406986..32ab1c280 100644
--- a/system/database/drivers/pdo/pdo_result.php
+++ b/system/database/drivers/pdo/pdo_result.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* PDO Result Class
@@ -162,7 +163,7 @@ class CI_DB_pdo_result extends CI_DB_result {
{
if ($this->db->db_debug)
{
- return $this->db->display_error('db_unsuported_feature');
+ return $this->db->display_error('db_unsupported_feature');
}
return FALSE;
@@ -205,7 +206,7 @@ class CI_DB_pdo_result extends CI_DB_result {
*
* Returns the result set as an object
*
- * @param string
+ * @param string $class_name
* @return object
*/
protected function _fetch_object($class_name = 'stdClass')
diff --git a/system/database/drivers/pdo/pdo_utility.php b/system/database/drivers/pdo/pdo_utility.php
index 930842118..86f2b120a 100644
--- a/system/database/drivers/pdo/pdo_utility.php
+++ b/system/database/drivers/pdo/pdo_utility.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 2.1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* PDO Utility Class
@@ -34,18 +35,16 @@
*/
class CI_DB_pdo_utility extends CI_DB_utility {
- protected $_list_databases = FALSE;
-
/**
- * PDO Export
+ * Export
*
- * @param array Preferences
+ * @param array $params Preferences
* @return mixed
*/
protected function _backup($params = array())
{
// Currently unsupported
- return $this->db->display_error('db_unsuported_feature');
+ return $this->db->display_error('db_unsupported_feature');
}
}
diff --git a/system/database/drivers/pdo/subdrivers/pdo_4d_driver.php b/system/database/drivers/pdo/subdrivers/pdo_4d_driver.php
index 438d312a1..6ebd92a9b 100644
--- a/system/database/drivers/pdo/subdrivers/pdo_4d_driver.php
+++ b/system/database/drivers/pdo/subdrivers/pdo_4d_driver.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 3.0.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* PDO 4D Database Adapter Class
@@ -40,19 +41,28 @@
*/
class CI_DB_pdo_4d_driver extends CI_DB_pdo_driver {
+ /**
+ * Sub-driver
+ *
+ * @var string
+ */
public $subdriver = '4d';
- // The character used for escaping
+ /**
+ * Identifier escape character
+ *
+ * @var string[]
+ */
protected $_escape_char = array('[', ']');
- protected $_random_keyword = ' RAND()';
+ // --------------------------------------------------------------------
/**
- * Constructor
+ * Class constructor
*
* Builds the DSN if not already set.
*
- * @param array
+ * @param array $params
* @return void
*/
public function __construct($params)
@@ -80,7 +90,7 @@ class CI_DB_pdo_4d_driver extends CI_DB_pdo_driver {
*
* Generates a platform-specific query string so that the table names can be fetched
*
- * @param bool
+ * @param bool $prefix_limit
* @return string
*/
protected function _list_tables($prefix_limit = FALSE)
@@ -103,7 +113,7 @@ class CI_DB_pdo_4d_driver extends CI_DB_pdo_driver {
*
* Generates a platform-specific query string so that the column names can be fetched
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _list_columns($table = '')
@@ -119,7 +129,7 @@ class CI_DB_pdo_4d_driver extends CI_DB_pdo_driver {
*
* Generates a platform-specific query so that the column data can be retrieved
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _field_data($table)
@@ -134,8 +144,8 @@ class CI_DB_pdo_4d_driver extends CI_DB_pdo_driver {
*
* Generates a platform-specific update string from the supplied data
*
- * @param string the table name
- * @param array the update data
+ * @param string $table
+ * @param array $values
* @return string
*/
protected function _update($table, $values)
@@ -152,7 +162,7 @@ class CI_DB_pdo_4d_driver extends CI_DB_pdo_driver {
*
* Generates a platform-specific delete string from the supplied data
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _delete($table)
@@ -164,11 +174,11 @@ class CI_DB_pdo_4d_driver extends CI_DB_pdo_driver {
// --------------------------------------------------------------------
/**
- * Limit string
+ * LIMIT
*
* Generates a platform-specific LIMIT clause
*
- * @param string the sql query string
+ * @param string $sql SQL Query
* @return string
*/
protected function _limit($sql)
diff --git a/system/database/drivers/pdo/subdrivers/pdo_4d_forge.php b/system/database/drivers/pdo/subdrivers/pdo_4d_forge.php
new file mode 100644
index 000000000..231ad53a4
--- /dev/null
+++ b/system/database/drivers/pdo/subdrivers/pdo_4d_forge.php
@@ -0,0 +1,209 @@
+<?php
+/**
+ * CodeIgniter
+ *
+ * An open source application development framework for PHP 5.2.4 or newer
+ *
+ * NOTICE OF LICENSE
+ *
+ * Licensed under the Open Software License version 3.0
+ *
+ * This source file is subject to the Open Software License (OSL 3.0) that is
+ * bundled with this package in the files license.txt / license.rst. It is
+ * also available through the world wide web at this URL:
+ * http://opensource.org/licenses/OSL-3.0
+ * If you did not receive a copy of the license and are unable to obtain it
+ * through the world wide web, please send an email to
+ * licensing@ellislab.com so we can send you a copy immediately.
+ *
+ * @package CodeIgniter
+ * @author EllisLab Dev Team
+ * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
+ * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
+ * @link http://codeigniter.com
+ * @since Version 2.1.0
+ * @filesource
+ */
+defined('BASEPATH') OR exit('No direct script access allowed');
+
+/**
+ * PDO 4D Forge Class
+ *
+ * @category Database
+ * @author EllisLab Dev Team
+ * @link http://codeigniter.com/user_guide/database/
+ */
+class CI_DB_pdo_4d_forge extends CI_DB_4d_forge {
+
+ /**
+ * CREATE DATABASE statement
+ *
+ * @var string
+ */
+ protected $_create_database = 'CREATE SCHEMA %s';
+
+ /**
+ * DROP DATABASE statement
+ *
+ * @var string
+ */
+ protected $_drop_database = 'DROP SCHEMA %s';
+
+ /**
+ * CREATE TABLE IF statement
+ *
+ * @var string
+ */
+ protected $_create_table_if = 'CREATE TABLE IF NOT EXISTS';
+
+ /**
+ * RENAME TABLE statement
+ *
+ * @var string
+ */
+ protected $_rename_table = FALSE;
+
+ /**
+ * DROP TABLE IF statement
+ *
+ * @var string
+ */
+ protected $_drop_table_if = 'DROP TABLE IF EXISTS';
+
+ /**
+ * UNSIGNED support
+ *
+ * @var array
+ */
+ protected $_unsigned = array(
+ 'INT16' => 'INT',
+ 'SMALLINT' => 'INT',
+ 'INT' => 'INT64',
+ 'INT32' => 'INT64'
+ );
+
+ /**
+ * DEFAULT value representation in CREATE/ALTER TABLE statements
+ *
+ * @var string
+ */
+ protected $_default = FALSE;
+
+ // --------------------------------------------------------------------
+
+ /**
+ * ALTER TABLE
+ *
+ * @param string $alter_type ALTER type
+ * @param string $table Table name
+ * @param mixed $field Column definition
+ * @return string|string[]
+ */
+ protected function _alter_table($alter_type, $table, $field)
+ {
+ if (in_array($alter_type, array('ADD', 'DROP'), TRUE))
+ {
+ return parent::_alter_table($alter_table, $table, $field);
+ }
+
+ // No method of modifying columns is supported
+ return FALSE;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Process column
+ *
+ * @param array $field
+ * @return string
+ */
+ protected function _process_column($field)
+ {
+ return $this->db->escape_identifiers($field['name'])
+ .' '.$field['type'].$field['length']
+ .$field['null']
+ .$field['unique']
+ .$field['auto_increment'];
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Field attribute TYPE
+ *
+ * Performs a data type mapping between different databases.
+ *
+ * @param array &$attributes
+ * @return void
+ */
+ protected function _attr_type(&$attributes)
+ {
+ switch (strtoupper($attributes['TYPE']))
+ {
+ case 'TINYINT':
+ $attributes['TYPE'] = 'SMALLINT';
+ $attributes['UNSIGNED'] = FALSE;
+ return;
+ case 'MEDIUMINT':
+ $attributes['TYPE'] = 'INTEGER';
+ $attributes['UNSIGNED'] = FALSE;
+ return;
+ case 'INTEGER':
+ $attributes['TYPE'] = 'INT';
+ return;
+ case 'BIGINT':
+ $attribites['TYPE'] = 'INT64';
+ return;
+ default: return;
+ }
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Field attribute UNIQUE
+ *
+ * @param array &$attributes
+ * @param array &$field
+ * @return void
+ */
+ protected function _attr_unique(&$attributes, &$field)
+ {
+ if ( ! empty($attributes['UNIQUE']) && $attributes['UNIQUE'] === TRUE)
+ {
+ $field['unique'] = ' UNIQUE';
+
+ // UNIQUE must be used with NOT NULL
+ $field['null'] = ' NOT NULL';
+ }
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Field attribute AUTO_INCREMENT
+ *
+ * @param array &$attributes
+ * @param array &$field
+ * @return void
+ */
+ protected function _attr_auto_increment(&$attributes, &$field)
+ {
+ if ( ! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === TRUE)
+ {
+ if (stripos($field['type'], 'int') !== FALSE)
+ {
+ $field['auto_increment'] = ' AUTO_INCREMENT';
+ }
+ elseif (strcasecmp($field['type'], 'UUID') === 0)
+ {
+ $field['auto_increment'] = ' AUTO_GENERATE';
+ }
+ }
+ }
+
+}
+
+/* End of file pdo_4d_forge.php */
+/* Location: ./system/database/drivers/pdo/subdrivers/pdo_4d_forge.php */ \ No newline at end of file
diff --git a/system/database/drivers/pdo/subdrivers/pdo_cubrid_driver.php b/system/database/drivers/pdo/subdrivers/pdo_cubrid_driver.php
index d2a484d9e..4f762b91c 100644
--- a/system/database/drivers/pdo/subdrivers/pdo_cubrid_driver.php
+++ b/system/database/drivers/pdo/subdrivers/pdo_cubrid_driver.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 3.0.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* PDO CUBRID Database Adapter Class
@@ -40,18 +41,28 @@
*/
class CI_DB_pdo_cubrid_driver extends CI_DB_pdo_driver {
+ /**
+ * Sub-driver
+ *
+ * @var string
+ */
public $subdriver = 'cubrid';
+ /**
+ * Identifier escape character
+ *
+ * @var string
+ */
protected $_escape_char = '`';
- protected $_random_keyword = ' RAND()';
+ // --------------------------------------------------------------------
/**
- * Constructor
+ * Class constructor
*
* Builds the DSN if not already set.
*
- * @param array
+ * @param array $params
* @return void
*/
public function __construct($params)
@@ -75,7 +86,7 @@ class CI_DB_pdo_cubrid_driver extends CI_DB_pdo_driver {
*
* Generates a platform-specific query string so that the table names can be fetched
*
- * @param bool
+ * @param bool $prefix_limit
* @return string
*/
protected function _list_tables($prefix_limit = FALSE)
@@ -97,7 +108,7 @@ class CI_DB_pdo_cubrid_driver extends CI_DB_pdo_driver {
*
* Generates a platform-specific query string so that the column names can be fetched
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _list_columns($table = '')
@@ -112,7 +123,7 @@ class CI_DB_pdo_cubrid_driver extends CI_DB_pdo_driver {
*
* Generates a platform-specific query so that the column data can be retrieved
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _field_data($table)
@@ -127,9 +138,9 @@ class CI_DB_pdo_cubrid_driver extends CI_DB_pdo_driver {
*
* Generates a platform-specific batch update string from the supplied data
*
- * @param string the table name
- * @param array the update data
- * @param string the where key
+ * @param string $table Table name
+ * @param array $values Update data
+ * @param string $index WHERE key
* @return string
*/
protected function _update_batch($table, $values, $index)
@@ -168,10 +179,10 @@ class CI_DB_pdo_cubrid_driver extends CI_DB_pdo_driver {
*
* Generates a platform-specific truncate string from the supplied data
*
- * If the database does not support the truncate() command,
+ * If the database does not support the TRUNCATE statement,
* then this method maps to 'DELETE FROM table'
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _truncate($table)
diff --git a/system/database/drivers/pdo/subdrivers/pdo_cubrid_forge.php b/system/database/drivers/pdo/subdrivers/pdo_cubrid_forge.php
new file mode 100644
index 000000000..e8421ec41
--- /dev/null
+++ b/system/database/drivers/pdo/subdrivers/pdo_cubrid_forge.php
@@ -0,0 +1,212 @@
+<?php
+/**
+ * CodeIgniter
+ *
+ * An open source application development framework for PHP 5.2.4 or newer
+ *
+ * NOTICE OF LICENSE
+ *
+ * Licensed under the Open Software License version 3.0
+ *
+ * This source file is subject to the Open Software License (OSL 3.0) that is
+ * bundled with this package in the files license.txt / license.rst. It is
+ * also available through the world wide web at this URL:
+ * http://opensource.org/licenses/OSL-3.0
+ * If you did not receive a copy of the license and are unable to obtain it
+ * through the world wide web, please send an email to
+ * licensing@ellislab.com so we can send you a copy immediately.
+ *
+ * @package CodeIgniter
+ * @author EllisLab Dev Team
+ * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
+ * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
+ * @link http://codeigniter.com
+ * @since Version 2.1.0
+ * @filesource
+ */
+defined('BASEPATH') OR exit('No direct script access allowed');
+
+/**
+ * PDO CUBRID Forge Class
+ *
+ * @category Database
+ * @author EllisLab Dev Team
+ * @link http://codeigniter.com/user_guide/database/
+ */
+class CI_DB_pdo_cubrid_forge extends CI_DB_pdo_forge {
+
+ /**
+ * CREATE DATABASE statement
+ *
+ * @var string
+ */
+ protected $_create_database = FALSE;
+
+ /**
+ * DROP DATABASE statement
+ *
+ * @var string
+ */
+ protected $_drop_database = FALSE;
+
+ /**
+ * CREATE TABLE keys flag
+ *
+ * Whether table keys are created from within the
+ * CREATE TABLE statement.
+ *
+ * @var bool
+ */
+ protected $_create_table_keys = TRUE;
+
+ /**
+ * DROP TABLE IF statement
+ *
+ * @var string
+ */
+ protected $_drop_table_if = 'DROP TABLE IF EXISTS';
+
+ /**
+ * UNSIGNED support
+ *
+ * @var array
+ */
+ protected $_unsigned = array(
+ 'SHORT' => 'INTEGER',
+ 'SMALLINT' => 'INTEGER',
+ 'INT' => 'BIGINT',
+ 'INTEGER' => 'BIGINT',
+ 'BIGINT' => 'NUMERIC',
+ 'FLOAT' => 'DOUBLE',
+ 'REAL' => 'DOUBLE'
+ );
+
+ // --------------------------------------------------------------------
+
+ /**
+ * ALTER TABLE
+ *
+ * @param string $alter_type ALTER type
+ * @param string $table Table name
+ * @param mixed $field Column definition
+ * @return string|string[]
+ */
+ protected function _alter_table($alter_type, $table, $field)
+ {
+ if (in_array($alter_type, array('DROP', 'ADD'), TRUE))
+ {
+ return parent::_alter_table($alter_type, $table, $field);
+ }
+
+ $sql = 'ALTER TABLE '.$this->db->escape_identifiers($table);
+ $sqls = array();
+ for ($i = 0, $c = count($field); $i < $c; $i++)
+ {
+ if ($field[$i]['_literal'] !== FALSE)
+ {
+ $sqls[] = $sql.' CHANGE '.$field[$i]['_literal'];
+ }
+ else
+ {
+ $sqls[] = $sql.' CHANGE '.$this->_process_column($field[$i]);
+ if ( ! empty($field[$i]['new_name']))
+ {
+ $sqls[] = $sql.' RENAME COLUMN '.$this->db->escape_identifiers($field[$i]['name'])
+ .' AS '.$this->db->escape_identifiers($field[$i]['name']);
+ }
+ }
+ }
+
+ return $sqls;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Process column
+ *
+ * @param array $field
+ * @return string
+ */
+ protected function _process_column($field)
+ {
+ $extra_clause = isset($field['after'])
+ ? ' AFTER '.$this->db->escape_identifiers($field['after']) : '';
+
+ if (empty($extra_clause) && isset($field['first']) && $field['first'] === TRUE)
+ {
+ $extra_clause = ' FIRST';
+ }
+
+ return $this->db->escape_identifiers($field['name'])
+ .(empty($field['new_name']) ? '' : $this->db->escape_identifiers($field['new_name']))
+ .' '.$field['type'].$field['length']
+ .$field['unsigned']
+ .$field['null']
+ .$field['default']
+ .$field['auto_increment']
+ .$field['unique']
+ .$extra_clause;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Field attribute TYPE
+ *
+ * Performs a data type mapping between different databases.
+ *
+ * @param array &$attributes
+ * @return void
+ */
+ protected function _attr_type(&$attributes)
+ {
+ switch (strtoupper($attributes['TYPE']))
+ {
+ case 'TINYINT':
+ $attributes['TYPE'] = 'SMALLINT';
+ $attributes['UNSIGNED'] = FALSE;
+ return;
+ case 'MEDIUMINT':
+ $attributes['TYPE'] = 'INTEGER';
+ $attributes['UNSIGNED'] = FALSE;
+ return;
+ default: return;
+ }
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Process indexes
+ *
+ * @param string $table (ignored)
+ * @return string
+ */
+ protected function _process_indexes($table = NULL)
+ {
+ $sql = '';
+
+ for ($i = 0, $c = count($this->keys); $i < $c; $i++)
+ {
+ if ( ! isset($this->fields[$this->keys[$i]]))
+ {
+ unset($this->keys[$i]);
+ continue;
+ }
+
+ is_array($this->keys[$i]) OR $this->keys[$i] = array($this->keys[$i]);
+
+ $sql .= ",\n\tKEY ".$this->db->escape_identifiers(implode('_', $this->keys[$i]))
+ .' ('.implode(', ', $this->db->escape_identifiers($this->keys[$i])).')';
+ }
+
+ $this->keys = array();
+
+ return $sql;
+ }
+
+}
+
+/* End of file pdo_cubrid_forge.php */
+/* Location: ./system/database/drivers/pdo/subdrivers/pdo_cubrid_forge.php */ \ No newline at end of file
diff --git a/system/database/drivers/pdo/subdrivers/pdo_dblib_driver.php b/system/database/drivers/pdo/subdrivers/pdo_dblib_driver.php
index 785b2795c..7121819ec 100644
--- a/system/database/drivers/pdo/subdrivers/pdo_dblib_driver.php
+++ b/system/database/drivers/pdo/subdrivers/pdo_dblib_driver.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 3.0.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* PDO DBLIB Database Adapter Class
@@ -40,18 +41,40 @@
*/
class CI_DB_pdo_dblib_driver extends CI_DB_pdo_driver {
+ /**
+ * Sub-driver
+ *
+ * @var string
+ */
public $subdriver = 'dblib';
+ // --------------------------------------------------------------------
+
+ /**
+ * ORDER BY random keyword
+ *
+ * @var string
+ */
protected $_random_keyword = ' NEWID()';
+ /**
+ * Quoted identifier flag
+ *
+ * Whether to use SQL-92 standard quoted identifier
+ * (double quotes) or brackets for identifier escaping.
+ *
+ * @var bool
+ */
protected $_quoted_identifier;
+ // --------------------------------------------------------------------
+
/**
- * Constructor
+ * Class constructor
*
* Builds the DSN if not already set.
*
- * @param array
+ * @param array $params
* @return void
*/
public function __construct($params)
@@ -85,9 +108,9 @@ class CI_DB_pdo_dblib_driver extends CI_DB_pdo_driver {
// --------------------------------------------------------------------
/**
- * Non-persistent database connection
+ * Database connection
*
- * @param bool
+ * @param bool $persistent
* @return object
*/
public function db_connect($persistent = FALSE)
@@ -115,7 +138,7 @@ class CI_DB_pdo_dblib_driver extends CI_DB_pdo_driver {
*
* Generates a platform-specific query string so that the table names can be fetched
*
- * @param bool
+ * @param bool $prefix_limit
* @return string
*/
protected function _list_tables($prefix_limit = FALSE)
@@ -140,7 +163,7 @@ class CI_DB_pdo_dblib_driver extends CI_DB_pdo_driver {
*
* Generates a platform-specific query string so that the column names can be fetched
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _list_columns($table = '')
@@ -157,8 +180,8 @@ class CI_DB_pdo_dblib_driver extends CI_DB_pdo_driver {
*
* Generates a platform-specific update string from the supplied data
*
- * @param string the table name
- * @param array the update data
+ * @param string $table
+ * @param array $values
* @return string
*/
protected function _update($table, $values)
@@ -175,7 +198,7 @@ class CI_DB_pdo_dblib_driver extends CI_DB_pdo_driver {
*
* Generates a platform-specific delete string from the supplied data
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _delete($table)
@@ -191,11 +214,11 @@ class CI_DB_pdo_dblib_driver extends CI_DB_pdo_driver {
// --------------------------------------------------------------------
/**
- * Limit string
+ * LIMIT
*
* Generates a platform-specific LIMIT clause
*
- * @param string the sql query string
+ * @param string $sql SQL Query
* @return string
*/
protected function _limit($sql)
@@ -239,6 +262,29 @@ class CI_DB_pdo_dblib_driver extends CI_DB_pdo_driver {
return preg_replace('/(^\SELECT (DISTINCT)?)/i','\\1 TOP '.$limit.' ', $sql);
}
+ // --------------------------------------------------------------------
+
+ /**
+ * Insert batch statement
+ *
+ * Generates a platform-specific insert string from the supplied data.
+ *
+ * @param string $table Table name
+ * @param array $keys INSERT keys
+ * @param array $values INSERT values
+ * @return string|bool
+ */
+ protected function _insert_batch($table, $keys, $values)
+ {
+ // Multiple-value inserts are only supported as of SQL Server 2008
+ if (version_compare($this->version(), '10', '>='))
+ {
+ return parent::_insert_batch($table, $keys, $values);
+ }
+
+ return ($this->db->db_debug) ? $this->db->display_error('db_unsupported_feature') : FALSE;
+ }
+
}
/* End of file pdo_dblib_driver.php */
diff --git a/system/database/drivers/pdo/subdrivers/pdo_dblib_forge.php b/system/database/drivers/pdo/subdrivers/pdo_dblib_forge.php
new file mode 100644
index 000000000..236e1cce2
--- /dev/null
+++ b/system/database/drivers/pdo/subdrivers/pdo_dblib_forge.php
@@ -0,0 +1,136 @@
+<?php
+/**
+ * CodeIgniter
+ *
+ * An open source application development framework for PHP 5.2.4 or newer
+ *
+ * NOTICE OF LICENSE
+ *
+ * Licensed under the Open Software License version 3.0
+ *
+ * This source file is subject to the Open Software License (OSL 3.0) that is
+ * bundled with this package in the files license.txt / license.rst. It is
+ * also available through the world wide web at this URL:
+ * http://opensource.org/licenses/OSL-3.0
+ * If you did not receive a copy of the license and are unable to obtain it
+ * through the world wide web, please send an email to
+ * licensing@ellislab.com so we can send you a copy immediately.
+ *
+ * @package CodeIgniter
+ * @author EllisLab Dev Team
+ * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
+ * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
+ * @link http://codeigniter.com
+ * @since Version 2.1.0
+ * @filesource
+ */
+defined('BASEPATH') OR exit('No direct script access allowed');
+
+/**
+ * PDO DBLIB Forge Class
+ *
+ * @category Database
+ * @author EllisLab Dev Team
+ * @link http://codeigniter.com/user_guide/database/
+ */
+class CI_DB_pdo_dblib_forge extends CI_DB_pdo_forge {
+
+ /**
+ * CREATE TABLE IF statement
+ *
+ * @var string
+ */
+ protected $_create_table_if = "IF NOT EXISTS (SELECT * FROM sysobjects WHERE ID = object_id(N'%s') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)\nCREATE TABLE";
+
+ /**
+ * DROP TABLE IF statement
+ *
+ * @var string
+ */
+ protected $_drop_table_if = "IF EXISTS (SELECT * FROM sysobjects WHERE ID = object_id(N'%s') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)\nDROP TABLE";
+
+ /**
+ * UNSIGNED support
+ *
+ * @var array
+ */
+ protected $_unsigned = array(
+ 'TINYINT' => 'SMALLINT',
+ 'SMALLINT' => 'INT',
+ 'INT' => 'BIGINT',
+ 'REAL' => 'FLOAT'
+ );
+
+ // --------------------------------------------------------------------
+
+ /**
+ * ALTER TABLE
+ *
+ * @param string $alter_type ALTER type
+ * @param string $table Table name
+ * @param mixed $field Column definition
+ * @return string|string[]
+ */
+ protected function _alter_table($alter_type, $table, $field)
+ {
+ if (in_array($alter_type, array('ADD', 'DROP'), TRUE))
+ {
+ return parent::_alter_table($alter_type, $table, $field);
+ }
+
+ $sql = 'ALTER TABLE '.$this->db->escape_identifiers($table).' ALTER COLUMN ';
+ $sqls = array();
+ for ($i = 0, $c = count($field); $i < $c; $i++)
+ {
+ $sqls[] = $sql.$this->_process_column($field[$i]);
+ }
+
+ return $sqls;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Field attribute TYPE
+ *
+ * Performs a data type mapping between different databases.
+ *
+ * @param array &$attributes
+ * @return void
+ */
+ protected function _attr_type(&$attributes)
+ {
+ switch (strtoupper($attributes['TYPE']))
+ {
+ case 'MEDIUMINT':
+ $attributes['TYPE'] = 'INTEGER';
+ $attributes['UNSIGNED'] = FALSE;
+ return;
+ case 'INTEGER':
+ $attributes['TYPE'] = 'INT';
+ return;
+ default: return;
+ }
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Field attribute AUTO_INCREMENT
+ *
+ * @param array &$attributes
+ * @param array &$field
+ * @return void
+ */
+ protected function _attr_auto_increment(&$attributes, &$field)
+ {
+ if ( ! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === TRUE && stripos($field['type'], 'int') !== FALSE)
+ {
+ $field['auto_increment'] = ' IDENTITY(1,1)';
+ }
+ }
+
+}
+
+/* End of file pdo_dblib_forge.php */
+/* Location: ./system/database/drivers/pdo/subdrivers/pdo_dblib_forge.php */ \ No newline at end of file
diff --git a/system/database/drivers/pdo/subdrivers/pdo_firebird_driver.php b/system/database/drivers/pdo/subdrivers/pdo_firebird_driver.php
index 32d1f219a..83b9648c1 100644
--- a/system/database/drivers/pdo/subdrivers/pdo_firebird_driver.php
+++ b/system/database/drivers/pdo/subdrivers/pdo_firebird_driver.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 3.0.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* PDO Firebird Database Adapter Class
@@ -40,21 +41,30 @@
*/
class CI_DB_pdo_firebird_driver extends CI_DB_pdo_driver {
+ /**
+ * Sub-driver
+ *
+ * @var string
+ */
public $subdriver = 'firebird';
+ // --------------------------------------------------------------------
+
/**
- * The syntax to count rows is slightly different across different
- * database engines, so this string appears in each driver and is
- * used for the count_all() and count_all_results() functions.
+ * ORDER BY random keyword
+ *
+ * @var string
*/
- protected $_random_keyword = ' RANDOM()'; // Currently not supported
+ protected $_random_keyword = ' RANDOM()';
+
+ // --------------------------------------------------------------------
/**
- * Constructor
+ * Class constructor
*
* Builds the DSN if not already set.
*
- * @param array
+ * @param array $params
* @return void
*/
public function __construct($params)
@@ -90,7 +100,7 @@ class CI_DB_pdo_firebird_driver extends CI_DB_pdo_driver {
*
* Generates a platform-specific query string so that the table names can be fetched
*
- * @param bool
+ * @param bool $prefix_limit
* @return string
*/
protected function _list_tables($prefix_limit = FALSE)
@@ -113,7 +123,7 @@ class CI_DB_pdo_firebird_driver extends CI_DB_pdo_driver {
*
* Generates a platform-specific query string so that the column names can be fetched
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _list_columns($table = '')
@@ -128,7 +138,7 @@ class CI_DB_pdo_firebird_driver extends CI_DB_pdo_driver {
*
* Generates a platform-specific query so that the column data can be retrieved
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _field_data($table)
@@ -143,8 +153,8 @@ class CI_DB_pdo_firebird_driver extends CI_DB_pdo_driver {
*
* Generates a platform-specific update string from the supplied data
*
- * @param string the table name
- * @param array the update data
+ * @param string $table
+ * @param array $values
* @return string
*/
protected function _update($table, $values)
@@ -160,10 +170,10 @@ class CI_DB_pdo_firebird_driver extends CI_DB_pdo_driver {
*
* Generates a platform-specific truncate string from the supplied data
*
- * If the database does not support the truncate() command,
+ * If the database does not support the TRUNCATE statement,
* then this method maps to 'DELETE FROM table'
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _truncate($table)
@@ -178,7 +188,7 @@ class CI_DB_pdo_firebird_driver extends CI_DB_pdo_driver {
*
* Generates a platform-specific delete string from the supplied data
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _delete($table)
@@ -190,11 +200,11 @@ class CI_DB_pdo_firebird_driver extends CI_DB_pdo_driver {
// --------------------------------------------------------------------
/**
- * Limit string
+ * LIMIT
*
* Generates a platform-specific LIMIT clause
*
- * @param string the sql query string
+ * @param string $sql SQL Query
* @return string
*/
protected function _limit($sql)
diff --git a/system/database/drivers/pdo/subdrivers/pdo_firebird_forge.php b/system/database/drivers/pdo/subdrivers/pdo_firebird_forge.php
new file mode 100644
index 000000000..474188f4e
--- /dev/null
+++ b/system/database/drivers/pdo/subdrivers/pdo_firebird_forge.php
@@ -0,0 +1,228 @@
+<?php
+/**
+ * CodeIgniter
+ *
+ * An open source application development framework for PHP 5.2.4 or newer
+ *
+ * NOTICE OF LICENSE
+ *
+ * Licensed under the Open Software License version 3.0
+ *
+ * This source file is subject to the Open Software License (OSL 3.0) that is
+ * bundled with this package in the files license.txt / license.rst. It is
+ * also available through the world wide web at this URL:
+ * http://opensource.org/licenses/OSL-3.0
+ * If you did not receive a copy of the license and are unable to obtain it
+ * through the world wide web, please send an email to
+ * licensing@ellislab.com so we can send you a copy immediately.
+ *
+ * @package CodeIgniter
+ * @author EllisLab Dev Team
+ * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
+ * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
+ * @link http://codeigniter.com
+ * @since Version 2.1.0
+ * @filesource
+ */
+defined('BASEPATH') OR exit('No direct script access allowed');
+
+/**
+ * PDO Firebird Forge Class
+ *
+ * @category Database
+ * @author EllisLab Dev Team
+ * @link http://codeigniter.com/user_guide/database/
+ */
+class CI_DB_pdo_firebird_forge extends CI_DB_pdo_forge {
+
+ /**
+ * RENAME TABLE statement
+ *
+ * @var string
+ */
+ protected $_rename_table = FALSE;
+
+ /**
+ * UNSIGNED support
+ *
+ * @var array
+ */
+ protected $_unsigned = array(
+ 'SMALLINT' => 'INTEGER',
+ 'INTEGER' => 'INT64',
+ 'FLOAT' => 'DOUBLE PRECISION'
+ );
+
+ /**
+ * NULL value representation in CREATE/ALTER TABLE statements
+ *
+ * @var string
+ */
+ protected $_null = 'NULL';
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Create database
+ *
+ * @param string $db_name
+ * @return string
+ */
+ public function create_database($db_name)
+ {
+ // Firebird databases are flat files, so a path is required
+
+ // Hostname is needed for remote access
+ empty($this->db->hostname) OR $db_name = $this->hostname.':'.$db_name;
+
+ return parent::create_database('"'.$db_name.'"');
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Drop database
+ *
+ * @param string $db_name (ignored)
+ * @return bool
+ */
+ public function drop_database($db_name = '')
+ {
+ if ( ! ibase_drop_db($this->conn_id))
+ {
+ return ($this->db->db_debug) ? $this->db->display_error('db_unable_to_drop') : FALSE;
+ }
+ elseif ( ! empty($this->db->data_cache['db_names']))
+ {
+ $key = array_search(strtolower($this->db->database), array_map('strtolower', $this->db->data_cache['db_names']), TRUE);
+ if ($key !== FALSE)
+ {
+ unset($this->db->data_cache['db_names'][$key]);
+ }
+ }
+
+ return TRUE;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * ALTER TABLE
+ *
+ * @param string $alter_type ALTER type
+ * @param string $table Table name
+ * @param mixed $field Column definition
+ * @return string|string[]
+ */
+ protected function _alter_table($alter_type, $table, $field)
+ {
+ if (in_array($alter_type, array('DROP', 'ADD'), TRUE))
+ {
+ return parent::_alter_table($alter_type, $table, $field);
+ }
+
+ $sql = 'ALTER TABLE '.$this->db->escape_identifiers($table);
+ $sqls = array();
+ for ($i = 0, $c = count($field), $sql .= $alter_type.' '; $i < $c; $i++)
+ {
+ if ($field[$i]['_literal'] !== FALSE)
+ {
+ return FALSE;
+ }
+
+ if (isset($field[$i]['type']))
+ {
+ $sqls[] = $sql.' TYPE '.$field[$i]['type'].$field[$i]['length'];
+ }
+
+ if ( ! empty($field[$i]['default']))
+ {
+ $sqls[] = $sql.' ALTER '.$this->db->escape_identifiers($field[$i]['name'])
+ .' SET '.$field[$i]['default'];
+ }
+
+ if (isset($field[$i]['null']))
+ {
+ $sqls[] = 'UPDATE "RDB$RELATION_FIELDS" SET "RDB$NULL_FLAG" = '
+ .($field[$i]['null'] === TRUE ? 'NULL' : '1')
+ .' WHERE "RDB$FIELD_NAME" = '.$this->db->escape($field[$i]['name'])
+ .' AND "RDB$RELATION_NAME" = '.$this->db->escape($table);
+ }
+
+ if ( ! empty($field[$i]['new_name']))
+ {
+ $sqls[] = $sql.' ALTER '.$this->db->escape_identifiers($field[$i]['name'])
+ .' TO '.$this->db->escape_identifiers($field[$i]['new_name']);
+ }
+ }
+
+ return $sqls;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Process column
+ *
+ * @param array $field
+ * @return string
+ */
+ protected function _process_column($field)
+ {
+ return $this->db->escape_identifiers($field['name'])
+ .' '.$field['type'].$field['length']
+ .$field['null']
+ .$field['unique']
+ .$field['default'];
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Field attribute TYPE
+ *
+ * Performs a data type mapping between different databases.
+ *
+ * @param array &$attributes
+ * @return void
+ */
+ protected function _attr_type(&$attributes)
+ {
+ switch (strtoupper($attributes['TYPE']))
+ {
+ case 'TINYINT':
+ $attributes['TYPE'] = 'SMALLINT';
+ $attributes['UNSIGNED'] = FALSE;
+ return;
+ case 'MEDIUMINT':
+ $attributes['TYPE'] = 'INTEGER';
+ $attributes['UNSIGNED'] = FALSE;
+ return;
+ case 'INT':
+ $attributes['TYPE'] = 'INTEGER';
+ return;
+ case 'BIGINT':
+ $attributes['TYPE'] = 'INT64';
+ return;
+ default: return;
+ }
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Field attribute AUTO_INCREMENT
+ *
+ * @param array &$attributes
+ * @param array &$field
+ * @return void
+ */
+ protected function _attr_auto_increment(&$attributes, &$field)
+ {
+ // Not supported
+ }
+
+}
+
+/* End of file pdo_firebird_forge.php */
+/* Location: ./system/database/drivers/pdo/subdrivers/pdo_firebird_forge.php */ \ No newline at end of file
diff --git a/system/database/drivers/pdo/subdrivers/pdo_ibm_driver.php b/system/database/drivers/pdo/subdrivers/pdo_ibm_driver.php
index 22a5f928c..d8dbc50c0 100644
--- a/system/database/drivers/pdo/subdrivers/pdo_ibm_driver.php
+++ b/system/database/drivers/pdo/subdrivers/pdo_ibm_driver.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 3.0.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* PDO IBM DB2 Database Adapter Class
@@ -40,16 +41,21 @@
*/
class CI_DB_pdo_ibm_driver extends CI_DB_pdo_driver {
+ /**
+ * Sub-driver
+ *
+ * @var string
+ */
public $subdriver = 'ibm';
- protected $_random_keyword = ' RAND()';
+ // --------------------------------------------------------------------
/**
- * Constructor
+ * Class constructor
*
* Builds the DSN if not already set.
*
- * @param array
+ * @param array $params
* @return void
*/
public function __construct($params)
@@ -115,7 +121,7 @@ class CI_DB_pdo_ibm_driver extends CI_DB_pdo_driver {
*
* Generates a platform-specific query string so that the table names can be fetched
*
- * @param bool
+ * @param bool $prefix_limit
* @return string
*/
protected function _list_tables($prefix_limit = FALSE)
@@ -138,7 +144,7 @@ class CI_DB_pdo_ibm_driver extends CI_DB_pdo_driver {
*
* Generates a platform-specific query string so that the column names can be fetched
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _list_columns($table = '')
@@ -154,7 +160,7 @@ class CI_DB_pdo_ibm_driver extends CI_DB_pdo_driver {
*
* Generates a platform-specific query so that the column data can be retrieved
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _field_data($table)
@@ -169,8 +175,8 @@ class CI_DB_pdo_ibm_driver extends CI_DB_pdo_driver {
*
* Generates a platform-specific update string from the supplied data
*
- * @param string the table name
- * @param array the update data
+ * @param string $table
+ * @param array $values
* @return string
*/
protected function _update($table, $values)
@@ -187,7 +193,7 @@ class CI_DB_pdo_ibm_driver extends CI_DB_pdo_driver {
*
* Generates a platform-specific delete string from the supplied data
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _delete($table)
@@ -199,21 +205,19 @@ class CI_DB_pdo_ibm_driver extends CI_DB_pdo_driver {
// --------------------------------------------------------------------
/**
- * Limit string
+ * LIMIT
*
* Generates a platform-specific LIMIT clause
*
- * @param string the sql query string
- * @param int the number of rows to limit the query to
- * @param int the offset value
+ * @param string $sql SQL Query
* @return string
*/
- protected function _limit($sql, $limit, $offset)
+ protected function _limit($sql)
{
- $sql .= ' FETCH FIRST '.($limit + $offset).' ROWS ONLY';
+ $sql .= ' FETCH FIRST '.($this->qb_limit + $this->qb_offset).' ROWS ONLY';
- return ($offset)
- ? 'SELECT * FROM ('.$sql.') WHERE rownum > '.$offset
+ return ($this->qb_offset)
+ ? 'SELECT * FROM ('.$sql.') WHERE rownum > '.$this->qb_offset
: $sql;
}
diff --git a/system/database/drivers/pdo/subdrivers/pdo_ibm_forge.php b/system/database/drivers/pdo/subdrivers/pdo_ibm_forge.php
new file mode 100644
index 000000000..f095c717a
--- /dev/null
+++ b/system/database/drivers/pdo/subdrivers/pdo_ibm_forge.php
@@ -0,0 +1,146 @@
+<?php
+/**
+ * CodeIgniter
+ *
+ * An open source application development framework for PHP 5.2.4 or newer
+ *
+ * NOTICE OF LICENSE
+ *
+ * Licensed under the Open Software License version 3.0
+ *
+ * This source file is subject to the Open Software License (OSL 3.0) that is
+ * bundled with this package in the files license.txt / license.rst. It is
+ * also available through the world wide web at this URL:
+ * http://opensource.org/licenses/OSL-3.0
+ * If you did not receive a copy of the license and are unable to obtain it
+ * through the world wide web, please send an email to
+ * licensing@ellislab.com so we can send you a copy immediately.
+ *
+ * @package CodeIgniter
+ * @author EllisLab Dev Team
+ * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
+ * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
+ * @link http://codeigniter.com
+ * @since Version 2.1.0
+ * @filesource
+ */
+defined('BASEPATH') OR exit('No direct script access allowed');
+
+/**
+ * PDO IBM DB2 Forge Class
+ *
+ * @category Database
+ * @author EllisLab Dev Team
+ * @link http://codeigniter.com/user_guide/database/
+ */
+class CI_DB_pdo_ibm_forge extends CI_DB_pdo_forge {
+
+ /**
+ * RENAME TABLE IF statement
+ *
+ * @var string
+ */
+ protected $_rename_table = 'RENAME TABLE %s TO %s';
+
+ /**
+ * UNSIGNED support
+ *
+ * @var array
+ */
+ protected $_unsigned = array(
+ 'SMALLINT' => 'INTEGER',
+ 'INT' => 'BIGINT',
+ 'INTEGER' => 'BIGINT'
+ );
+
+ /**
+ * DEFAULT value representation in CREATE/ALTER TABLE statements
+ *
+ * @var string
+ */
+ protected $_default = FALSE;
+
+ // --------------------------------------------------------------------
+
+ /**
+ * ALTER TABLE
+ *
+ * @param string $alter_type ALTER type
+ * @param string $table Table name
+ * @param mixed $field Column definition
+ * @return string|string[]
+ */
+ protected function _alter_table($alter_type, $table, $field)
+ {
+ if ($alter_type === 'CHANGE')
+ {
+ $alter_type = 'MODIFY';
+ }
+
+ return parent::_alter_table($alter_type, $table, $field);
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Field attribute TYPE
+ *
+ * Performs a data type mapping between different databases.
+ *
+ * @param array &$attributes
+ * @return void
+ */
+ protected function _attr_type(&$attributes)
+ {
+ switch (strtoupper($attributes['TYPE']))
+ {
+ case 'TINYINT':
+ $attributes['TYPE'] = 'SMALLINT';
+ $attributes['UNSIGNED'] = FALSE;
+ return;
+ case 'MEDIUMINT':
+ $attributes['TYPE'] = 'INTEGER';
+ $attributes['UNSIGNED'] = FALSE;
+ return;
+ default: return;
+ }
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Field attribute UNIQUE
+ *
+ * @param array &$attributes
+ * @param array &$field
+ * @return void
+ */
+ protected function _attr_unique(&$attributes, &$field)
+ {
+ if ( ! empty($attributes['UNIQUE']) && $attributes['UNIQUE'] === TRUE)
+ {
+ $field['unique'] = ' UNIQUE';
+
+ // UNIQUE must be used with NOT NULL
+ $field['null'] = ' NOT NULL';
+ }
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Field attribute AUTO_INCREMENT
+ *
+ * @param array &$attributes
+ * @param array &$field
+ * @return void
+ */
+ protected function _attr_auto_increment(&$attributes, &$field)
+ {
+ // Not supported
+ }
+
+}
+
+/* End of file pdo_ibm_forge.php */
+/* Location: ./system/database/drivers/pdo/subdrivers/pdo_ibm_forge.php */ \ No newline at end of file
diff --git a/system/database/drivers/pdo/subdrivers/pdo_informix_driver.php b/system/database/drivers/pdo/subdrivers/pdo_informix_driver.php
index 8dd430184..8998670e1 100644
--- a/system/database/drivers/pdo/subdrivers/pdo_informix_driver.php
+++ b/system/database/drivers/pdo/subdrivers/pdo_informix_driver.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 3.0.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* PDO Informix Database Adapter Class
@@ -40,16 +41,21 @@
*/
class CI_DB_pdo_informix_driver extends CI_DB_pdo_driver {
+ /**
+ * Sub-driver
+ *
+ * @var string
+ */
public $subdriver = 'informix';
- protected $_random_keyword = ' RAND()';
+ // --------------------------------------------------------------------
/**
- * Constructor
+ * Class constructor
*
* Builds the DSN if not already set.
*
- * @param array
+ * @param array $params
* @return void
*/
public function __construct($params)
@@ -108,7 +114,7 @@ class CI_DB_pdo_informix_driver extends CI_DB_pdo_driver {
*
* Generates a platform-specific query string so that the table names can be fetched
*
- * @param bool
+ * @param bool $prefix_limit
* @return string
*/
protected function _list_tables($prefix_limit = FALSE)
@@ -131,7 +137,7 @@ class CI_DB_pdo_informix_driver extends CI_DB_pdo_driver {
*
* Generates a platform-specific query string so that the column names can be fetched
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _list_columns($table = '')
@@ -148,7 +154,7 @@ class CI_DB_pdo_informix_driver extends CI_DB_pdo_driver {
*
* Generates a platform-specific query so that the column data can be retrieved
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _field_data($table)
@@ -163,8 +169,8 @@ class CI_DB_pdo_informix_driver extends CI_DB_pdo_driver {
*
* Generates a platform-specific update string from the supplied data
*
- * @param string the table name
- * @param array the update data
+ * @param string $table
+ * @param array $values
* @return string
*/
protected function _update($table, $values)
@@ -181,10 +187,10 @@ class CI_DB_pdo_informix_driver extends CI_DB_pdo_driver {
*
* Generates a platform-specific truncate string from the supplied data
*
- * If the database does not support the truncate() command,
+ * If the database does not support the TRUNCATE statement,
* then this method maps to 'DELETE FROM table'
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _truncate($table)
@@ -199,7 +205,7 @@ class CI_DB_pdo_informix_driver extends CI_DB_pdo_driver {
*
* Generates a platform-specific delete string from the supplied data
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _delete($table)
@@ -211,11 +217,11 @@ class CI_DB_pdo_informix_driver extends CI_DB_pdo_driver {
// --------------------------------------------------------------------
/**
- * Limit string
+ * LIMIT
*
* Generates a platform-specific LIMIT clause
*
- * @param string the sql query string
+ * @param string $sql $SQL Query
* @return string
*/
protected function _limit($sql)
diff --git a/system/database/drivers/pdo/subdrivers/pdo_informix_forge.php b/system/database/drivers/pdo/subdrivers/pdo_informix_forge.php
new file mode 100644
index 000000000..8722dd200
--- /dev/null
+++ b/system/database/drivers/pdo/subdrivers/pdo_informix_forge.php
@@ -0,0 +1,155 @@
+<?php
+/**
+ * CodeIgniter
+ *
+ * An open source application development framework for PHP 5.2.4 or newer
+ *
+ * NOTICE OF LICENSE
+ *
+ * Licensed under the Open Software License version 3.0
+ *
+ * This source file is subject to the Open Software License (OSL 3.0) that is
+ * bundled with this package in the files license.txt / license.rst. It is
+ * also available through the world wide web at this URL:
+ * http://opensource.org/licenses/OSL-3.0
+ * If you did not receive a copy of the license and are unable to obtain it
+ * through the world wide web, please send an email to
+ * licensing@ellislab.com so we can send you a copy immediately.
+ *
+ * @package CodeIgniter
+ * @author EllisLab Dev Team
+ * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
+ * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
+ * @link http://codeigniter.com
+ * @since Version 2.1.0
+ * @filesource
+ */
+defined('BASEPATH') OR exit('No direct script access allowed');
+
+/**
+ * PDO Informix Forge Class
+ *
+ * @category Database
+ * @author EllisLab Dev Team
+ * @link http://codeigniter.com/user_guide/database/
+ */
+class CI_DB_pdo_informix_forge extends CI_DB_pdo_forge {
+
+ /**
+ * RENAME TABLE statement
+ *
+ * @var string
+ */
+ protected $_rename_table = 'RENAME TABLE %s TO %s';
+
+ /**
+ * UNSIGNED support
+ *
+ * @var array
+ */
+ protected $_unsigned = array(
+ 'SMALLINT' => 'INTEGER',
+ 'INT' => 'BIGINT',
+ 'INTEGER' => 'BIGINT',
+ 'REAL' => 'DOUBLE PRECISION',
+ 'SMALLFLOAT' => 'DOUBLE PRECISION'
+ );
+
+ /**
+ * DEFAULT value representation in CREATE/ALTER TABLE statements
+ *
+ * @var string
+ */
+ protected $_default = ', ';
+
+ // --------------------------------------------------------------------
+
+ /**
+ * ALTER TABLE
+ *
+ * @param string $alter_type ALTER type
+ * @param string $table Table name
+ * @param mixed $field Column definition
+ * @return string|string[]
+ */
+ protected function _alter_table($alter_type, $table, $field)
+ {
+ if ($alter_type === 'CHANGE')
+ {
+ $alter_type = 'MODIFY';
+ }
+
+ return parent::_alter_table($alter_type, $table, $field);
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Field attribute TYPE
+ *
+ * Performs a data type mapping between different databases.
+ *
+ * @param array &$attributes
+ * @return void
+ */
+ protected function _attr_type(&$attributes)
+ {
+ switch (strtoupper($attributes['TYPE']))
+ {
+ case 'TINYINT':
+ $attributes['TYPE'] = 'SMALLINT';
+ $attributes['UNSIGNED'] = FALSE;
+ return;
+ case 'MEDIUMINT':
+ $attributes['TYPE'] = 'INTEGER';
+ $attributes['UNSIGNED'] = FALSE;
+ return;
+ case 'BYTE':
+ case 'TEXT':
+ case 'BLOB':
+ case 'CLOB':
+ $attributes['UNIQUE'] = FALSE;
+ if (isset($attributes['DEFAULT']))
+ {
+ unset($attributes['DEFAULT']);
+ }
+ return;
+ default: return;
+ }
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Field attribute UNIQUE
+ *
+ * @param array &$attributes
+ * @param array &$field
+ * @return void
+ */
+ protected function _attr_unique(&$attributes, &$field)
+ {
+ if ( ! empty($attributes['UNIQUE']) && $attributes['UNIQUE'] === TRUE)
+ {
+ $field['unique'] = ' UNIQUE CONSTRAINT '.$this->db->escape_identifiers($field['name']);
+ }
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Field attribute AUTO_INCREMENT
+ *
+ * @param array &$attributes
+ * @param array &$field
+ * @return void
+ */
+ protected function _attr_auto_increment(&$attributes, &$field)
+ {
+ // Not supported
+ }
+
+}
+
+/* End of file pdo_informix_forge.php */
+/* Location: ./system/database/drivers/pdo/subdrivers/pdo_informix_forge.php */ \ No newline at end of file
diff --git a/system/database/drivers/pdo/subdrivers/pdo_mysql_driver.php b/system/database/drivers/pdo/subdrivers/pdo_mysql_driver.php
index 0fb5d8f12..2d076f314 100644
--- a/system/database/drivers/pdo/subdrivers/pdo_mysql_driver.php
+++ b/system/database/drivers/pdo/subdrivers/pdo_mysql_driver.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 3.0.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* PDO MySQL Database Adapter Class
@@ -40,19 +41,37 @@
*/
class CI_DB_pdo_mysql_driver extends CI_DB_pdo_driver {
+ /**
+ * Sub-driver
+ *
+ * @var string
+ */
public $subdriver = 'mysql';
+
+ /**
+ * Compression flag
+ *
+ * @var bool
+ */
public $compress = FALSE;
+ // --------------------------------------------------------------------
+
+ /**
+ * Identifier escape character
+ *
+ * @var string
+ */
protected $_escape_char = '`';
- protected $_random_keyword = ' RAND()';
+ // --------------------------------------------------------------------
/**
- * Constructor
+ * Class constructor
*
* Builds the DSN if not already set.
*
- * @param array
+ * @param array $params
* @return void
*/
public function __construct($params)
@@ -76,9 +95,9 @@ class CI_DB_pdo_mysql_driver extends CI_DB_pdo_driver {
// --------------------------------------------------------------------
/**
- * Non-persistent database connection
+ * Database connection
*
- * @param bool
+ * @param bool $persistent
* @return object
* @todo SSL support
*/
@@ -110,7 +129,7 @@ class CI_DB_pdo_mysql_driver extends CI_DB_pdo_driver {
*
* Generates a platform-specific query string so that the table names can be fetched
*
- * @param bool
+ * @param bool $prefix_limit
* @return string
*/
protected function _list_tables($prefix_limit = FALSE)
@@ -132,7 +151,7 @@ class CI_DB_pdo_mysql_driver extends CI_DB_pdo_driver {
*
* Generates a platform-specific query string so that the column names can be fetched
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _list_columns($table = '')
@@ -147,7 +166,7 @@ class CI_DB_pdo_mysql_driver extends CI_DB_pdo_driver {
*
* Generates a platform-specific query so that the column data can be retrieved
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _field_data($table)
@@ -162,9 +181,9 @@ class CI_DB_pdo_mysql_driver extends CI_DB_pdo_driver {
*
* Generates a platform-specific batch update string from the supplied data
*
- * @param string the table name
- * @param array the update data
- * @param string the where key
+ * @param string $table Table name
+ * @param array $values Update data
+ * @param string $index UPDATE key
* @return string
*/
protected function _update_batch($table, $values, $index)
@@ -203,10 +222,10 @@ class CI_DB_pdo_mysql_driver extends CI_DB_pdo_driver {
*
* Generates a platform-specific truncate string from the supplied data
*
- * If the database does not support the truncate() command,
+ * If the database does not support the TRUNCATE statement,
* then this method maps to 'DELETE FROM table'
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _truncate($table)
diff --git a/system/database/drivers/pdo/subdrivers/pdo_mysql_forge.php b/system/database/drivers/pdo/subdrivers/pdo_mysql_forge.php
new file mode 100644
index 000000000..866b6fb21
--- /dev/null
+++ b/system/database/drivers/pdo/subdrivers/pdo_mysql_forge.php
@@ -0,0 +1,218 @@
+<?php
+/**
+ * CodeIgniter
+ *
+ * An open source application development framework for PHP 5.2.4 or newer
+ *
+ * NOTICE OF LICENSE
+ *
+ * Licensed under the Open Software License version 3.0
+ *
+ * This source file is subject to the Open Software License (OSL 3.0) that is
+ * bundled with this package in the files license.txt / license.rst. It is
+ * also available through the world wide web at this URL:
+ * http://opensource.org/licenses/OSL-3.0
+ * If you did not receive a copy of the license and are unable to obtain it
+ * through the world wide web, please send an email to
+ * licensing@ellislab.com so we can send you a copy immediately.
+ *
+ * @package CodeIgniter
+ * @author EllisLab Dev Team
+ * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
+ * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
+ * @link http://codeigniter.com
+ * @since Version 2.1.0
+ * @filesource
+ */
+defined('BASEPATH') OR exit('No direct script access allowed');
+
+/**
+ * PDO MySQL Forge Class
+ *
+ * @category Database
+ * @author EllisLab Dev Team
+ * @link http://codeigniter.com/user_guide/database/
+ */
+class CI_DB_pdo_mysql_forge extends CI_DB_pdo_forge {
+
+ /**
+ * CREATE DATABASE statement
+ *
+ * @var string
+ */
+ protected $_create_database = 'CREATE DATABASE %s CHARACTER SET %s COLLATE %s';
+
+ /**
+ * CREATE TABLE IF statement
+ *
+ * @var string
+ */
+ protected $_create_table_if = 'CREATE TABLE IF NOT EXISTS';
+
+ /**
+ * CREATE TABLE keys flag
+ *
+ * Whether table keys are created from within the
+ * CREATE TABLE statement.
+ *
+ * @var bool
+ */
+ protected $_create_table_keys = TRUE;
+
+ /**
+ * DROP TABLE IF statement
+ *
+ * @var string
+ */
+ protected $_drop_table_if = 'DROP TABLE IF EXISTS';
+
+ /**
+ * UNSIGNED support
+ *
+ * @var array
+ */
+ protected $_unsigned = array(
+ 'TINYINT',
+ 'SMALLINT',
+ 'MEDIUMINT',
+ 'INT',
+ 'INTEGER',
+ 'BIGINT',
+ 'REAL',
+ 'DOUBLE',
+ 'DOUBLE PRECISION',
+ 'FLOAT',
+ 'DECIMAL',
+ 'NUMERIC'
+ );
+
+ /**
+ * NULL value representation in CREATE/ALTER TABLE statements
+ *
+ * @var string
+ */
+ protected $_null = 'NULL';
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Class constructor
+ *
+ * @param object &$db Database object
+ * @return void
+ */
+ public function __construct(&$db)
+ {
+ parent::__construct($db);
+
+ $this->_create_table .= ' DEFAULT CHARSET '.$this->db->char_set.' COLLATE '.$this->db->dbcollat;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * ALTER TABLE
+ *
+ * @param string $alter_type ALTER type
+ * @param string $table Table name
+ * @param mixed $field Column definition
+ * @return string|string[]
+ */
+ protected function _alter_table($alter_type, $table, $field)
+ {
+ if ($alter_type === 'DROP')
+ {
+ return parent::_alter_table($alter_type, $table, $field);
+ }
+
+ $sql = 'ALTER TABLE '.$this->db->escape_identifiers($table);
+ for ($i = 0, $c = count($field); $i < $c; $i++)
+ {
+ if ($field[$i]['_literal'] !== FALSE)
+ {
+ $field[$i] = ($alter_type === 'ADD')
+ ? "\n\tADD ".$field[$i]['_literal']
+ : "\n\tMODIFY ".$field[$i]['_literal'];
+ }
+ else
+ {
+ if ($alter_type === 'ADD')
+ {
+ $field[$i]['_literal'] = "\n\tADD ";
+ }
+ else
+ {
+ $field[$i]['_literal'] = empty($field[$i]['new_name']) ? "\n\tMODIFY " : "\n\tCHANGE ";
+ }
+
+ $field[$i] = $field[$i]['_literal'].$this->_process_column($field[$i]);
+ }
+ }
+
+ return array($sql.implode(',', $field));
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Process column
+ *
+ * @param array $field
+ * @return string
+ */
+ protected function _process_column($field)
+ {
+ $extra_clause = isset($field['after'])
+ ? ' AFTER '.$this->db->escape_identifiers($field['after']) : '';
+
+ if (empty($extra_clause) && isset($field['first']) && $field['first'] === TRUE)
+ {
+ $extra_clause = ' FIRST';
+ }
+
+ return $this->db->escape_identifiers($field['name'])
+ .(empty($field['new_name']) ? '' : $this->db->escape_identifiers($field['new_name']))
+ .' '.$field['type'].$field['length']
+ .$field['unsigned']
+ .$field['null']
+ .$field['default']
+ .$field['auto_increment']
+ .$field['unique']
+ .$extra_clause;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Process indexes
+ *
+ * @param string $table (ignored)
+ * @return string
+ */
+ protected function _process_indexes($table = NULL)
+ {
+ $sql = '';
+
+ for ($i = 0, $c = count($this->keys); $i < $c; $i++)
+ {
+ if ( ! isset($this->fields[$this->keys[$i]]))
+ {
+ unset($this->keys[$i]);
+ continue;
+ }
+
+ is_array($this->keys[$i]) OR $this->keys[$i] = array($this->keys[$i]);
+
+ $sql .= ",\n\tKEY ".$this->db->escape_identifiers(implode('_', $this->keys[$i]))
+ .' ('.implode(', ', $this->db->escape_identifiers($this->keys[$i])).')';
+ }
+
+ $this->keys = array();
+
+ return $sql;
+ }
+
+}
+
+/* End of file pdo_mysql_forge.php */
+/* Location: ./system/database/drivers/pdo/subdrivers/pdo_mysql_forge.php */ \ No newline at end of file
diff --git a/system/database/drivers/pdo/subdrivers/pdo_oci_driver.php b/system/database/drivers/pdo/subdrivers/pdo_oci_driver.php
index b03218fad..e1beb3683 100644
--- a/system/database/drivers/pdo/subdrivers/pdo_oci_driver.php
+++ b/system/database/drivers/pdo/subdrivers/pdo_oci_driver.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 3.0.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* PDO Oracle Database Adapter Class
@@ -40,24 +41,49 @@
*/
class CI_DB_pdo_oci_driver extends CI_DB_pdo_driver {
+ /**
+ * Sub-driver
+ *
+ * @var string
+ */
public $subdriver = 'oci';
+ // --------------------------------------------------------------------
+
/**
- * The syntax to count rows is slightly different across different
- * database engines, so this string appears in each driver and is
- * used for the count_all() and count_all_results() functions.
+ * List of reserved identifiers
+ *
+ * Identifiers that must NOT be escaped.
+ *
+ * @var string[]
+ */
+ protected $_reserved_identifiers = array('*', 'rownum');
+
+ /**
+ * ORDER BY random keyword
+ *
+ * @var string
*/
- protected $_count_string = 'SELECT COUNT(1) AS ';
protected $_random_keyword = ' ASC'; // Currently not supported
- protected $_reserved_identifiers = array('*', 'rownum');
+ /**
+ * COUNT string
+ *
+ * @used-by CI_DB_driver::count_all()
+ * @used-by CI_DB_query_builder::count_all_results()
+ *
+ * @var string
+ */
+ protected $_count_string = 'SELECT COUNT(1) AS ';
+
+ // --------------------------------------------------------------------
/**
- * Constructor
+ * Class constructor
*
* Builds the DSN if not already set.
*
- * @param array
+ * @param array $params
* @return void
*/
public function __construct($params)
@@ -97,7 +123,7 @@ class CI_DB_pdo_oci_driver extends CI_DB_pdo_driver {
*
* Generates a platform-specific query string so that the table names can be fetched
*
- * @param bool
+ * @param bool $prefix_limit
* @return string
*/
protected function _list_tables($prefix_limit = FALSE)
@@ -120,7 +146,7 @@ class CI_DB_pdo_oci_driver extends CI_DB_pdo_driver {
*
* Generates a platform-specific query string so that the column names can be fetched
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _list_columns($table = '')
@@ -135,7 +161,7 @@ class CI_DB_pdo_oci_driver extends CI_DB_pdo_driver {
*
* Generates a platform-specific query so that the column data can be retrieved
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _field_data($table)
@@ -146,11 +172,11 @@ class CI_DB_pdo_oci_driver extends CI_DB_pdo_driver {
// --------------------------------------------------------------------
/**
- * Insert_batch statement
+ * Insert batch statement
*
- * @param string the table name
- * @param array the insert keys
- * @param array the insert values
+ * @param string $table Table name
+ * @param array $keys INSERT keys
+ * @param array $values INSERT values
* @return string
*/
protected function _insert_batch($table, $keys, $values)
@@ -173,7 +199,7 @@ class CI_DB_pdo_oci_driver extends CI_DB_pdo_driver {
*
* Generates a platform-specific delete string from the supplied data
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _delete($table)
@@ -190,11 +216,11 @@ class CI_DB_pdo_oci_driver extends CI_DB_pdo_driver {
// --------------------------------------------------------------------
/**
- * Limit string
+ * LIMIT
*
* Generates a platform-specific LIMIT clause
*
- * @param string the sql query string
+ * @param string $sql SQL Query
* @return string
*/
protected function _limit($sql)
diff --git a/system/database/drivers/pdo/subdrivers/pdo_oci_forge.php b/system/database/drivers/pdo/subdrivers/pdo_oci_forge.php
new file mode 100644
index 000000000..8052d218f
--- /dev/null
+++ b/system/database/drivers/pdo/subdrivers/pdo_oci_forge.php
@@ -0,0 +1,133 @@
+<?php
+/**
+ * CodeIgniter
+ *
+ * An open source application development framework for PHP 5.2.4 or newer
+ *
+ * NOTICE OF LICENSE
+ *
+ * Licensed under the Open Software License version 3.0
+ *
+ * This source file is subject to the Open Software License (OSL 3.0) that is
+ * bundled with this package in the files license.txt / license.rst. It is
+ * also available through the world wide web at this URL:
+ * http://opensource.org/licenses/OSL-3.0
+ * If you did not receive a copy of the license and are unable to obtain it
+ * through the world wide web, please send an email to
+ * licensing@ellislab.com so we can send you a copy immediately.
+ *
+ * @package CodeIgniter
+ * @author EllisLab Dev Team
+ * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
+ * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
+ * @link http://codeigniter.com
+ * @since Version 2.1.0
+ * @filesource
+ */
+defined('BASEPATH') OR exit('No direct script access allowed');
+
+/**
+ * PDO Oracle Forge Class
+ *
+ * @category Database
+ * @author EllisLab Dev Team
+ * @link http://codeigniter.com/user_guide/database/
+ */
+class CI_DB_pdo_oci_forge extends CI_DB_pdo_forge {
+
+ /**
+ * CREATE DATABASE statement
+ *
+ * @var string
+ */
+ protected $_create_database = FALSE;
+
+ /**
+ * DROP DATABASE statement
+ *
+ * @var string
+ */
+ protected $_drop_database = FALSE;
+
+ /**
+ * CREATE TABLE IF statement
+ *
+ * @var string
+ */
+ protected $_create_table_if = 'CREATE TABLE IF NOT EXISTS';
+
+ /**
+ * UNSIGNED support
+ *
+ * @var bool|array
+ */
+ protected $_unsigned = FALSE;
+
+ // --------------------------------------------------------------------
+
+ /**
+ * ALTER TABLE
+ *
+ * @param string $alter_type ALTER type
+ * @param string $table Table name
+ * @param mixed $field Column definition
+ * @return string|string[]
+ */
+ protected function _alter_table($alter_type, $table, $field)
+ {
+ if ($alter_type === 'DROP')
+ {
+ return parent::_alter_table($alter_type, $table, $field);
+ }
+ elseif ($alter_type === 'CHANGE')
+ {
+ $alter_type = 'MODIFY';
+ }
+
+ $sql = 'ALTER TABLE '.$this->db->escape_identifiers($table);
+ $sqls = array();
+ for ($i = 0, $c = count($field); $i < $c; $i++)
+ {
+ if ($field[$i]['_literal'] !== FALSE)
+ {
+ $field[$i] = "\n\t".$field[$i]['_literal'];
+ }
+ else
+ {
+ $field[$i]['_literal'] = "\n\t".$this->_process_column($field[$i]);
+ if ($alter_type === 'MODIFY' && ! empty($field[$i]['new_name']))
+ {
+ $sqls[] = $sql.' RENAME COLUMN '.$this->db->escape_identifiers($field[$i]['name'])
+ .' '.$this->db->escape_identifiers($field[$i]['new_name']);
+ }
+ }
+ }
+
+ $sql .= ' '.$alter_type.' ';
+ $sql .= (count($field) === 1)
+ ? $fields[0]
+ : '('.implode(',', $field).')';
+
+ // RENAME COLUMN must be executed after MODIFY
+ array_unshift($sqls, $sql);
+ return $sql;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Field attribute AUTO_INCREMENT
+ *
+ * @param array &$attributes
+ * @param array &$field
+ * @return void
+ */
+ protected function _attr_auto_increment(&$attributes, &$field)
+ {
+ // Not supported - sequences and triggers must be used instead
+ }
+
+}
+
+/* End of file pdo_oci_forge.php */
+/* Location: ./system/database/drivers/pdo/subdrivers/pdo_oci_forge.php */ \ No newline at end of file
diff --git a/system/database/drivers/pdo/subdrivers/pdo_odbc_driver.php b/system/database/drivers/pdo/subdrivers/pdo_odbc_driver.php
index d64e9fb36..f6e0e215a 100644
--- a/system/database/drivers/pdo/subdrivers/pdo_odbc_driver.php
+++ b/system/database/drivers/pdo/subdrivers/pdo_odbc_driver.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 3.0.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* PDO ODBC Database Adapter Class
@@ -40,29 +41,46 @@
*/
class CI_DB_pdo_odbc_driver extends CI_DB_pdo_driver {
+ /**
+ * Sub-driver
+ *
+ * @var string
+ */
public $subdriver = 'odbc';
- // The character used for escaping - not used in ODBC
- protected $_escape_char = '';
+ /**
+ * Database schema
+ *
+ * @var string
+ */
+ public $schema = 'public';
- // clause and character used for LIKE escape sequences
- protected $_like_escape_str = " {escape '%s'} ";
+ // --------------------------------------------------------------------
- protected $_random_keyword = ' RAND()';
+ /**
+ * Identifier escape character
+ *
+ * Must be empty for ODBC.
+ *
+ * @var string
+ */
+ protected $_escape_char = '';
/**
- * Database schema
+ * ESCAPE statement string
*
* @var string
*/
- public $schema = 'public';
+ protected $_like_escape_str = " {escape '%s'} ";
+
+ // --------------------------------------------------------------------
/**
- * Constructor
+ * Class constructor
*
* Builds the DSN if not already set.
*
- * @param array
+ * @param array $params
* @return void
*/
public function __construct($params)
@@ -129,7 +147,7 @@ class CI_DB_pdo_odbc_driver extends CI_DB_pdo_driver {
*
* Generates a platform-specific query string so that the table names can be fetched
*
- * @param bool $prefix_limit = FALSE
+ * @param bool $prefix_limit
* @return string
*/
protected function _list_tables($prefix_limit = FALSE)
@@ -152,7 +170,7 @@ class CI_DB_pdo_odbc_driver extends CI_DB_pdo_driver {
*
* Generates a platform-specific query string so that the column names can be fetched
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _list_columns($table = '')
@@ -167,8 +185,8 @@ class CI_DB_pdo_odbc_driver extends CI_DB_pdo_driver {
*
* Generates a platform-specific update string from the supplied data
*
- * @param string the table name
- * @param array the update data
+ * @param string $table
+ * @param array $values
* @return string
*/
protected function _update($table, $values)
@@ -185,10 +203,10 @@ class CI_DB_pdo_odbc_driver extends CI_DB_pdo_driver {
*
* Generates a platform-specific truncate string from the supplied data
*
- * If the database does not support the truncate() command,
+ * If the database does not support the TRUNCATE statement,
* then this method maps to 'DELETE FROM table'
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _truncate($table)
@@ -215,11 +233,11 @@ class CI_DB_pdo_odbc_driver extends CI_DB_pdo_driver {
// --------------------------------------------------------------------
/**
- * Limit string
+ * LIMIT
*
* Generates a platform-specific LIMIT clause
*
- * @param string the sql query string
+ * @param string $sql SQL Query
* @return string
*/
protected function _limit($sql)
diff --git a/system/database/drivers/pdo/subdrivers/pdo_odbc_forge.php b/system/database/drivers/pdo/subdrivers/pdo_odbc_forge.php
new file mode 100644
index 000000000..ab4d2bf84
--- /dev/null
+++ b/system/database/drivers/pdo/subdrivers/pdo_odbc_forge.php
@@ -0,0 +1,62 @@
+<?php
+/**
+ * CodeIgniter
+ *
+ * An open source application development framework for PHP 5.2.4 or newer
+ *
+ * NOTICE OF LICENSE
+ *
+ * Licensed under the Open Software License version 3.0
+ *
+ * This source file is subject to the Open Software License (OSL 3.0) that is
+ * bundled with this package in the files license.txt / license.rst. It is
+ * also available through the world wide web at this URL:
+ * http://opensource.org/licenses/OSL-3.0
+ * If you did not receive a copy of the license and are unable to obtain it
+ * through the world wide web, please send an email to
+ * licensing@ellislab.com so we can send you a copy immediately.
+ *
+ * @package CodeIgniter
+ * @author EllisLab Dev Team
+ * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
+ * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
+ * @link http://codeigniter.com
+ * @since Version 2.1.0
+ * @filesource
+ */
+defined('BASEPATH') OR exit('No direct script access allowed');
+
+/**
+ * PDO ODBC Forge Class
+ *
+ * @category Database
+ * @author EllisLab Dev Team
+ * @link http://codeigniter.com/database/
+ */
+class CI_DB_pdo_odbc_forge extends CI_DB_pdo_forge {
+
+ /**
+ * UNSIGNED support
+ *
+ * @var bool|array
+ */
+ protected $_unsigned = FALSE;
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Field attribute AUTO_INCREMENT
+ *
+ * @param array &$attributes
+ * @param array &$field
+ * @return void
+ */
+ protected function _attr_auto_increment(&$attributes, &$field)
+ {
+ // Not supported (in most databases at least)
+ }
+
+}
+
+/* End of file pdo_odbc_forge.php */
+/* Location: ./system/database/drivers/pdo/subdrivers/pdo_odbc_forge.php */ \ No newline at end of file
diff --git a/system/database/drivers/pdo/subdrivers/pdo_pgsql_driver.php b/system/database/drivers/pdo/subdrivers/pdo_pgsql_driver.php
index 93674b576..c3f5b7603 100644
--- a/system/database/drivers/pdo/subdrivers/pdo_pgsql_driver.php
+++ b/system/database/drivers/pdo/subdrivers/pdo_pgsql_driver.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 3.0.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* PDO PostgreSQL Database Adapter Class
@@ -40,10 +41,13 @@
*/
class CI_DB_pdo_pgsql_driver extends CI_DB_pdo_driver {
+ /**
+ * Sub-driver
+ *
+ * @var string
+ */
public $subdriver = 'pgsql';
- protected $_random_keyword = ' RANDOM()';
-
/**
* Database schema
*
@@ -51,12 +55,23 @@ class CI_DB_pdo_pgsql_driver extends CI_DB_pdo_driver {
*/
public $schema = 'public';
+ // --------------------------------------------------------------------
+
/**
- * Constructor
+ * ORDER BY random keyword
+ *
+ * @var string
+ */
+ protected $_random_keyword = ' RANDOM()';
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Class constructor
*
* Builds the DSN if not already set.
*
- * @param array
+ * @param array $params
* @return void
*/
public function __construct($params)
@@ -77,7 +92,7 @@ class CI_DB_pdo_pgsql_driver extends CI_DB_pdo_driver {
/**
* Insert ID
*
- * @param string
+ * @param string $name
* @return int
*/
public function insert_id($name = NULL)
@@ -99,7 +114,7 @@ class CI_DB_pdo_pgsql_driver extends CI_DB_pdo_driver {
*
* Generates a platform-specific query string so that the table names can be fetched
*
- * @param bool $prefix_limit = FALSE
+ * @param bool $prefix_limit
* @return string
*/
protected function _list_tables($prefix_limit = FALSE)
@@ -123,7 +138,7 @@ class CI_DB_pdo_pgsql_driver extends CI_DB_pdo_driver {
*
* Generates a platform-specific query string so that the column names can be fetched
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _list_columns($table = '')
@@ -138,7 +153,7 @@ class CI_DB_pdo_pgsql_driver extends CI_DB_pdo_driver {
*
* Generates a platform-specific query so that the column data can be retrieved
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _field_data($table)
@@ -153,8 +168,8 @@ class CI_DB_pdo_pgsql_driver extends CI_DB_pdo_driver {
*
* Generates a platform-specific update string from the supplied data
*
- * @param string the table name
- * @param array the update data
+ * @param string $table
+ * @param array $values
* @return string
*/
protected function _update($table, $values)
@@ -171,9 +186,9 @@ class CI_DB_pdo_pgsql_driver extends CI_DB_pdo_driver {
*
* Generates a platform-specific batch update string from the supplied data
*
- * @param string the table name
- * @param array the update data
- * @param string the where key
+ * @param string $table Table name
+ * @param array $values Update data
+ * @param string $index WHERE key
* @return string
*/
protected function _update_batch($table, $values, $index)
@@ -212,7 +227,7 @@ class CI_DB_pdo_pgsql_driver extends CI_DB_pdo_driver {
*
* Generates a platform-specific delete string from the supplied data
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _delete($table)
@@ -224,11 +239,11 @@ class CI_DB_pdo_pgsql_driver extends CI_DB_pdo_driver {
// --------------------------------------------------------------------
/**
- * Limit string
+ * LIMIT
*
* Generates a platform-specific LIMIT clause
*
- * @param string the sql query string
+ * @param string $sql SQL Query
* @return string
*/
protected function _limit($sql)
diff --git a/system/database/drivers/pdo/subdrivers/pdo_pgsql_forge.php b/system/database/drivers/pdo/subdrivers/pdo_pgsql_forge.php
new file mode 100644
index 000000000..484c1603d
--- /dev/null
+++ b/system/database/drivers/pdo/subdrivers/pdo_pgsql_forge.php
@@ -0,0 +1,194 @@
+<?php
+/**
+ * CodeIgniter
+ *
+ * An open source application development framework for PHP 5.2.4 or newer
+ *
+ * NOTICE OF LICENSE
+ *
+ * Licensed under the Open Software License version 3.0
+ *
+ * This source file is subject to the Open Software License (OSL 3.0) that is
+ * bundled with this package in the files license.txt / license.rst. It is
+ * also available through the world wide web at this URL:
+ * http://opensource.org/licenses/OSL-3.0
+ * If you did not receive a copy of the license and are unable to obtain it
+ * through the world wide web, please send an email to
+ * licensing@ellislab.com so we can send you a copy immediately.
+ *
+ * @package CodeIgniter
+ * @author EllisLab Dev Team
+ * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
+ * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
+ * @link http://codeigniter.com
+ * @since Version 2.1.0
+ * @filesource
+ */
+defined('BASEPATH') OR exit('No direct script access allowed');
+
+/**
+ * PDO PostgreSQL Forge Class
+ *
+ * @category Database
+ * @author EllisLab Dev Team
+ * @link http://codeigniter.com/user_guide/database/
+ */
+class CI_DB_pdo_pgsql_forge extends CI_DB_pdo_forge {
+
+ /**
+ * DROP TABLE IF statement
+ *
+ * @var string
+ */
+ protected $_drop_table_if = 'DROP TABLE IF EXISTS';
+
+ /**
+ * UNSIGNED support
+ *
+ * @var array
+ */
+ protected $_unsigned = array(
+ 'INT2' => 'INTEGER',
+ 'SMALLINT' => 'INTEGER',
+ 'INT' => 'BIGINT',
+ 'INT4' => 'BIGINT',
+ 'INTEGER' => 'BIGINT',
+ 'INT8' => 'NUMERIC',
+ 'BIGINT' => 'NUMERIC',
+ 'REAL' => 'DOUBLE PRECISION',
+ 'FLOAT' => 'DOUBLE PRECISION'
+ );
+
+ /**
+ * NULL value representation in CREATE/ALTER TABLE statements
+ *
+ * @var string
+ */
+ protected $_null = 'NULL';
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Class constructor
+ *
+ * @param object &$db Database object
+ * @return void
+ */
+ public function __construct(&$db)
+ {
+ parent::__construct($db);
+
+ if (version_compare($this->db->version(), '9.0', '>'))
+ {
+ $this->create_table_if = 'CREATE TABLE IF NOT EXISTS';
+ }
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * ALTER TABLE
+ *
+ * @param string $alter_type ALTER type
+ * @param string $table Table name
+ * @param mixed $field Column definition
+ * @return string|string[]
+ */
+ protected function _alter_table($alter_type, $table, $field)
+ {
+ if (in_array($alter_type, array('DROP', 'ADD'), TRUE))
+ {
+ return parent::_alter_table($alter_type, $table, $field);
+ }
+
+ $sql = 'ALTER TABLE '.$this->db->escape_identifiers($table);
+ $sqls = array();
+ for ($i = 0, $c = count($field), $sql .= $alter_type.' '; $i < $c; $i++)
+ {
+ if ($field[$i]['_literal'] !== FALSE)
+ {
+ return FALSE;
+ }
+
+ if (version_compare($this->db->version(), '8', '>=') && isset($field[$i]['type']))
+ {
+ $sqls[] = $sql.' TYPE '.$field[$i]['type'].$field[$i]['length'];
+ }
+
+ if ( ! empty($field[$i]['default']))
+ {
+ $sqls[] = $sql.' ALTER '.$this->db->escape_identifiers($field[$i]['name'])
+ .' SET '.$field[$i]['default'];
+ }
+
+ if (isset($field[$i]['null']))
+ {
+ $sqls[] = $sql.' ALTER '.$this->db->escape_identifiers($field[$i]['name'])
+ .($field[$i]['null'] === TRUE ? ' DROP NOT NULL' : ' SET NOT NULL');
+ }
+
+ if ( ! empty($field[$i]['new_name']))
+ {
+ $sqls[] = $sql.' RENAME '.$this->db->escape_identifiers($field[$i]['name'])
+ .' TO '.$this->db->escape_identifiers($field[$i]['new_name']);
+ }
+ }
+
+ return $sqls;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Field attribute TYPE
+ *
+ * Performs a data type mapping between different databases.
+ *
+ * @param array &$attributes
+ * @return void
+ */
+ protected function _attr_type(&$attributes)
+ {
+ // Reset field lenghts for data types that don't support it
+ if (isset($attributes['CONSTRAINT']) && stripos($attributes['TYPE'], 'int') !== FALSE)
+ {
+ $attributes['CONSTRAINT'] = NULL;
+ }
+
+ switch (strtoupper($attributes['TYPE']))
+ {
+ case 'TINYINT':
+ $attributes['TYPE'] = 'SMALLINT';
+ $attributes['UNSIGNED'] = FALSE;
+ return;
+ case 'MEDIUMINT':
+ $attributes['TYPE'] = 'INTEGER';
+ $attributes['UNSIGNED'] = FALSE;
+ return;
+ default: return;
+ }
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Field attribute AUTO_INCREMENT
+ *
+ * @param array &$attributes
+ * @param array &$field
+ * @return void
+ */
+ protected function _attr_auto_increment(&$attributes, &$field)
+ {
+ if ( ! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === TRUE)
+ {
+ $field['type'] = ($field['type'] === 'NUMERIC')
+ ? 'BIGSERIAL'
+ : 'SERIAL';
+ }
+ }
+
+}
+
+/* End of file pdo_pgsql_forge.php */
+/* Location: ./system/database/drivers/pdo/subdrivers/pdo_pgsql_forge.php */ \ No newline at end of file
diff --git a/system/database/drivers/pdo/subdrivers/pdo_sqlite_driver.php b/system/database/drivers/pdo/subdrivers/pdo_sqlite_driver.php
index bf0363f63..b24b13e76 100644
--- a/system/database/drivers/pdo/subdrivers/pdo_sqlite_driver.php
+++ b/system/database/drivers/pdo/subdrivers/pdo_sqlite_driver.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 3.0.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* PDO SQLite Database Adapter Class
@@ -40,21 +41,30 @@
*/
class CI_DB_pdo_sqlite_driver extends CI_DB_pdo_driver {
+ /**
+ * Sub-driver
+ *
+ * @var string
+ */
public $subdriver = 'sqlite';
+ // --------------------------------------------------------------------
+
/**
- * The syntax to count rows is slightly different across different
- * database engines, so this string appears in each driver and is
- * used for the count_all() and count_all_results() functions.
+ * ORDER BY random keyword
+ *
+ * @var string
*/
- protected $_random_keyword = ' RANDOM()'; // Currently not supported
+ protected $_random_keyword = ' RANDOM()';
+
+ // --------------------------------------------------------------------
/**
- * Constructor
+ * Class constructor
*
* Builds the DSN if not already set.
*
- * @param array
+ * @param array $params
* @return void
*/
public function __construct($params)
@@ -81,7 +91,7 @@ class CI_DB_pdo_sqlite_driver extends CI_DB_pdo_driver {
*
* Generates a platform-specific query string so that the table names can be fetched
*
- * @param bool
+ * @param bool $prefix_limit
* @return string
*/
protected function _list_tables($prefix_limit = FALSE)
@@ -104,7 +114,7 @@ class CI_DB_pdo_sqlite_driver extends CI_DB_pdo_driver {
*
* Generates a platform-specific query string so that the column names can be fetched
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _list_columns($table = '')
@@ -120,7 +130,7 @@ class CI_DB_pdo_sqlite_driver extends CI_DB_pdo_driver {
*
* Generates a platform-specific query so that the column data can be retrieved
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _field_data($table)
@@ -133,9 +143,9 @@ class CI_DB_pdo_sqlite_driver extends CI_DB_pdo_driver {
/**
* Replace statement
*
- * @param string the table name
- * @param array the insert keys
- * @param array the insert values
+ * @param string $table Table name
+ * @param array $keys INSERT keys
+ * @param array $values INSERT values
* @return string
*/
protected function _replace($table, $keys, $values)
@@ -150,10 +160,10 @@ class CI_DB_pdo_sqlite_driver extends CI_DB_pdo_driver {
*
* Generates a platform-specific truncate string from the supplied data
*
- * If the database does not support the truncate() command,
+ * If the database does not support the TRUNCATE statement,
* then this method maps to 'DELETE FROM table'
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _truncate($table)
diff --git a/system/database/drivers/pdo/subdrivers/pdo_sqlite_forge.php b/system/database/drivers/pdo/subdrivers/pdo_sqlite_forge.php
new file mode 100644
index 000000000..da098df31
--- /dev/null
+++ b/system/database/drivers/pdo/subdrivers/pdo_sqlite_forge.php
@@ -0,0 +1,229 @@
+<?php
+/**
+ * CodeIgniter
+ *
+ * An open source application development framework for PHP 5.1.6 or newer
+ *
+ * NOTICE OF LICENSE
+ *
+ * Licensed under the Open Software License version 3.0
+ *
+ * This source file is subject to the Open Software License (OSL 3.0) that is
+ * bundled with this package in the files license.txt / license.rst. It is
+ * also available through the world wide web at this URL:
+ * http://opensource.org/licenses/OSL-3.0
+ * If you did not receive a copy of the license and are unable to obtain it
+ * through the world wide web, please send an email to
+ * licensing@ellislab.com so we can send you a copy immediately.
+ *
+ * @package CodeIgniter
+ * @author EllisLab Dev Team
+ * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
+ * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
+ * @link http://codeigniter.com
+ * @since Version 2.1.0
+ * @filesource
+ */
+defined('BASEPATH') OR exit('No direct script access allowed');
+
+/**
+ * PDO SQLite Forge Class
+ *
+ * @category Database
+ * @author EllisLab Dev Team
+ * @link http://codeigniter.com/user_guide/database/
+ */
+class CI_DB_pdo_sqlite_forge extends CI_DB_pdo_forge {
+
+ /**
+ * CREATE TABLE IF statement
+ *
+ * @var string
+ */
+ protected $_create_table_if = 'CREATE TABLE IF NOT EXISTS';
+
+ /**
+ * DROP TABLE IF statement
+ *
+ * @var string
+ */
+ protected $_drop_table_if = 'DROP TABLE IF EXISTS';
+
+ /**
+ * UNSIGNED support
+ *
+ * @var bool|array
+ */
+ protected $_unsigned = FALSE;
+
+ /**
+ * NULL value representation in CREATE/ALTER TABLE statements
+ *
+ * @var string
+ */
+ protected $_null = 'NULL';
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Class constructor
+ *
+ * @param object &$db Database object
+ * @return void
+ */
+ public function __construct(&$db)
+ {
+ parent::__construct($db);
+
+ if (version_compare($this->db->version(), '3.3', '<'))
+ {
+ $this->_create_table_if = FALSE;
+ }
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Create database
+ *
+ * @param string $db_name (ignored)
+ * @return bool
+ */
+ public function create_database($db_name = '')
+ {
+ // In SQLite, a database is created when you connect to the database.
+ // We'll return TRUE so that an error isn't generated
+ return TRUE;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Drop database
+ *
+ * @param string $db_name (ignored)
+ * @return bool
+ */
+ public function drop_database($db_name = '')
+ {
+ // In SQLite, a database is dropped when we delete a file
+ if (@file_exists($this->db->database))
+ {
+ // We need to close the pseudo-connection first
+ $this->db->close();
+ if ( ! @unlink($this->db->database))
+ {
+ return $this->db->db_debug ? $this->db->display_error('db_unable_to_drop') : FALSE;
+ }
+ elseif ( ! empty($this->db->data_cache['db_names']))
+ {
+ $key = array_search(strtolower($this->db->database), array_map('strtolower', $this->db->data_cache['db_names']), TRUE);
+ if ($key !== FALSE)
+ {
+ unset($this->db->data_cache['db_names'][$key]);
+ }
+ }
+
+ return TRUE;
+ }
+
+ return $this->db->db_debug ? $this->db->display_error('db_unable_to_drop') : FALSE;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * ALTER TABLE
+ *
+ * @param string $alter_type ALTER type
+ * @param string $table Table name
+ * @param mixed $field Column definition
+ * @return string|string[]
+ */
+ protected function _alter_table($alter_type, $table, $field)
+ {
+ if ($alter_type === 'DROP' OR $alter_type === 'CHANGE')
+ {
+ // drop_column():
+ // BEGIN TRANSACTION;
+ // CREATE TEMPORARY TABLE t1_backup(a,b);
+ // INSERT INTO t1_backup SELECT a,b FROM t1;
+ // DROP TABLE t1;
+ // CREATE TABLE t1(a,b);
+ // INSERT INTO t1 SELECT a,b FROM t1_backup;
+ // DROP TABLE t1_backup;
+ // COMMIT;
+
+ return FALSE;
+ }
+
+ return parent::_alter_table($alter_type, $table, $field);
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Process column
+ *
+ * @param array $field
+ * @return string
+ */
+ protected function _process_column($field)
+ {
+ return $this->db->escape_identifiers($field['name'])
+ .' '.$field['type']
+ .$field['auto_increment']
+ .$field['null']
+ .$field['unique']
+ .$field['default'];
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Field attribute TYPE
+ *
+ * Performs a data type mapping between different databases.
+ *
+ * @param array &$attributes
+ * @return void
+ */
+ protected function _attr_type(&$attributes)
+ {
+ switch (strtoupper($attributes['TYPE']))
+ {
+ case 'ENUM':
+ case 'SET':
+ $attributes['TYPE'] = 'TEXT';
+ return;
+ default: return;
+ }
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Field attribute AUTO_INCREMENT
+ *
+ * @param array &$attributes
+ * @param array &$field
+ * @return void
+ */
+ protected function _attr_auto_increment(&$attributes, &$field)
+ {
+ if ( ! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === TRUE && stripos($field['type'], 'int') !== FALSE)
+ {
+ $field['type'] = 'INTEGER PRIMARY KEY';
+ $field['default'] = '';
+ $field['null'] = '';
+ $field['unique'] = '';
+ $field['auto_increment'] = ' AUTOINCREMENT';
+
+ $this->primary_keys = array();
+ }
+ }
+
+}
+
+/* End of file pdo_sqlite_forge.php */
+/* Location: ./system/database/drivers/pdo/subdrivers/pdo_sqlite_forge.php */ \ No newline at end of file
diff --git a/system/database/drivers/pdo/subdrivers/pdo_sqlsrv_driver.php b/system/database/drivers/pdo/subdrivers/pdo_sqlsrv_driver.php
index 33bd7bea5..7bb7f8806 100644
--- a/system/database/drivers/pdo/subdrivers/pdo_sqlsrv_driver.php
+++ b/system/database/drivers/pdo/subdrivers/pdo_sqlsrv_driver.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 3.0.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* PDO SQLSRV Database Adapter Class
@@ -40,18 +41,40 @@
*/
class CI_DB_pdo_sqlsrv_driver extends CI_DB_pdo_driver {
+ /**
+ * Sub-driver
+ *
+ * @var string
+ */
public $subdriver = 'sqlsrv';
+ // --------------------------------------------------------------------
+
+ /**
+ * ORDER BY random keyword
+ *
+ * @var string
+ */
protected $_random_keyword = ' NEWID()';
+ /**
+ * Quoted identifier flag
+ *
+ * Whether to use SQL-92 standard quoted identifier
+ * (double quotes) or brackets for identifier escaping.
+ *
+ * @var bool
+ */
protected $_quoted_identifier;
+ // --------------------------------------------------------------------
+
/**
- * Constructor
+ * Class constructor
*
* Builds the DSN if not already set.
*
- * @param array
+ * @param array $params
* @return void
*/
public function __construct($params)
@@ -109,9 +132,9 @@ class CI_DB_pdo_sqlsrv_driver extends CI_DB_pdo_driver {
// --------------------------------------------------------------------
/**
- * Non-persistent database connection
+ * Database connection
*
- * @param bool
+ * @param bool $persistent
* @return object
*/
public function db_connect($persistent = FALSE)
@@ -144,7 +167,7 @@ class CI_DB_pdo_sqlsrv_driver extends CI_DB_pdo_driver {
*
* Generates a platform-specific query string so that the table names can be fetched
*
- * @param bool
+ * @param bool $prefix_limit
* @return string
*/
protected function _list_tables($prefix_limit = FALSE)
@@ -169,7 +192,7 @@ class CI_DB_pdo_sqlsrv_driver extends CI_DB_pdo_driver {
*
* Generates a platform-specific query string so that the column names can be fetched
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _list_columns($table = '')
@@ -186,8 +209,8 @@ class CI_DB_pdo_sqlsrv_driver extends CI_DB_pdo_driver {
*
* Generates a platform-specific update string from the supplied data
*
- * @param string the table name
- * @param array the update data
+ * @param string $table
+ * @param array $values
* @return string
*/
protected function _update($table, $values)
@@ -204,7 +227,7 @@ class CI_DB_pdo_sqlsrv_driver extends CI_DB_pdo_driver {
*
* Generates a platform-specific delete string from the supplied data
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _delete($table)
@@ -220,11 +243,11 @@ class CI_DB_pdo_sqlsrv_driver extends CI_DB_pdo_driver {
// --------------------------------------------------------------------
/**
- * Limit string
+ * LIMIT
*
* Generates a platform-specific LIMIT clause
*
- * @param string the sql query string
+ * @param string $sql SQL Query
* @return string
*/
protected function _limit($sql)
@@ -273,6 +296,29 @@ class CI_DB_pdo_sqlsrv_driver extends CI_DB_pdo_driver {
return preg_replace('/(^\SELECT (DISTINCT)?)/i','\\1 TOP '.$limit.' ', $sql);
}
+ // --------------------------------------------------------------------
+
+ /**
+ * Insert batch statement
+ *
+ * Generates a platform-specific insert string from the supplied data.
+ *
+ * @param string $table Table name
+ * @param array $keys INSERT keys
+ * @param array $values INSERT values
+ * @return string|bool
+ */
+ protected function _insert_batch($table, $keys, $values)
+ {
+ // Multiple-value inserts are only supported as of SQL Server 2008
+ if (version_compare($this->version(), '10', '>='))
+ {
+ return parent::_insert_batch($table, $keys, $values);
+ }
+
+ return ($this->db->db_debug) ? $this->db->display_error('db_unsupported_feature') : FALSE;
+ }
+
}
/* End of file pdo_sqlsrv_driver.php */
diff --git a/system/database/drivers/pdo/subdrivers/pdo_sqlsrv_forge.php b/system/database/drivers/pdo/subdrivers/pdo_sqlsrv_forge.php
new file mode 100644
index 000000000..e4b669f6e
--- /dev/null
+++ b/system/database/drivers/pdo/subdrivers/pdo_sqlsrv_forge.php
@@ -0,0 +1,136 @@
+<?php
+/**
+ * CodeIgniter
+ *
+ * An open source application development framework for PHP 5.2.4 or newer
+ *
+ * NOTICE OF LICENSE
+ *
+ * Licensed under the Open Software License version 3.0
+ *
+ * This source file is subject to the Open Software License (OSL 3.0) that is
+ * bundled with this package in the files license.txt / license.rst. It is
+ * also available through the world wide web at this URL:
+ * http://opensource.org/licenses/OSL-3.0
+ * If you did not receive a copy of the license and are unable to obtain it
+ * through the world wide web, please send an email to
+ * licensing@ellislab.com so we can send you a copy immediately.
+ *
+ * @package CodeIgniter
+ * @author EllisLab Dev Team
+ * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
+ * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
+ * @link http://codeigniter.com
+ * @since Version 2.1.0
+ * @filesource
+ */
+defined('BASEPATH') OR exit('No direct script access allowed');
+
+/**
+ * PDO SQLSRV Forge Class
+ *
+ * @category Database
+ * @author EllisLab Dev Team
+ * @link http://codeigniter.com/user_guide/database/
+ */
+class CI_DB_pdo_sqlsrv_forge extends CI_DB_pdo_forge {
+
+ /**
+ * CREATE TABLE IF statement
+ *
+ * @var string
+ */
+ protected $_create_table_if = "IF NOT EXISTS (SELECT * FROM sysobjects WHERE ID = object_id(N'%s') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)\nCREATE TABLE";
+
+ /**
+ * DROP TABLE IF statement
+ *
+ * @var string
+ */
+ protected $_drop_table_if = "IF EXISTS (SELECT * FROM sysobjects WHERE ID = object_id(N'%s') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)\nDROP TABLE";
+
+ /**
+ * UNSIGNED support
+ *
+ * @var array
+ */
+ protected $_unsigned = array(
+ 'TINYINT' => 'SMALLINT',
+ 'SMALLINT' => 'INT',
+ 'INT' => 'BIGINT',
+ 'REAL' => 'FLOAT'
+ );
+
+ // --------------------------------------------------------------------
+
+ /**
+ * ALTER TABLE
+ *
+ * @param string $alter_type ALTER type
+ * @param string $table Table name
+ * @param mixed $field Column definition
+ * @return string|string[]
+ */
+ protected function _alter_table($alter_type, $table, $field)
+ {
+ if (in_array($alter_type, array('ADD', 'DROP'), TRUE))
+ {
+ return parent::_alter_table($alter_type, $table, $field);
+ }
+
+ $sql = 'ALTER TABLE '.$this->db->escape_identifiers($table).' ALTER COLUMN ';
+ $sqls = array();
+ for ($i = 0, $c = count($field); $i < $c; $i++)
+ {
+ $sqls[] = $sql.$this->_process_column($field[$i]);
+ }
+
+ return $sqls;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Field attribute TYPE
+ *
+ * Performs a data type mapping between different databases.
+ *
+ * @param array &$attributes
+ * @return void
+ */
+ protected function _attr_type(&$attributes)
+ {
+ switch (strtoupper($attributes['TYPE']))
+ {
+ case 'MEDIUMINT':
+ $attributes['TYPE'] = 'INTEGER';
+ $attributes['UNSIGNED'] = FALSE;
+ return;
+ case 'INTEGER':
+ $attributes['TYPE'] = 'INT';
+ return;
+ default: return;
+ }
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Field attribute AUTO_INCREMENT
+ *
+ * @param array &$attributes
+ * @param array &$field
+ * @return void
+ */
+ protected function _attr_auto_increment(&$attributes, &$field)
+ {
+ if ( ! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === TRUE && stripos($field['type'], 'int') !== FALSE)
+ {
+ $field['auto_increment'] = ' IDENTITY(1,1)';
+ }
+ }
+
+}
+
+/* End of file pdo_sqlsrv_forge.php */
+/* Location: ./system/database/drivers/pdo/subdrivers/pdo_sqlsrv_forge.php */ \ No newline at end of file
diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php
index ca231f6f7..40f21b1e8 100644
--- a/system/database/drivers/postgre/postgre_driver.php
+++ b/system/database/drivers/postgre/postgre_driver.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Postgre Database Adapter Class
@@ -40,12 +41,13 @@
*/
class CI_DB_postgre_driver extends CI_DB {
+ /**
+ * Database driver
+ *
+ * @var string
+ */
public $dbdriver = 'postgre';
- protected $_escape_char = '"';
-
- protected $_random_keyword = ' RANDOM()'; // database specific random keyword
-
/**
* Database schema
*
@@ -53,8 +55,19 @@ class CI_DB_postgre_driver extends CI_DB {
*/
public $schema = 'public';
+ // --------------------------------------------------------------------
+
/**
- * Constructor
+ * ORDER BY random keyword
+ *
+ * @var string
+ */
+ protected $_random_keyword = ' RANDOM()'; // database specific random keyword
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Class constructor
*
* Creates a DSN string to be used for db_connect() and db_pconnect()
*
@@ -170,7 +183,7 @@ class CI_DB_postgre_driver extends CI_DB {
/**
* Set client character set
*
- * @param string
+ * @param string $charset
* @return bool
*/
protected function _db_set_charset($charset)
@@ -191,8 +204,12 @@ class CI_DB_postgre_driver extends CI_DB {
{
return $this->data_cache['version'];
}
+ elseif ( ! $this->conn_id)
+ {
+ $this->initialize();
+ }
- if (($pg_version = pg_version($this->conn_id)) === FALSE)
+ if ( ! $this->conn_id OR ($pg_version = pg_version($this->conn_id)) === FALSE)
{
return FALSE;
}
@@ -212,7 +229,7 @@ class CI_DB_postgre_driver extends CI_DB {
/**
* Execute the query
*
- * @param string an SQL query
+ * @param string $sql an SQL query
* @return resource
*/
protected function _execute($sql)
@@ -225,7 +242,7 @@ class CI_DB_postgre_driver extends CI_DB {
/**
* Begin Transaction
*
- * @param bool
+ * @param bool $test_mode
* @return bool
*/
public function trans_begin($test_mode = FALSE)
@@ -285,8 +302,8 @@ class CI_DB_postgre_driver extends CI_DB {
/**
* Escape String
*
- * @param string
- * @param bool whether or not the string will be used in a LIKE condition
+ * @param string $str
+ * @param bool $like Whether or not the string will be used in a LIKE condition
* @return string
*/
public function escape_str($str, $like = FALSE)
@@ -322,7 +339,7 @@ class CI_DB_postgre_driver extends CI_DB {
* Escapes data based on type
* Sets boolean and null types
*
- * @param string
+ * @param string $str
* @return mixed
*/
public function escape($str)
@@ -400,7 +417,7 @@ class CI_DB_postgre_driver extends CI_DB {
*
* Generates a platform-specific query string so that the table names can be fetched
*
- * @param bool $prefix_limit = FALSE
+ * @param bool $prefix_limit
* @return string
*/
protected function _list_tables($prefix_limit = FALSE)
@@ -424,7 +441,7 @@ class CI_DB_postgre_driver extends CI_DB {
*
* Generates a platform-specific query string so that the column names can be fetched
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _list_columns($table = '')
@@ -439,7 +456,7 @@ class CI_DB_postgre_driver extends CI_DB {
*
* Generates a platform-specific query so that the column data can be retrieved
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _field_data($table)
@@ -469,8 +486,8 @@ class CI_DB_postgre_driver extends CI_DB {
*
* Generates a platform-specific update string from the supplied data
*
- * @param string the table name
- * @param array the update data
+ * @param string $table
+ * @param array $values
* @return string
*/
protected function _update($table, $values)
@@ -487,9 +504,9 @@ class CI_DB_postgre_driver extends CI_DB {
*
* Generates a platform-specific batch update string from the supplied data
*
- * @param string the table name
- * @param array the update data
- * @param string the where key
+ * @param string $table Table name
+ * @param array $values Update data
+ * @param string $index WHERE key
* @return string
*/
protected function _update_batch($table, $values, $index)
@@ -528,7 +545,7 @@ class CI_DB_postgre_driver extends CI_DB {
*
* Generates a platform-specific delete string from the supplied data
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _delete($table)
@@ -540,11 +557,11 @@ class CI_DB_postgre_driver extends CI_DB {
// --------------------------------------------------------------------
/**
- * Limit string
+ * LIMIT
*
* Generates a platform-specific LIMIT clause
*
- * @param string the sql query string
+ * @param string $sql SQL Query
* @return string
*/
protected function _limit($sql)
diff --git a/system/database/drivers/postgre/postgre_forge.php b/system/database/drivers/postgre/postgre_forge.php
index 1164d9bb3..425622fac 100644
--- a/system/database/drivers/postgre/postgre_forge.php
+++ b/system/database/drivers/postgre/postgre_forge.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Postgre Forge Class
@@ -34,182 +35,151 @@
*/
class CI_DB_postgre_forge extends CI_DB_forge {
- protected $_drop_table = 'DROP TABLE IF EXISTS %s CASCADE';
+ /**
+ * UNSIGNED support
+ *
+ * @var array
+ */
+ protected $_unsigned = array(
+ 'INT2' => 'INTEGER',
+ 'SMALLINT' => 'INTEGER',
+ 'INT' => 'BIGINT',
+ 'INT4' => 'BIGINT',
+ 'INTEGER' => 'BIGINT',
+ 'INT8' => 'NUMERIC',
+ 'BIGINT' => 'NUMERIC',
+ 'REAL' => 'DOUBLE PRECISION',
+ 'FLOAT' => 'DOUBLE PRECISION'
+ );
/**
- * Process Fields
+ * NULL value representation in CREATE/ALTER TABLE statements
*
- * @param mixed $fields
- * @param array $primary_keys = array()
- * @return string
+ * @var string
*/
- protected function _process_fields($fields, $primary_keys = array())
+ protected $_null = 'NULL';
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Class constructor
+ *
+ * @param object &$db Database object
+ * @return void
+ */
+ public function __construct(&$db)
{
- $sql = '';
- $current_field_count = 0;
+ parent::__construct($db);
- foreach ($fields as $field => $attributes)
+ if (version_compare($this->db->version(), '9.0', '>'))
{
- // Numeric field names aren't allowed in databases, so if the key is
- // numeric, we know it was assigned by PHP and the developer manually
- // entered the field information, so we'll simply add it to the list
- if (is_numeric($field))
+ $this->create_table_if = 'CREATE TABLE IF NOT EXISTS';
+ }
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * ALTER TABLE
+ *
+ * @param string $alter_type ALTER type
+ * @param string $table Table name
+ * @param mixed $field Column definition
+ * @return string|string[]
+ */
+ protected function _alter_table($alter_type, $table, $field)
+ {
+ if (in_array($alter_type, array('DROP', 'ADD'), TRUE))
+ {
+ return parent::_alter_table($alter_type, $table, $field);
+ }
+
+ $sql = 'ALTER TABLE '.$this->db->escape_identifiers($table);
+ $sqls = array();
+ for ($i = 0, $c = count($field), $sql .= $alter_type.' '; $i < $c; $i++)
+ {
+ if ($field[$i]['_literal'] !== FALSE)
+ {
+ return FALSE;
+ }
+
+ if (version_compare($this->db->version(), '8', '>=') && isset($field[$i]['type']))
{
- $sql .= "\n\t".$attributes;
+ $sqls[] = $sql.' TYPE '.$field[$i]['type'].$field[$i]['length'];
}
- else
+
+ if ( ! empty($field[$i]['default']))
+ {
+ $sqls[] = $sql.' ALTER '.$this->db->escape_identifiers($field[$i]['name'])
+ .' SET '.$field[$i]['default'];
+ }
+
+ if (isset($field[$i]['null']))
{
- $sql .= "\n\t".$this->db->escape_identifiers($field);
-
- $attributes = array_change_key_case($attributes, CASE_UPPER);
- $is_unsigned = ( ! empty($attributes['UNSIGNED']) && $attributes['UNSIGNED'] === TRUE);
-
- // Convert datatypes to be PostgreSQL-compatible
- switch (strtoupper($attributes['TYPE']))
- {
- case 'TINYINT':
- $attributes['TYPE'] = 'SMALLINT';
- break;
- case 'SMALLINT':
- $attributes['TYPE'] = ($is_unsigned) ? 'INTEGER' : 'SMALLINT';
- break;
- case 'MEDIUMINT':
- $attributes['TYPE'] = 'INTEGER';
- break;
- case 'INT':
- $attributes['TYPE'] = ($is_unsigned) ? 'BIGINT' : 'INTEGER';
- break;
- case 'BIGINT':
- $attributes['TYPE'] = ($is_unsigned) ? 'NUMERIC' : 'BIGINT';
- break;
- case 'DOUBLE':
- $attributes['TYPE'] = 'DOUBLE PRECISION';
- break;
- case 'DATETIME':
- $attributes['TYPE'] = 'TIMESTAMP';
- break;
- case 'LONGTEXT':
- $attributes['TYPE'] = 'TEXT';
- break;
- case 'BLOB':
- $attributes['TYPE'] = 'BYTEA';
- break;
- default:
- break;
- }
-
- // If this is an auto-incrementing primary key, use the serial data type instead
- $sql .= (in_array($field, $primary_keys) && ! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === TRUE)
- ? ' SERIAL' : ' '.$attributes['TYPE'];
-
- // Modified to prevent constraints with integer data types
- if ( ! empty($attributes['CONSTRAINT']) && strpos($attributes['TYPE'], 'INT') === FALSE)
- {
- $sql .= '('.$attributes['CONSTRAINT'].')';
- }
-
- if (isset($attributes['DEFAULT']))
- {
- $sql .= " DEFAULT '".$attributes['DEFAULT']."'";
- }
-
- $sql .= ( ! empty($attributes['NULL']) && $attributes['NULL'] === TRUE)
- ? ' NULL' : ' NOT NULL';
-
- // Added new attribute to create unique fields. Also works with MySQL
- if ( ! empty($attributes['UNIQUE']) && $attributes['UNIQUE'] === TRUE)
- {
- $sql .= ' UNIQUE';
- }
+ $sqls[] = $sql.' ALTER '.$this->db->escape_identifiers($field[$i]['name'])
+ .($field[$i]['null'] === TRUE ? ' DROP NOT NULL' : ' SET NOT NULL');
}
- // don't add a comma on the end of the last field
- if (++$current_field_count < count($fields))
+ if ( ! empty($field[$i]['new_name']))
{
- $sql .= ',';
+ $sqls[] = $sql.' RENAME '.$this->db->escape_identifiers($field[$i]['name'])
+ .' TO '.$this->db->escape_identifiers($field[$i]['new_name']);
}
}
- return $sql;
- }
+ return $sqls;
+ }
// --------------------------------------------------------------------
/**
- * Create Table
+ * Field attribute TYPE
+ *
+ * Performs a data type mapping between different databases.
*
- * @param string the table name
- * @param array the fields
- * @param mixed primary key(s)
- * @param mixed key(s)
- * @param bool should 'IF NOT EXISTS' be added to the SQL
- * @return bool
+ * @param array &$attributes
+ * @return void
*/
- protected function _create_table($table, $fields, $primary_keys, $keys, $if_not_exists)
+ protected function _attr_type(&$attributes)
{
- $sql = 'CREATE TABLE ';
-
- // PostgreSQL doesn't support IF NOT EXISTS syntax so we check if table exists manually
- if ($if_not_exists === TRUE && $this->db->table_exists($table))
+ // Reset field lenghts for data types that don't support it
+ if (isset($attributes['CONSTRAINT']) && stripos($attributes['TYPE'], 'int') !== FALSE)
{
- return TRUE;
+ $attributes['CONSTRAINT'] = NULL;
}
- $sql .= $this->db->escape_identifiers($table).' ('.$this->_process_fields($fields, $primary_keys);
-
- if (count($primary_keys) > 0)
+ switch (strtoupper($attributes['TYPE']))
{
- $sql .= ",\n\tPRIMARY KEY (".implode(', ', $this->db->escape_identifiers($primary_keys)).')';
+ case 'TINYINT':
+ $attributes['TYPE'] = 'SMALLINT';
+ $attributes['UNSIGNED'] = FALSE;
+ return;
+ case 'MEDIUMINT':
+ $attributes['TYPE'] = 'INTEGER';
+ $attributes['UNSIGNED'] = FALSE;
+ return;
+ default: return;
}
-
- $sql .= "\n);";
-
- if (is_array($keys) && count($keys) > 0)
- {
- foreach ($keys as $key)
- {
- $key = is_array($key)
- ? $this->db->escape_identifiers($key)
- : array($this->db->escape_identifiers($key));
-
- foreach ($key as $field)
- {
- $sql .= "\nCREATE INDEX ".$this->db->escape_identifiers($table.'_'.str_replace(array('"', "'"), '', $field).'_index')
- .' ON '.$this->db->escape_identifiers($table).' ('.$this->db->escape_identifiers($field).');';
- }
- }
- }
-
- return $sql;
}
// --------------------------------------------------------------------
/**
- * Alter table query
+ * Field attribute AUTO_INCREMENT
*
- * Generates a platform-specific query so that a table can be altered
- * Called by add_column(), drop_column(), and column_alter(),
- *
- * @param string $alter_type the ALTER type (ADD, DROP, CHANGE)
- * @param string $table the table name
- * @param string $fields the column definition
- * @param string $after_field = ''
- * @return string
+ * @param array &$attributes
+ * @param array &$field
+ * @return void
*/
- protected function _alter_table($alter_type, $table, $fields, $after_field = '')
- {
- $sql = 'ALTER TABLE '.$this->db->escape_identifiers($table).' '.$alter_type.' ';
-
- // DROP has everything it needs now.
- if ($alter_type === 'DROP')
- {
- return $sql.$this->db->escape_identifiers($fields);
- }
-
- return $sql.$this->_process_fields($fields)
- .($after_field !== '' ? ' AFTER '.$this->db->escape_identifiers($after_field) : '');
- }
+ protected function _attr_auto_increment(&$attributes, &$field)
+ {
+ if ( ! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === TRUE)
+ {
+ $field['type'] = ($field['type'] === 'NUMERIC')
+ ? 'BIGSERIAL'
+ : 'SERIAL';
+ }
+ }
}
diff --git a/system/database/drivers/postgre/postgre_result.php b/system/database/drivers/postgre/postgre_result.php
index 458ae869c..3f73f84c7 100644
--- a/system/database/drivers/postgre/postgre_result.php
+++ b/system/database/drivers/postgre/postgre_result.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Postgres Result Class
@@ -129,9 +130,9 @@ class CI_DB_postgre_result extends CI_DB_result {
*
* Moves the internal pointer to the desired offset. We call
* this internally before fetching results to make sure the
- * result set starts at zero
+ * result set starts at zero.
*
- * @param int $n = 0
+ * @param int $n
* @return bool
*/
protected function _data_seek($n = 0)
@@ -160,7 +161,7 @@ class CI_DB_postgre_result extends CI_DB_result {
*
* Returns the result set as an object
*
- * @param string
+ * @param string $class_name
* @return object
*/
protected function _fetch_object($class_name = 'stdClass')
diff --git a/system/database/drivers/postgre/postgre_utility.php b/system/database/drivers/postgre/postgre_utility.php
index c95e6df0c..d3b2b9cdc 100644
--- a/system/database/drivers/postgre/postgre_utility.php
+++ b/system/database/drivers/postgre/postgre_utility.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Postgre Utility Class
@@ -34,19 +35,32 @@
*/
class CI_DB_postgre_utility extends CI_DB_utility {
+ /**
+ * List databases statement
+ *
+ * @var string
+ */
protected $_list_databases = 'SELECT datname FROM pg_database';
+
+ /**
+ * OPTIMIZE TABLE statement
+ *
+ * @var string
+ */
protected $_optimize_table = 'REINDEX TABLE %s';
+ // --------------------------------------------------------------------
+
/**
- * Postgre Export
+ * Export
*
- * @param array Preferences
+ * @param array $params Preferences
* @return mixed
*/
protected function _backup($params = array())
{
// Currently unsupported
- return $this->db->display_error('db_unsuported_feature');
+ return $this->db->display_error('db_unsupported_feature');
}
}
diff --git a/system/database/drivers/sqlite/sqlite_driver.php b/system/database/drivers/sqlite/sqlite_driver.php
index 2fd39346f..85411735c 100644
--- a/system/database/drivers/sqlite/sqlite_driver.php
+++ b/system/database/drivers/sqlite/sqlite_driver.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* SQLite Database Adapter Class
@@ -40,13 +41,24 @@
*/
class CI_DB_sqlite_driver extends CI_DB {
+ /**
+ * Database driver
+ *
+ * @var string
+ */
public $dbdriver = 'sqlite';
- // The character used to escape with - not needed for SQLite
- protected $_escape_char = '"';
+ // --------------------------------------------------------------------
+ /**
+ * ORDER BY random keyword
+ *
+ * @var string
+ */
protected $_random_keyword = ' Random()'; // database specific random keyword
+ // --------------------------------------------------------------------
+
/**
* Non-persistent database connection
*
@@ -112,7 +124,7 @@ class CI_DB_sqlite_driver extends CI_DB {
/**
* Execute the query
*
- * @param string an SQL query
+ * @param string $sql an SQL query
* @return resource
*/
protected function _execute($sql)
@@ -127,7 +139,7 @@ class CI_DB_sqlite_driver extends CI_DB {
/**
* Begin Transaction
*
- * @param bool $test_mode = FALSE
+ * @param bool $test_mode
* @return bool
*/
public function trans_begin($test_mode = FALSE)
@@ -190,8 +202,8 @@ class CI_DB_sqlite_driver extends CI_DB {
/**
* Escape String
*
- * @param string
- * @param bool whether or not the string will be used in a LIKE condition
+ * @param string $str
+ * @param bool $like Whether or not the string will be used in a LIKE condition
* @return string
*/
public function escape_str($str, $like = FALSE)
@@ -250,7 +262,7 @@ class CI_DB_sqlite_driver extends CI_DB {
*
* Generates a platform-specific query string so that the table names can be fetched
*
- * @param bool
+ * @param bool $prefix_limit
* @return string
*/
protected function _list_tables($prefix_limit = FALSE)
@@ -272,7 +284,7 @@ class CI_DB_sqlite_driver extends CI_DB {
*
* Generates a platform-specific query string so that the column names can be fetched
*
- * @param string the table name
+ * @param string $table
* @return bool
*/
protected function _list_columns($table = '')
@@ -288,7 +300,7 @@ class CI_DB_sqlite_driver extends CI_DB {
*
* Generates a platform-specific query so that the column data can be retrieved
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _field_data($table)
@@ -320,9 +332,9 @@ class CI_DB_sqlite_driver extends CI_DB {
*
* Generates a platform-specific replace string from the supplied data
*
- * @param string the table name
- * @param array the insert keys
- * @param array the insert values
+ * @param string $table Table name
+ * @param array $keys INSERT keys
+ * @param array $values INSERT values
* @return string
*/
protected function _replace($table, $keys, $values)
@@ -337,10 +349,10 @@ class CI_DB_sqlite_driver extends CI_DB {
*
* Generates a platform-specific truncate string from the supplied data
*
- * If the database does not support the truncate() command,
+ * If the database does not support the TRUNCATE statement,
* then this function maps to 'DELETE FROM table'
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _truncate($table)
diff --git a/system/database/drivers/sqlite/sqlite_forge.php b/system/database/drivers/sqlite/sqlite_forge.php
index e02e327f3..6ad583560 100644
--- a/system/database/drivers/sqlite/sqlite_forge.php
+++ b/system/database/drivers/sqlite/sqlite_forge.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* SQLite Forge Class
@@ -35,9 +36,32 @@
class CI_DB_sqlite_forge extends CI_DB_forge {
/**
+ * CREATE TABLE IF statement
+ *
+ * @var string
+ */
+ protected $_create_table_if = FALSE;
+
+ /**
+ * UNSIGNED support
+ *
+ * @var bool|array
+ */
+ protected $_unsigned = FALSE;
+
+ /**
+ * NULL value representation in CREATE/ALTER TABLE statements
+ *
+ * @var string
+ */
+ protected $_null = 'NULL';
+
+ // --------------------------------------------------------------------
+
+ /**
* Create database
*
- * @param string the database name
+ * @param string $db_name (ignored)
* @return bool
*/
public function create_database($db_name = '')
@@ -52,7 +76,7 @@ class CI_DB_sqlite_forge extends CI_DB_forge {
/**
* Drop database
*
- * @param string the database name (ignored)
+ * @param string $db_name (ignored)
* @return bool
*/
public function drop_database($db_name = '')
@@ -76,126 +100,95 @@ class CI_DB_sqlite_forge extends CI_DB_forge {
// --------------------------------------------------------------------
/**
- * Create Table
+ * ALTER TABLE
*
- * @param string the table name
- * @param array the fields
- * @param mixed primary key(s)
- * @param mixed key(s)
- * @param bool should 'IF NOT EXISTS' be added to the SQL
- * @return bool
+ * @todo implement drop_column(), modify_column()
+ * @param string $alter_type ALTER type
+ * @param string $table Table name
+ * @param mixed $field Column definition
+ * @return string|string[]
*/
- protected function _create_table($table, $fields, $primary_keys, $keys, $if_not_exists)
+ protected function _alter_table($alter_type, $table, $field)
{
- $sql = 'CREATE TABLE ';
-
- // IF NOT EXISTS added to SQLite in 3.3.0
- if ($if_not_exists === TRUE && version_compare($this->db->version(), '3.3.0', '>=') === TRUE)
+ if ($alter_type === 'DROP' OR $alter_type === 'CHANGE')
{
- $sql .= 'IF NOT EXISTS ';
- }
-
- $sql .= $this->db->escape_identifiers($table).' (';
- $current_field_count = 0;
-
- foreach ($fields as $field => $attributes)
- {
- // Numeric field names aren't allowed in databases, so if the key is
- // numeric, we know it was assigned by PHP and the developer manually
- // entered the field information, so we'll simply add it to the list
- if (is_numeric($field))
- {
- $sql .= "\n\t".$attributes;
- }
- else
- {
- $attributes = array_change_key_case($attributes, CASE_UPPER);
-
- $sql .= "\n\t".$this->db->escape_identifiers($field).' '.$attributes['TYPE'];
-
- empty($attributes['CONSTRAINT']) OR $sql .= '('.$attributes['CONSTRAINT'].')';
-
- if ( ! empty($attributes['UNSIGNED']) && $attributes['UNSIGNED'] === TRUE)
- {
- $sql .= ' UNSIGNED';
- }
-
- if (isset($attributes['DEFAULT']))
- {
- $sql .= " DEFAULT '".$attributes['DEFAULT']."'";
- }
+ // drop_column():
+ // BEGIN TRANSACTION;
+ // CREATE TEMPORARY TABLE t1_backup(a,b);
+ // INSERT INTO t1_backup SELECT a,b FROM t1;
+ // DROP TABLE t1;
+ // CREATE TABLE t1(a,b);
+ // INSERT INTO t1 SELECT a,b FROM t1_backup;
+ // DROP TABLE t1_backup;
+ // COMMIT;
+ return FALSE;
+ }
- $sql .= ( ! empty($attributes['NULL']) && $attributes['NULL'] === TRUE)
- ? ' NULL' : ' NOT NULL';
+ return parent::_alter_table($alter_type, $table, $field);
+ }
- if ( ! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === TRUE)
- {
- $sql .= ' AUTO_INCREMENT';
- }
- }
+ // --------------------------------------------------------------------
- // don't add a comma on the end of the last field
- if (++$current_field_count < count($fields))
- {
- $sql .= ',';
- }
- }
+ /**
+ * Process column
+ *
+ * @param array $field
+ * @return string
+ */
+ protected function _process_column($field)
+ {
+ return $this->db->escape_identifiers($field['name'])
+ .' '.$field['type']
+ .$field['auto_increment']
+ .$field['null']
+ .$field['unique']
+ .$field['default'];
+ }
- if (count($primary_keys) > 0)
- {
- $sql .= ",\n\tPRIMARY KEY (".implode(', ', $this->db->escape_identifiers($primary_keys)).')';
- }
+ // --------------------------------------------------------------------
- if (is_array($keys) && count($keys) > 0)
+ /**
+ * Field attribute TYPE
+ *
+ * Performs a data type mapping between different databases.
+ *
+ * @param array &$attributes
+ * @return void
+ */
+ protected function _attr_type(&$attributes)
+ {
+ switch (strtoupper($attributes['TYPE']))
{
- foreach ($keys as $key)
- {
- $key = is_array($key)
- ? $this->db->escape_identifiers($key)
- : array($this->db->escape_identifiers($key));
-
- $sql .= ",\n\tUNIQUE (".implode(', ', $key).')';
- }
+ case 'ENUM':
+ case 'SET':
+ $attributes['TYPE'] = 'TEXT';
+ return;
+ default: return;
}
-
- return $sql."\n)";
}
// --------------------------------------------------------------------
/**
- * Alter table query
+ * Field attribute AUTO_INCREMENT
*
- * Generates a platform-specific query so that a table can be altered
- * Called by add_column(), drop_column(), and column_alter(),
- *
- * @param string the ALTER type (ADD, DROP, CHANGE)
- * @param string the column name
- * @param string the table name
- * @param string the column definition
- * @param string the default value
- * @param bool should 'NOT NULL' be added
- * @param string the field after which we should add the new field
- * @return string
+ * @param array &$attributes
+ * @param array &$field
+ * @return void
*/
- protected function _alter_table($alter_type, $table, $column_name, $column_definition = '', $default_value = '', $null = '', $after_field = '')
+ protected function _attr_auto_increment(&$attributes, &$field)
{
- /* SQLite only supports adding new columns and it does
- * NOT support the AFTER statement. Each new column will
- * be added as the last one in the table.
- */
- if ($alter_type !== 'ADD COLUMN')
+ if ( ! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === TRUE && stripos($field['type'], 'int') !== FALSE)
{
- // Not supported
- return FALSE;
- }
+ $field['type'] = 'INTEGER PRIMARY KEY';
+ $field['default'] = '';
+ $field['null'] = '';
+ $field['unique'] = '';
+ $field['auto_increment'] = ' AUTOINCREMENT';
- return 'ALTER TABLE '.$this->db->escape_identifiers($table).' '.$alter_type.' '.$this->db->escape_identifiers($column_name)
- .' '.$column_definition
- .($default_value != '' ? " DEFAULT '".$default_value."'" : '')
- // If NOT NULL is specified, the field must have a DEFAULT value other than NULL
- .(($null !== NULL && $default_value !== 'NULL') ? ' NOT NULL' : ' NULL');
+ $this->primary_keys = array();
+ }
}
}
diff --git a/system/database/drivers/sqlite/sqlite_result.php b/system/database/drivers/sqlite/sqlite_result.php
index 214841412..0e6335f73 100644
--- a/system/database/drivers/sqlite/sqlite_result.php
+++ b/system/database/drivers/sqlite/sqlite_result.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* SQLite Result Class
@@ -113,9 +114,9 @@ class CI_DB_sqlite_result extends CI_DB_result {
*
* Moves the internal pointer to the desired offset. We call
* this internally before fetching results to make sure the
- * result set starts at zero
+ * result set starts at zero.
*
- * @param int $n = 0
+ * @param int $n
* @return bool
*/
protected function _data_seek($n = 0)
@@ -144,7 +145,7 @@ class CI_DB_sqlite_result extends CI_DB_result {
*
* Returns the result set as an object
*
- * @param string
+ * @param string $class_name
* @return object
*/
protected function _fetch_object($class_name = 'stdClass')
diff --git a/system/database/drivers/sqlite/sqlite_utility.php b/system/database/drivers/sqlite/sqlite_utility.php
index 1bcb42d9f..222d02712 100644
--- a/system/database/drivers/sqlite/sqlite_utility.php
+++ b/system/database/drivers/sqlite/sqlite_utility.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* SQLite Utility Class
@@ -34,18 +35,16 @@
*/
class CI_DB_sqlite_utility extends CI_DB_utility {
- protected $_list_databases = FALSE;
-
/**
- * SQLite Export
+ * Export
*
- * @param array Preferences
+ * @param array $params Preferences
* @return mixed
*/
protected function _backup($params = array())
{
// Currently unsupported
- return $this->db->display_error('db_unsuported_feature');
+ return $this->db->display_error('db_unsupported_feature');
}
}
diff --git a/system/database/drivers/sqlite3/sqlite3_driver.php b/system/database/drivers/sqlite3/sqlite3_driver.php
index 22c72b9b8..9a2c1eefc 100644
--- a/system/database/drivers/sqlite3/sqlite3_driver.php
+++ b/system/database/drivers/sqlite3/sqlite3_driver.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* SQLite3 Database Adapter Class
@@ -41,13 +42,24 @@
*/
class CI_DB_sqlite3_driver extends CI_DB {
+ /**
+ * Database driver
+ *
+ * @var string
+ */
public $dbdriver = 'sqlite3';
- // The character used for escaping
- protected $_escape_char = '"';
+ // --------------------------------------------------------------------
+ /**
+ * ORDER BY random keyword
+ *
+ * @var string
+ */
protected $_random_keyword = ' RANDOM()';
+ // --------------------------------------------------------------------
+
/**
* Non-persistent database connection
*
@@ -119,7 +131,7 @@ class CI_DB_sqlite3_driver extends CI_DB {
/**
* Begin Transaction
*
- * @param bool $test_mode = FALSE
+ * @param bool $test_mode
* @return bool
*/
public function trans_begin($test_mode = FALSE)
@@ -179,8 +191,8 @@ class CI_DB_sqlite3_driver extends CI_DB {
/**
* Escape String
*
- * @param string
- * @param bool whether or not the string will be used in a LIKE condition
+ * @param string $str
+ * @param bool $like Whether or not the string will be used in a LIKE condition
* @return string
*/
public function escape_str($str, $like = FALSE)
@@ -239,7 +251,7 @@ class CI_DB_sqlite3_driver extends CI_DB {
*
* Generates a platform-specific query string so that the table names can be fetched
*
- * @param bool
+ * @param bool $prefix_limit
* @return string
*/
protected function _list_tables($prefix_limit = FALSE)
@@ -257,7 +269,7 @@ class CI_DB_sqlite3_driver extends CI_DB {
*
* Generates a platform-specific query string so that the column names can be fetched
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _list_columns($table = '')
@@ -273,7 +285,7 @@ class CI_DB_sqlite3_driver extends CI_DB {
*
* Generates a platform-specific query so that the column data can be retrieved
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _field_data($table)
@@ -303,9 +315,9 @@ class CI_DB_sqlite3_driver extends CI_DB {
*
* Generates a platform-specific replace string from the supplied data
*
- * @param string the table name
- * @param array the insert keys
- * @param array the insert values
+ * @param string $table Table name
+ * @param array $keys INSERT keys
+ * @param array $values INSERT values
* @return string
*/
protected function _replace($table, $keys, $values)
@@ -320,10 +332,10 @@ class CI_DB_sqlite3_driver extends CI_DB {
*
* Generates a platform-specific truncate string from the supplied data
*
- * If the database does not support the truncate() command, then,
+ * If the database does not support the TRUNCATE statement,
* then this method maps to 'DELETE FROM table'
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _truncate($table)
diff --git a/system/database/drivers/sqlite3/sqlite3_forge.php b/system/database/drivers/sqlite3/sqlite3_forge.php
index f9ae5bcce..e9b91e972 100644
--- a/system/database/drivers/sqlite3/sqlite3_forge.php
+++ b/system/database/drivers/sqlite3/sqlite3_forge.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* SQLite3 Forge Class
@@ -35,9 +36,43 @@
class CI_DB_sqlite3_forge extends CI_DB_forge {
/**
+ * UNSIGNED support
+ *
+ * @var bool|array
+ */
+ protected $_unsigned = FALSE;
+
+ /**
+ * NULL value representation in CREATE/ALTER TABLE statements
+ *
+ * @var string
+ */
+ protected $_null = 'NULL';
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Class constructor
+ *
+ * @param object &$db Database object
+ * @return void
+ */
+ public function __construct(&$db)
+ {
+ parent::__construct($db);
+
+ if (version_compare($this->db->version(), '3.3', '<'))
+ {
+ $this->create_table_if = FALSE;
+ }
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
* Create database
*
- * @param string the database name
+ * @param string $db_name
* @return bool
*/
public function create_database($db_name = '')
@@ -52,7 +87,7 @@ class CI_DB_sqlite3_forge extends CI_DB_forge {
/**
* Drop database
*
- * @param string the database name (ignored)
+ * @param string $db_name (ignored)
* @return bool
*/
public function drop_database($db_name = '')
@@ -84,125 +119,95 @@ class CI_DB_sqlite3_forge extends CI_DB_forge {
// --------------------------------------------------------------------
/**
- * Create Table
+ * ALTER TABLE
*
- * @param string the table name
- * @param array the fields
- * @param mixed primary key(s)
- * @param mixed key(s)
- * @param bool should 'IF NOT EXISTS' be added to the SQL
- * @return bool
+ * @todo implement drop_column(), modify_column()
+ * @param string $alter_type ALTER type
+ * @param string $table Table name
+ * @param mixed $field Column definition
+ * @return string|string[]
*/
- protected function _create_table($table, $fields, $primary_keys, $keys, $if_not_exists)
+ protected function _alter_table($alter_type, $table, $field)
{
- $sql = 'CREATE TABLE ';
-
- // IF NOT EXISTS added to SQLite in 3.3.0
- if ($if_not_exists === TRUE && version_compare($this->db->version(), '3.3.0', '>=') === TRUE)
- {
- $sql .= 'IF NOT EXISTS ';
- }
-
- $sql .= $this->db->escape_identifiers($table).' (';
- $current_field_count = 0;
-
- foreach ($fields as $field => $attributes)
+ if ($alter_type === 'DROP' OR $alter_type === 'CHANGE')
{
- // Numeric field names aren't allowed in databases, so if the key is
- // numeric, we know it was assigned by PHP and the developer manually
- // entered the field information, so we'll simply add it to the list
- if (is_numeric($field))
- {
- $sql .= "\n\t".$attributes;
- }
- else
- {
- $attributes = array_change_key_case($attributes, CASE_UPPER);
-
- $sql .= "\n\t".$this->db->escape_identifiers($field).' '.$attributes['TYPE'];
-
- empty($attributes['CONSTRAINT']) OR $sql .= '('.$attributes['CONSTRAINT'].')';
-
- if ( ! empty($attributes['UNSIGNED']) && $attributes['UNSIGNED'] === TRUE)
- {
- $sql .= ' UNSIGNED';
- }
+ // drop_column():
+ // BEGIN TRANSACTION;
+ // CREATE TEMPORARY TABLE t1_backup(a,b);
+ // INSERT INTO t1_backup SELECT a,b FROM t1;
+ // DROP TABLE t1;
+ // CREATE TABLE t1(a,b);
+ // INSERT INTO t1 SELECT a,b FROM t1_backup;
+ // DROP TABLE t1_backup;
+ // COMMIT;
- if (isset($attributes['DEFAULT']))
- {
- $sql .= " DEFAULT '".$attributes['DEFAULT']."'";
- }
+ return FALSE;
+ }
- $sql .= ( ! empty($attributes['NULL']) && $attributes['NULL'] === TRUE)
- ? ' NULL' : ' NOT NULL';
+ return parent::_alter_table($alter_type, $table, $field);
+ }
- if ( ! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === TRUE)
- {
- $sql .= ' AUTO_INCREMENT';
- }
- }
+ // --------------------------------------------------------------------
- // don't add a comma on the end of the last field
- if (++$current_field_count < count($fields))
- {
- $sql .= ',';
- }
- }
+ /**
+ * Process column
+ *
+ * @param array $field
+ * @return string
+ */
+ protected function _process_column($field)
+ {
+ return $this->db->escape_identifiers($field['name'])
+ .' '.$field['type']
+ .$field['auto_increment']
+ .$field['null']
+ .$field['unique']
+ .$field['default'];
+ }
- if (count($primary_keys) > 0)
- {
- $sql .= ",\n\tPRIMARY KEY (".implode(', ', $this->db->escape_identifiers($primary_keys)).')';
- }
+ // --------------------------------------------------------------------
- if (is_array($keys) && count($keys) > 0)
+ /**
+ * Field attribute TYPE
+ *
+ * Performs a data type mapping between different databases.
+ *
+ * @param array &$attributes
+ * @return void
+ */
+ protected function _attr_type(&$attributes)
+ {
+ switch (strtoupper($attributes['TYPE']))
{
- foreach ($keys as $key)
- {
- $key = is_array($key)
- ? $this->db->escape_identifiers($key)
- : array($this->db->escape_identifiers($key));
-
- $sql .= ",\n\tUNIQUE (".implode(', ', $key).')';
- }
+ case 'ENUM':
+ case 'SET':
+ $attributes['TYPE'] = 'TEXT';
+ return;
+ default: return;
}
-
- return $sql."\n)";
}
// --------------------------------------------------------------------
/**
- * Alter table query
- *
- * Generates a platform-specific query so that a table can be altered
- * Called by add_column(), drop_column(), and column_alter(),
+ * Field attribute AUTO_INCREMENT
*
- * @param string the ALTER type (ADD, DROP, CHANGE)
- * @param string the column name
- * @param string the table name
- * @param string the column definition
- * @param string the default value
- * @param bool should 'NOT NULL' be added
- * @param string the field after which we should add the new field
- * @return string
+ * @param array &$attributes
+ * @param array &$field
+ * @return void
*/
- protected function _alter_table($alter_type, $table, $column_name, $column_definition = '', $default_value = '', $null = '', $after_field = '')
+ protected function _attr_auto_increment(&$attributes, &$field)
{
- /* SQLite only supports adding new columns and it does
- * NOT support the AFTER statement. Each new column will
- * be added as the last one in the table.
- */
- if ($alter_type !== 'ADD COLUMN')
+ if ( ! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === TRUE && stripos($field['type'], 'int') !== FALSE)
{
- // Not supported
- return FALSE;
- }
+ $field['type'] = 'INTEGER PRIMARY KEY';
+ $field['default'] = '';
+ $field['null'] = '';
+ $field['unique'] = '';
+ $field['auto_increment'] = ' AUTOINCREMENT';
- return 'ALTER TABLE '.$this->db->escape_identifiers($table).' '.$alter_type.' '.$this->db->escape_identifiers($column_name)
- .' '.$column_definition
- .($default_value !== '' ? ' DEFAULT '.$default_value : '')
- // If NOT NULL is specified, the field must have a DEFAULT value other than NULL
- .(($null !== NULL && $default_value !== 'NULL') ? ' NOT NULL' : ' NULL');
+ $this->primary_keys = array();
+ }
}
}
diff --git a/system/database/drivers/sqlite3/sqlite3_result.php b/system/database/drivers/sqlite3/sqlite3_result.php
index 35aecda36..153e3480a 100644
--- a/system/database/drivers/sqlite3/sqlite3_result.php
+++ b/system/database/drivers/sqlite3/sqlite3_result.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* SQLite3 Result Class
@@ -37,9 +38,6 @@
*/
class CI_DB_sqlite3_result extends CI_DB_result {
- // num_fields() might be called multiple times, so we'll use this one to cache it's result
- protected $_num_fields;
-
/**
* Number of fields in the result set
*
@@ -47,9 +45,7 @@ class CI_DB_sqlite3_result extends CI_DB_result {
*/
public function num_fields()
{
- return ( ! is_int($this->_num_fields))
- ? $this->_num_fields = $this->result_id->numColumns()
- : $this->_num_fields;
+ return $this->result_id->numColumns();
}
// --------------------------------------------------------------------
@@ -134,7 +130,7 @@ class CI_DB_sqlite3_result extends CI_DB_result {
*
* Returns the result set as an object
*
- * @param string
+ * @param string $class_name
* @return object
*/
protected function _fetch_object($class_name = 'stdClass')
@@ -165,9 +161,9 @@ class CI_DB_sqlite3_result extends CI_DB_result {
*
* Moves the internal pointer to the desired offset. We call
* this internally before fetching results to make sure the
- * result set starts at zero
+ * result set starts at zero.
*
- * @param $n = 0 (ignored)
+ * @param int $n (ignored)
* @return array
*/
protected function _data_seek($n = 0)
diff --git a/system/database/drivers/sqlite3/sqlite3_utility.php b/system/database/drivers/sqlite3/sqlite3_utility.php
index f58c3d168..c7736cc6d 100644
--- a/system/database/drivers/sqlite3/sqlite3_utility.php
+++ b/system/database/drivers/sqlite3/sqlite3_utility.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* SQLite3 Utility Class
@@ -34,18 +35,16 @@
*/
class CI_DB_sqlite3_utility extends CI_DB_utility {
- protected $_list_databases = FALSE;
-
/**
- * SQLite Export
+ * Export
*
- * @param array Preferences
+ * @param array $params Preferences
* @return mixed
*/
protected function _backup($params = array())
{
// Not supported
- return $this->db->display_error('db_unsuported_feature');
+ return $this->db->display_error('db_unsupported_feature');
}
}
diff --git a/system/database/drivers/sqlsrv/sqlsrv_driver.php b/system/database/drivers/sqlsrv/sqlsrv_driver.php
index 32f1a59d6..09ccc0200 100644
--- a/system/database/drivers/sqlsrv/sqlsrv_driver.php
+++ b/system/database/drivers/sqlsrv/sqlsrv_driver.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 2.0.3
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* SQLSRV Database Adapter Class
@@ -40,20 +41,38 @@
*/
class CI_DB_sqlsrv_driver extends CI_DB {
+ /**
+ * Database driver
+ *
+ * @var string
+ */
public $dbdriver = 'sqlsrv';
- // The character used for escaping
- protected $_escape_char = '"';
+ // --------------------------------------------------------------------
+ /**
+ * ORDER BY random keyword
+ *
+ * @var string
+ */
protected $_random_keyword = ' NEWID()';
- // SQLSRV-specific properties
+ /**
+ * Quoted identifier flag
+ *
+ * Whether to use SQL-92 standard quoted identifier
+ * (double quotes) or brackets for identifier escaping.
+ *
+ * @var bool
+ */
protected $_quoted_identifier = TRUE;
+ // --------------------------------------------------------------------
+
/**
- * Non-persistent database connection
+ * Database connection
*
- * @param bool $pooling = FALSE
+ * @param bool $pooling
* @return resource
*/
public function db_connect($pooling = FALSE)
@@ -106,7 +125,7 @@ class CI_DB_sqlsrv_driver extends CI_DB {
/**
* Select the database
*
- * @param string database name
+ * @param string $database
* @return bool
*/
public function db_select($database = '')
@@ -130,7 +149,7 @@ class CI_DB_sqlsrv_driver extends CI_DB {
/**
* Execute the query
*
- * @param string an SQL query
+ * @param string $sql an SQL query
* @return resource
*/
protected function _execute($sql)
@@ -145,7 +164,7 @@ class CI_DB_sqlsrv_driver extends CI_DB {
/**
* Begin Transaction
*
- * @param bool $test_mode = FALSE
+ * @param bool $test_mode
* @return bool
*/
public function trans_begin($test_mode = FALSE)
@@ -205,8 +224,8 @@ class CI_DB_sqlsrv_driver extends CI_DB {
/**
* Escape String
*
- * @param string
- * @param bool whether or not the string will be used in a LIKE condition
+ * @param string $str
+ * @param bool $like Whether or not the string will be used in a LIKE condition
* @return string
*/
public function escape_str($str, $like = FALSE)
@@ -256,8 +275,12 @@ class CI_DB_sqlsrv_driver extends CI_DB {
{
return $this->data_cache['version'];
}
+ elseif ( ! $this->conn_id)
+ {
+ $this->initialize();
+ }
- if (($info = sqlsrv_server_info($this->conn_id)) === FALSE)
+ if ( ! $this->conn_id OR ($info = sqlsrv_server_info($this->conn_id)) === FALSE)
{
return FALSE;
}
@@ -273,7 +296,7 @@ class CI_DB_sqlsrv_driver extends CI_DB {
* Generates a platform-specific query string so that the table names can be fetched
*
* @param bool
- * @return string
+ * @return string $prefix_limit
*/
protected function _list_tables($prefix_limit = FALSE)
{
@@ -297,7 +320,7 @@ class CI_DB_sqlsrv_driver extends CI_DB {
*
* Generates a platform-specific query string so that the column names can be fetched
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _list_columns($table = '')
@@ -312,7 +335,7 @@ class CI_DB_sqlsrv_driver extends CI_DB {
*
* Generates a platform-specific query so that the column data can be retrieved
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _field_data($table)
@@ -365,8 +388,8 @@ class CI_DB_sqlsrv_driver extends CI_DB {
*
* Generates a platform-specific update string from the supplied data
*
- * @param string the table name
- * @param array the update data
+ * @param string $table
+ * @param array $values
* @return string
*/
protected function _update($table, $values)
@@ -383,10 +406,10 @@ class CI_DB_sqlsrv_driver extends CI_DB {
*
* Generates a platform-specific truncate string from the supplied data
*
- * If the database does not support the truncate() command,
+ * If the database does not support the TRUNCATE statement,
* then this method maps to 'DELETE FROM table'
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _truncate($table)
@@ -401,7 +424,7 @@ class CI_DB_sqlsrv_driver extends CI_DB {
*
* Generates a platform-specific delete string from the supplied data
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _delete($table)
@@ -417,11 +440,11 @@ class CI_DB_sqlsrv_driver extends CI_DB {
// --------------------------------------------------------------------
/**
- * Limit string
+ * LIMIT
*
* Generates a platform-specific LIMIT clause
*
- * @param string the sql query string
+ * @param string $sql SQL Query
* @return string
*/
protected function _limit($sql)
@@ -473,6 +496,29 @@ class CI_DB_sqlsrv_driver extends CI_DB {
// --------------------------------------------------------------------
/**
+ * Insert batch statement
+ *
+ * Generates a platform-specific insert string from the supplied data.
+ *
+ * @param string $table Table name
+ * @param array $keys INSERT keys
+ * @param array $values INSERT values
+ * @return string|bool
+ */
+ protected function _insert_batch($table, $keys, $values)
+ {
+ // Multiple-value inserts are only supported as of SQL Server 2008
+ if (version_compare($this->version(), '10', '>='))
+ {
+ return parent::_insert_batch($table, $keys, $values);
+ }
+
+ return ($this->db->db_debug) ? $this->db->display_error('db_unsupported_feature') : FALSE;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
* Close DB Connection
*
* @return void
diff --git a/system/database/drivers/sqlsrv/sqlsrv_forge.php b/system/database/drivers/sqlsrv/sqlsrv_forge.php
index ccdb36929..da8f68c56 100644
--- a/system/database/drivers/sqlsrv/sqlsrv_forge.php
+++ b/system/database/drivers/sqlsrv/sqlsrv_forge.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 2.0.3
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* SQLSRV Forge Class
@@ -34,124 +35,99 @@
*/
class CI_DB_sqlsrv_forge extends CI_DB_forge {
- protected $_drop_table = 'DROP TABLE %s';
-
/**
- * Create Table
+ * CREATE TABLE IF statement
*
- * @param string the table name
- * @param array the fields
- * @param mixed primary key(s)
- * @param mixed key(s)
- * @param bool should 'IF NOT EXISTS' be added to the SQL
- * @return string
+ * @var string
*/
- protected function _create_table($table, $fields, $primary_keys, $keys, $if_not_exists)
- {
- $sql = ($if_not_exists === TRUE)
- ? "IF NOT EXISTS (SELECT * FROM sysobjects WHERE ID = object_id(N'".$table."') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)\n"
- : '';
-
- $sql .= 'CREATE TABLE '.$this->db->escape_identifiers($table).' (';
-
- $current_field_count = 0;
- foreach ($fields as $field => $attributes)
- {
- // Numeric field names aren't allowed in databases, so if the key is
- // numeric, we know it was assigned by PHP and the developer manually
- // entered the field information, so we'll simply add it to the list
- if (is_numeric($field))
- {
- $sql .= "\n\t".$attributes;
- }
- else
- {
- $attributes = array_change_key_case($attributes, CASE_UPPER);
-
- $sql .= "\n\t".$this->db->escape_identifiers($field).' '.$attributes['TYPE'];
-
- if (stripos($attributes['TYPE'], 'INT') === FALSE && ! empty($attributes['CONSTRAINT']))
- {
- $sql .= '('.$attributes['CONSTRAINT'].')';
- }
-
- if ( ! empty($attributes['UNSIGNED']) && $attributes['UNSIGNED'] === TRUE)
- {
- $sql .= ' UNSIGNED';
- }
+ protected $_create_table_if = "IF NOT EXISTS (SELECT * FROM sysobjects WHERE ID = object_id(N'%s') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)\nCREATE TABLE";
- if (isset($attributes['DEFAULT']))
- {
- $sql .= " DEFAULT '".$attributes['DEFAULT']."'";
- }
-
- $sql .= ( ! empty($attributes['NULL']) && $attribues['NULL'] === TRUE)
- ? ' NULL' : ' NOT NULL';
+ /**
+ * DROP TABLE IF statement
+ *
+ * @var string
+ */
+ protected $_drop_table_if = "IF EXISTS (SELECT * FROM sysobjects WHERE ID = object_id(N'%s') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)\nDROP TABLE";
- if ( ! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === TRUE)
- {
- $sql .= ' AUTO_INCREMENT';
- }
- }
+ /**
+ * UNSIGNED support
+ *
+ * @var array
+ */
+ protected $_unsigned = array(
+ 'TINYINT' => 'SMALLINT',
+ 'SMALLINT' => 'INT',
+ 'INT' => 'BIGINT',
+ 'REAL' => 'FLOAT'
+ );
- // don't add a comma on the end of the last field
- if (++$current_field_count < count($fields))
- {
- $sql .= ',';
- }
- }
+ // --------------------------------------------------------------------
- if (count($primary_keys) > 0)
+ /**
+ * ALTER TABLE
+ *
+ * @param string $alter_type ALTER type
+ * @param string $table Table name
+ * @param mixed $field Column definition
+ * @return string|string[]
+ */
+ protected function _alter_table($alter_type, $table, $field)
+ {
+ if (in_array($alter_type, array('ADD', 'DROP'), TRUE))
{
- $sql .= ",\n\tPRIMARY KEY (".implode(', ', $this->db->escape_identifiers($primary_keys)).')';
+ return parent::_alter_table($alter_type, $table, $field);
}
- if (is_array($keys) && count($keys) > 0)
+ $sql = 'ALTER TABLE '.$this->db->escape_identifiers($table).' ALTER COLUMN ';
+ $sqls = array();
+ for ($i = 0, $c = count($field); $i < $c; $i++)
{
- foreach ($keys as $key)
- {
- $key = is_array($key)
- ? $this->db->escape_identifiers($key)
- : array($this->escape_identifiers($key));
-
- $sql .= ",\n\tFOREIGN KEY (".implode(', ', $key).')';
- }
+ $sqls[] = $sql.$this->_process_column($field[$i]);
}
- return $sql."\n)";
+ return $sqls;
}
// --------------------------------------------------------------------
/**
- * Alter table query
+ * Field attribute TYPE
*
- * Generates a platform-specific query so that a table can be altered
- * Called by add_column(), drop_column(), and column_alter(),
+ * Performs a data type mapping between different databases.
*
- * @param string the ALTER type (ADD, DROP, CHANGE)
- * @param string the column name
- * @param string the table name
- * @param string the column definition
- * @param string the default value
- * @param bool should 'NOT NULL' be added
- * @param string the field after which we should add the new field
- * @return string
+ * @param array &$attributes
+ * @return void
*/
- protected function _alter_table($alter_type, $table, $column_name, $column_definition = '', $default_value = '', $null = '', $after_field = '')
+ protected function _attr_type(&$attributes)
{
- $sql = 'ALTER TABLE '.$this->db->escape_identifiers($table).' '.$alter_type.' '.$this->db->escape_identifiers($column_name);
-
- // DROP has everything it needs now.
- if ($alter_type === 'DROP')
+ switch (strtoupper($attributes['TYPE']))
{
- return $sql;
+ case 'MEDIUMINT':
+ $attributes['TYPE'] = 'INTEGER';
+ $attributes['UNSIGNED'] = FALSE;
+ return;
+ case 'INTEGER':
+ $attributes['TYPE'] = 'INT';
+ return;
+ default: return;
}
+ }
- return $sql.' '.$column_definition
- .($default_value != '' ? ' DEFAULT "'.$default_value.'"' : '')
- .($null === NULL ? ' NULL' : ' NOT NULL')
- .($after_field != '' ? ' AFTER '.$this->db->escape_identifiers($after_field) : '');
+ // --------------------------------------------------------------------
+
+ /**
+ * Field attribute AUTO_INCREMENT
+ *
+ * @param array &$attributes
+ * @param array &$field
+ * @return void
+ */
+ protected function _attr_auto_increment(&$attributes, &$field)
+ {
+ if ( ! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === TRUE && stripos($field['type'], 'int') !== FALSE)
+ {
+ $field['auto_increment'] = ' IDENTITY(1,1)';
+ }
}
}
diff --git a/system/database/drivers/sqlsrv/sqlsrv_result.php b/system/database/drivers/sqlsrv/sqlsrv_result.php
index fb7a68647..6d24cc995 100644
--- a/system/database/drivers/sqlsrv/sqlsrv_result.php
+++ b/system/database/drivers/sqlsrv/sqlsrv_result.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* SQLSRV Result Class
@@ -145,7 +146,7 @@ class CI_DB_sqlsrv_result extends CI_DB_result {
*
* Returns the result set as an object
*
- * @param string
+ * @param string $class_name
* @return object
*/
protected function _fetch_object($class_name = 'stdClass')
diff --git a/system/database/drivers/sqlsrv/sqlsrv_utility.php b/system/database/drivers/sqlsrv/sqlsrv_utility.php
index d518cc15a..2bc7f9e03 100644
--- a/system/database/drivers/sqlsrv/sqlsrv_utility.php
+++ b/system/database/drivers/sqlsrv/sqlsrv_utility.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 2.0.3
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* SQLSRV Utility Class
@@ -34,19 +35,32 @@
*/
class CI_DB_sqlsrv_utility extends CI_DB_utility {
+ /**
+ * List databases statement
+ *
+ * @var string
+ */
protected $_list_databases = 'EXEC sp_helpdb'; // Can also be: EXEC sp_databases
+
+ /**
+ * OPTIMIZE TABLE statement
+ *
+ * @var string
+ */
protected $_optimize_table = 'ALTER INDEX all ON %s REORGANIZE';
+ // --------------------------------------------------------------------
+
/**
- * SQLSRV Export
+ * Export
*
- * @param array Preferences
+ * @param array $params Preferences
* @return bool
*/
protected function _backup($params = array())
{
// Currently unsupported
- return $this->db->display_error('db_unsuported_feature');
+ return $this->db->display_error('db_unsupported_feature');
}
}
diff --git a/system/helpers/array_helper.php b/system/helpers/array_helper.php
index ed2fe3c4a..0e66e4b77 100644
--- a/system/helpers/array_helper.php
+++ b/system/helpers/array_helper.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* CodeIgniter Array Helpers
diff --git a/system/helpers/captcha_helper.php b/system/helpers/captcha_helper.php
index 3aac14db8..e9b167fa9 100644
--- a/system/helpers/captcha_helper.php
+++ b/system/helpers/captcha_helper.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* CodeIgniter CAPTCHA Helper
diff --git a/system/helpers/cookie_helper.php b/system/helpers/cookie_helper.php
index f396c76b0..02841409d 100644
--- a/system/helpers/cookie_helper.php
+++ b/system/helpers/cookie_helper.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* CodeIgniter Cookie Helpers
diff --git a/system/helpers/date_helper.php b/system/helpers/date_helper.php
index 5d9251526..0fa400d7e 100644
--- a/system/helpers/date_helper.php
+++ b/system/helpers/date_helper.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* CodeIgniter Date Helpers
@@ -449,20 +450,13 @@ if ( ! function_exists('human_to_unix'))
return FALSE;
}
- $split = explode(' ', $datestr);
+ sscanf($datestr, '%d-%d-%d %s %s', $year, $month, $day, $time, $ampm);
+ sscanf($time, '%d:%d:%d', $hour, $min, $sec);
+ isset($sec) OR $sec = 0;
- list($year, $month, $day) = explode('-', $split[0]);
-
- $ex = explode(':', $split['1']);
-
- $hour = (int) $ex[0];
- $min = (int) $ex[1];
- $sec = ( ! empty($ex[2]) && preg_match('/[0-9]{1,2}/', $ex[2]))
- ? (int) $ex[2] : 0;
-
- if (isset($split[2]))
+ if (isset($ampm))
{
- $ampm = strtolower($split[2]);
+ $ampm = strtolower($ampm);
if ($ampm[0] === 'p' && $hour < 12)
{
diff --git a/system/helpers/directory_helper.php b/system/helpers/directory_helper.php
index 7d6b6770e..49dcfc8a9 100644
--- a/system/helpers/directory_helper.php
+++ b/system/helpers/directory_helper.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* CodeIgniter Directory Helpers
@@ -46,9 +47,10 @@ if ( ! function_exists('directory_map'))
* representation of it. Sub-folders contained with the
* directory will be mapped as well.
*
- * @param string path to source
- * @param int depth of directories to traverse (0 = fully recursive, 1 = current dir, etc)
- * @param bool whether to show hidden files
+ * @param string $source_dir Path to source
+ * @param int $directory_depth Depth of directories to traverse
+ * (0 = fully recursive, 1 = current dir, etc)
+ * @param bool $hidden Whether to show hidden files
* @return array
*/
function directory_map($source_dir, $directory_depth = 0, $hidden = FALSE)
@@ -67,9 +69,11 @@ if ( ! function_exists('directory_map'))
continue;
}
+ @is_dir($source_dir.$file) AND $file .= DIRECTORY_SEPARATOR;
+
if (($directory_depth < 1 OR $new_depth > 0) && @is_dir($source_dir.$file))
{
- $filedata[$file] = directory_map($source_dir.$file.DIRECTORY_SEPARATOR, $new_depth, $hidden);
+ $filedata[$file] = directory_map($source_dir.$file, $new_depth, $hidden);
}
else
{
diff --git a/system/helpers/download_helper.php b/system/helpers/download_helper.php
index 2c26a36d5..8fe66e222 100644
--- a/system/helpers/download_helper.php
+++ b/system/helpers/download_helper.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* CodeIgniter Download Helpers
diff --git a/system/helpers/email_helper.php b/system/helpers/email_helper.php
index 2a63b36c9..dfb166a5a 100644
--- a/system/helpers/email_helper.php
+++ b/system/helpers/email_helper.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* CodeIgniter Email Helpers
@@ -42,7 +43,8 @@ if ( ! function_exists('valid_email'))
/**
* Validate email address
*
- * @param string
+ * @deprecated 3.0.0 Use PHP's filter_var() instead
+ * @param string $email
* @return bool
*/
function valid_email($email)
@@ -58,12 +60,13 @@ if ( ! function_exists('send_email'))
/**
* Send an email
*
- * @param string
- * @param string
- * @param string
+ * @deprecated 3.0.0 Use PHP's mail() instead
+ * @param string $recipient
+ * @param string $subject
+ * @param string $message
* @return bool
*/
- function send_email($recipient, $subject = 'Test email', $message = 'Hello World')
+ function send_email($recipient, $subject, $message)
{
return mail($recipient, $subject, $message);
}
diff --git a/system/helpers/file_helper.php b/system/helpers/file_helper.php
index 8f23a3d54..aebb6e47a 100644
--- a/system/helpers/file_helper.php
+++ b/system/helpers/file_helper.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* CodeIgniter File Helpers
@@ -65,12 +66,12 @@ if ( ! function_exists('write_file'))
* Writes data to the file specified in the path.
* Creates a new file if non-existent.
*
- * @param string path to file
- * @param string file data
- * @param int
+ * @param string $path File path
+ * @param string $data Data to write
+ * @param string $mode fopen() mode (default: 'wb')
* @return bool
*/
- function write_file($path, $data, $mode = FOPEN_WRITE_CREATE_DESTRUCTIVE)
+ function write_file($path, $data, $mode = 'wb')
{
if ( ! $fp = @fopen($path, $mode))
{
@@ -98,13 +99,13 @@ if ( ! function_exists('delete_files'))
* If the second parameter is set to TRUE, any directories contained
* within the supplied base directory will be nuked as well.
*
- * @param string path to file
- * @param bool whether to delete any directories found in the path
- * @param int
- * @param bool whether to skip deleting .htaccess and index page files
+ * @param string $path File path
+ * @param bool $del_dir Whether to delete any directories found in the path
+ * @param bool $htdocs Whether to skip deleting .htaccess and index page files
+ * @param int $_level Current directory depth level (default: 0; internal use only)
* @return bool
*/
- function delete_files($path, $del_dir = FALSE, $level = 0, $htdocs = FALSE)
+ function delete_files($path, $del_dir = FALSE, $htdocs = FALSE, $_level = 0)
{
// Trim the trailing slash
$path = rtrim($path, '/\\');
@@ -120,7 +121,7 @@ if ( ! function_exists('delete_files'))
{
if (is_dir($path.DIRECTORY_SEPARATOR.$filename) && $filename[0] !== '.')
{
- delete_files($path.DIRECTORY_SEPARATOR.$filename, $del_dir, $level + 1, $htdocs);
+ delete_files($path.DIRECTORY_SEPARATOR.$filename, $del_dir, $htdocs, $_level + 1);
}
elseif ($htdocs !== TRUE OR ! preg_match('/^(\.htaccess|index\.(html|htm|php)|web\.config)$/i', $filename))
{
@@ -130,7 +131,7 @@ if ( ! function_exists('delete_files'))
}
@closedir($current_dir);
- if ($del_dir === TRUE && $level > 0)
+ if ($del_dir === TRUE && $_level > 0)
{
return @rmdir($path);
}
@@ -318,12 +319,12 @@ if ( ! function_exists('get_mime_by_extension'))
* Note: this is NOT an accurate way of determining file mime types, and is here strictly as a convenience
* It should NOT be trusted, and should certainly NOT be used for security
*
- * @param string path to file
- * @return mixed
+ * @param string $filename File name
+ * @return string
*/
- function get_mime_by_extension($file)
+ function get_mime_by_extension($filename)
{
- $extension = strtolower(substr(strrchr($file, '.'), 1));
+ $extension = strtolower(substr(strrchr($filename, '.'), 1));
static $mimes;
@@ -358,7 +359,7 @@ if ( ! function_exists('symbolic_permissions'))
* Takes a numeric value representing a file's permissions and returns
* standard symbolic notation representing that value
*
- * @param int
+ * @param int $perms Permissions
* @return string
*/
function symbolic_permissions($perms)
@@ -425,7 +426,7 @@ if ( ! function_exists('octal_permissions'))
* Takes a numeric value representing a file's permissions and returns
* a three character string representing the file's octal permissions
*
- * @param int
+ * @param int $perms Permissions
* @return string
*/
function octal_permissions($perms)
diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php
index 622622c0e..e7bea92cc 100644
--- a/system/helpers/form_helper.php
+++ b/system/helpers/form_helper.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -22,7 +22,9 @@
* @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* @link http://codeigniter.com
* @since Version 1.0
+ * @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* CodeIgniter Form Helpers
@@ -124,9 +126,9 @@ if ( ! function_exists('form_hidden'))
* Generates hidden fields. You can pass a simple key/value string or
* an associative array with multiple values.
*
- * @param mixed
- * @param string
- * @param bool
+ * @param mixed $name Field name
+ * @param string $value Field value
+ * @param bool $recursing
* @return string
*/
function form_hidden($name, $value = '', $recursing = FALSE)
@@ -149,7 +151,7 @@ if ( ! function_exists('form_hidden'))
if ( ! is_array($value))
{
- $form .= '<input type="hidden" name="'.$name.'" value="'.html_escape($value)."\" />\n";
+ $form .= '<input type="hidden" name="'.$name.'" value="'.form_prep($value)."\" />\n";
}
else
{
@@ -243,9 +245,9 @@ if ( ! function_exists('form_textarea'))
/**
* Textarea field
*
- * @param mixed
- * @param string
- * @param string
+ * @param mixed $data
+ * @param string $value
+ * @param string $extra
* @return string
*/
function form_textarea($data = '', $value = '', $extra = '')
@@ -263,7 +265,7 @@ if ( ! function_exists('form_textarea'))
}
$name = is_array($data) ? $data['name'] : $data;
- return '<textarea '._parse_form_attributes($data, $defaults).$extra.'>'.html_escape($val)."</textarea>\n";
+ return '<textarea '._parse_form_attributes($data, $defaults).$extra.'>'.form_prep($val, TRUE)."</textarea>\n";
}
}
@@ -298,10 +300,10 @@ if ( ! function_exists('form_dropdown'))
/**
* Drop-down Menu
*
- * @param mixed $name = ''
- * @param mixed $options = array()
- * @param mixed $selected = array()
- * @param mixed $extra = array()
+ * @param mixed $name
+ * @param mixed $options
+ * @param mixed $selected
+ * @param mixed $extra
* @return string
*/
function form_dropdown($name = '', $options = array(), $selected = array(), $extra = '')
@@ -349,7 +351,7 @@ if ( ! function_exists('form_dropdown'))
foreach ($val as $optgroup_key => $optgroup_val)
{
$sel = in_array($optgroup_key, $selected) ? ' selected="selected"' : '';
- $form .= '<option value="'.html_escape($optgroup_key).'"'.$sel.'>'
+ $form .= '<option value="'.form_prep($optgroup_key).'"'.$sel.'>'
.(string) $optgroup_val."</option>\n";
}
@@ -357,7 +359,7 @@ if ( ! function_exists('form_dropdown'))
}
else
{
- $form .= '<option value="'.html_escape($key).'"'
+ $form .= '<option value="'.form_prep($key).'"'
.(in_array($key, $selected) ? ' selected="selected"' : '').'>'
.(string) $val."</option>\n";
}
@@ -600,17 +602,28 @@ if ( ! function_exists('form_prep'))
*
* Formats text so that it can be safely placed in a form field in the event it has HTML tags.
*
- * @todo Remove in version 3.1+.
- * @deprecated 3.0.0 This function has been broken for a long time
- * and is now just an alias for html_escape(). It's
- * second argument is ignored.
- * @param string $str = ''
- * @param string $field_name = ''
- * @return string
+ * @param string|string[] $str Value to escape
+ * @param bool $is_textarea Whether we're escaping for a textarea element
+ * @return string|string[] Escaped values
*/
- function form_prep($str = '', $field_name = '')
+ function form_prep($str = '', $is_textarea = FALSE)
{
- return html_escape($str);
+ if (is_array($str))
+ {
+ foreach (array_keys($str) as $key)
+ {
+ $str[$key] = form_prep($str[$key], $is_textarea);
+ }
+
+ return $str;
+ }
+
+ if ($is_textarea === TRUE)
+ {
+ return str_replace(array('<', '>'), array('&lt;', '&gt;'), stripslashes($str));
+ }
+
+ return str_replace(array("'", '"'), array('&#39;', '&quot;'), stripslashes($str));
}
}
@@ -625,23 +638,21 @@ if ( ! function_exists('set_value'))
* re-populate an input field or textarea. If Form Validation
* is active it retrieves the info from the validation class
*
- * @param string
- * @param string
- * @return mixed
+ * @param string $field Field name
+ * @param string $default Default value
+ * @param bool $is_textarea Whether the field is a textarea element
+ * @return string
*/
- function set_value($field = '', $default = '')
+ function set_value($field = '', $default = '', $is_textarea = FALSE)
{
if (FALSE === ($OBJ =& _get_validation_object()))
{
- if ( ! isset($_POST[$field]))
- {
- return html_escape($default);
- }
-
- return html_escape($_POST[$field]);
+ return isset($_POST[$field])
+ ? form_prep($_POST[$field], $is_textarea)
+ : form_prep($default, $is_textarea);
}
- return html_escape($OBJ->set_value($field, $default));
+ return form_prep($OBJ->set_value($field, $default), $is_textarea);
}
}
@@ -862,8 +873,8 @@ if ( ! function_exists('_parse_form_attributes'))
*
* Helper function used by some of the form helpers
*
- * @param array
- * @param array
+ * @param array $attributes List of attributes
+ * @param array $default Default values
* @return string
*/
function _parse_form_attributes($attributes, $default)
@@ -891,7 +902,7 @@ if ( ! function_exists('_parse_form_attributes'))
{
if ($key === 'value')
{
- $val = html_escape($val);
+ $val = form_prep($val);
}
elseif ($key === 'name' && ! strlen($default['name']))
{
diff --git a/system/helpers/html_helper.php b/system/helpers/html_helper.php
index 2372e8174..fa49f7d75 100644
--- a/system/helpers/html_helper.php
+++ b/system/helpers/html_helper.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* CodeIgniter HTML Helpers
@@ -156,12 +157,12 @@ if ( ! function_exists('br'))
/**
* Generates HTML BR tags based on number supplied
*
- * @param int
+ * @param int $count Number of times to repeat the tag
* @return string
*/
- function br($num = 1)
+ function br($count = 1)
{
- return str_repeat('<br />', $num);
+ return str_repeat('<br />', $count);
}
}
diff --git a/system/helpers/inflector_helper.php b/system/helpers/inflector_helper.php
index 647d840e4..59cb296b2 100644
--- a/system/helpers/inflector_helper.php
+++ b/system/helpers/inflector_helper.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* CodeIgniter Inflector Helpers
@@ -44,7 +45,7 @@ if ( ! function_exists('singular'))
*
* Takes a plural word and makes it singular
*
- * @param string
+ * @param string $str Input string
* @return string
*/
function singular($str)
@@ -108,11 +109,10 @@ if ( ! function_exists('plural'))
*
* Takes a singular word and makes it plural
*
- * @param string
- * @param bool
+ * @param string $str Input string
* @return string
*/
- function plural($str, $force = FALSE)
+ function plural($str)
{
$result = strval($str);
@@ -165,7 +165,7 @@ if ( ! function_exists('camelize'))
*
* Takes multiple words separated by spaces or underscores and camelizes them
*
- * @param string
+ * @param string $str Input string
* @return string
*/
function camelize($str)
@@ -183,7 +183,7 @@ if ( ! function_exists('underscore'))
*
* Takes multiple words separated by spaces and underscores them
*
- * @param string
+ * @param string $str Input string
* @return string
*/
function underscore($str)
@@ -201,8 +201,8 @@ if ( ! function_exists('humanize'))
*
* Takes multiple words separated by the separator and changes them to spaces
*
- * @param string $str
- * @param string $separator
+ * @param string $str Input string
+ * @param string $separator Input separator
* @return string
*/
function humanize($str, $separator = '_')
@@ -218,12 +218,12 @@ if ( ! function_exists('is_countable'))
/**
* Checks if the given word has a plural version.
*
- * @param string the word to check
- * @return bool if the word is countable
+ * @param string $word Word to check
+ * @return bool
*/
function is_countable($word)
{
- return ! in_array(strtolower(strval($word)),
+ return ! in_array(strtolower($word),
array(
'equipment', 'information', 'rice', 'money',
'species', 'series', 'fish', 'meta'
diff --git a/system/helpers/language_helper.php b/system/helpers/language_helper.php
index bd567ed79..658be6de7 100644
--- a/system/helpers/language_helper.php
+++ b/system/helpers/language_helper.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* CodeIgniter Language Helpers
diff --git a/system/helpers/number_helper.php b/system/helpers/number_helper.php
index e49f2f7a0..b93096543 100644
--- a/system/helpers/number_helper.php
+++ b/system/helpers/number_helper.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* CodeIgniter Number Helpers
diff --git a/system/helpers/path_helper.php b/system/helpers/path_helper.php
index 166fef065..5a798b118 100644
--- a/system/helpers/path_helper.php
+++ b/system/helpers/path_helper.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* CodeIgniter Path Helpers
diff --git a/system/helpers/security_helper.php b/system/helpers/security_helper.php
index 8bbd06684..898a49c80 100644
--- a/system/helpers/security_helper.php
+++ b/system/helpers/security_helper.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* CodeIgniter Security Helpers
diff --git a/system/helpers/smiley_helper.php b/system/helpers/smiley_helper.php
index b6b2afcf4..4b491758e 100644
--- a/system/helpers/smiley_helper.php
+++ b/system/helpers/smiley_helper.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* CodeIgniter Smiley Helpers
@@ -130,10 +131,9 @@ if ( ! function_exists('get_clickable_smileys'))
*
* @param string the URL to the folder containing the smiley images
* @param array
- * @param array
* @return array
*/
- function get_clickable_smileys($image_url, $alias = '', $smileys = NULL)
+ function get_clickable_smileys($image_url, $alias = '')
{
// For backward compatibility with js_insert_smiley
if (is_array($alias))
@@ -142,7 +142,7 @@ if ( ! function_exists('get_clickable_smileys'))
}
elseif (FALSE === ($smileys = _get_smiley_array()))
{
- return $smileys;
+ return FALSE;
}
// Add a trailing slash to the file path if needed
diff --git a/system/helpers/string_helper.php b/system/helpers/string_helper.php
index c5c493452..9fc24559a 100644
--- a/system/helpers/string_helper.php
+++ b/system/helpers/string_helper.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* CodeIgniter String Helpers
@@ -50,6 +51,9 @@ if ( ! function_exists('trim_slashes'))
*
* this/that/theother
*
+ * @todo Remove in version 3.1+.
+ * @deprecated 3.0.0 This is just an alias for PHP's native trim()
+ *
* @param string
* @return string
*/
@@ -214,10 +218,10 @@ if ( ! function_exists('random_string'))
break;
}
return substr(str_shuffle(str_repeat($pool, ceil($len / strlen($pool)))), 0, $len);
- case 'unique':
+ case 'unique': // todo: remove in 3.1+
case 'md5':
return md5(uniqid(mt_rand()));
- case 'encrypt':
+ case 'encrypt': // todo: remove in 3.1+
case 'sha1':
return sha1(uniqid(mt_rand(), TRUE));
}
diff --git a/system/helpers/text_helper.php b/system/helpers/text_helper.php
index 89602fc28..cce659231 100644
--- a/system/helpers/text_helper.php
+++ b/system/helpers/text_helper.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* CodeIgniter Text Helpers
diff --git a/system/helpers/typography_helper.php b/system/helpers/typography_helper.php
index 96bedd026..48f1f1147 100644
--- a/system/helpers/typography_helper.php
+++ b/system/helpers/typography_helper.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* CodeIgniter Typography Helpers
diff --git a/system/helpers/url_helper.php b/system/helpers/url_helper.php
index dc77246dc..0aa358a0b 100644
--- a/system/helpers/url_helper.php
+++ b/system/helpers/url_helper.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* CodeIgniter URL Helpers
@@ -473,9 +474,11 @@ if ( ! function_exists('url_title'))
* human-friendly URL string with a "separator" string
* as the word separator.
*
- * @param string the string
- * @param string the separator
- * @param bool
+ * @todo Remove old 'dash' and 'underscore' usage in 3.1+.
+ * @param string $str Input string
+ * @param string $separator Word separator
+ * (usually '-' or '_')
+ * @param bool $lowercase Wether to transform the output string to lowercase
* @return string
*/
function url_title($str, $separator = '-', $lowercase = FALSE)
@@ -524,10 +527,11 @@ if ( ! function_exists('redirect'))
* For very fine grained control over headers, you could use the Output
* Library's set_header() function.
*
- * @param string the URL
- * @param string the method: location or refresh
- * @param int
- * @return string
+ * @param string $uri URL
+ * @param string $method Redirect method
+ * 'auto', 'location' or 'refresh'
+ * @param int $code HTTP Response status code
+ * @return void
*/
function redirect($uri = '', $method = 'auto', $code = NULL)
{
diff --git a/system/helpers/xml_helper.php b/system/helpers/xml_helper.php
index 1431777d2..c3dfdcddb 100644
--- a/system/helpers/xml_helper.php
+++ b/system/helpers/xml_helper.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* CodeIgniter XML Helpers
diff --git a/system/language/english/calendar_lang.php b/system/language/english/calendar_lang.php
index a70a564e8..288eb91d8 100644
--- a/system/language/english/calendar_lang.php
+++ b/system/language/english/calendar_lang.php
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
$lang['cal_su'] = 'Su';
$lang['cal_mo'] = 'Mo';
diff --git a/system/language/english/date_lang.php b/system/language/english/date_lang.php
index 6683e4c69..db1e9e0ff 100644
--- a/system/language/english/date_lang.php
+++ b/system/language/english/date_lang.php
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
$lang['date_year'] = 'Year';
$lang['date_years'] = 'Years';
diff --git a/system/language/english/db_lang.php b/system/language/english/db_lang.php
index 479cbb167..50ce6bbd6 100644
--- a/system/language/english/db_lang.php
+++ b/system/language/english/db_lang.php
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
$lang['db_invalid_connection_str'] = 'Unable to determine the database settings based on the connection string you submitted.';
$lang['db_unable_to_connect'] = 'Unable to connect to your database server using the provided settings.';
@@ -40,8 +41,8 @@ $lang['db_field_param_missing'] = 'To fetch fields requires the name of the tabl
$lang['db_unsupported_function'] = 'This feature is not available for the database you are using.';
$lang['db_transaction_failure'] = 'Transaction failure: Rollback performed.';
$lang['db_unable_to_drop'] = 'Unable to drop the specified database.';
-$lang['db_unsuported_feature'] = 'Unsupported feature of the database platform you are using.';
-$lang['db_unsuported_compression'] = 'The file compression format you chose is not supported by your server.';
+$lang['db_unsupported_feature'] = 'Unsupported feature of the database platform you are using.';
+$lang['db_unsupported_compression'] = 'The file compression format you chose is not supported by your server.';
$lang['db_filepath_error'] = 'Unable to write data to the file path you have submitted.';
$lang['db_invalid_cache_path'] = 'The cache path you submitted is not valid or writable.';
$lang['db_table_name_required'] = 'A table name is required for that operation.';
diff --git a/system/language/english/email_lang.php b/system/language/english/email_lang.php
index 0de9aa27e..646a49647 100644
--- a/system/language/english/email_lang.php
+++ b/system/language/english/email_lang.php
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
$lang['email_must_be_array'] = 'The email validation method must be passed an array.';
$lang['email_invalid_address'] = 'Invalid email address: %s';
diff --git a/system/language/english/form_validation_lang.php b/system/language/english/form_validation_lang.php
index 6ff0cc2f4..52ca21f92 100644
--- a/system/language/english/form_validation_lang.php
+++ b/system/language/english/form_validation_lang.php
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
$lang['required'] = 'The %s field is required.';
$lang['isset'] = 'The %s field must have a value.';
diff --git a/system/language/english/ftp_lang.php b/system/language/english/ftp_lang.php
index 24923c8d8..090a88c28 100644
--- a/system/language/english/ftp_lang.php
+++ b/system/language/english/ftp_lang.php
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
$lang['ftp_no_connection'] = 'Unable to locate a valid connection ID. Please make sure you are connected before peforming any file routines.';
$lang['ftp_unable_to_connect'] = 'Unable to connect to your FTP server using the supplied hostname.';
diff --git a/system/language/english/imglib_lang.php b/system/language/english/imglib_lang.php
index d755437f2..296c4af68 100644
--- a/system/language/english/imglib_lang.php
+++ b/system/language/english/imglib_lang.php
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
$lang['imglib_source_image_required'] = 'You must specify a source image in your preferences.';
$lang['imglib_gd_required'] = 'The GD image library is required for this feature.';
diff --git a/system/language/english/migration_lang.php b/system/language/english/migration_lang.php
index a262d3018..689a72952 100644
--- a/system/language/english/migration_lang.php
+++ b/system/language/english/migration_lang.php
@@ -24,6 +24,7 @@
* @since Version 3.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
$lang['migration_none_found'] = 'No migrations were found.';
$lang['migration_not_found'] = 'No migration could be found with the version number: %d.';
@@ -34,6 +35,5 @@ $lang['migration_missing_up_method'] = 'The migration class "%s" is missing an "
$lang['migration_missing_down_method'] = 'The migration class "%s" is missing a "down" method.';
$lang['migration_invalid_filename'] = 'Migration "%s" has an invalid filename.';
-
/* End of file migration_lang.php */
/* Location: ./system/language/english/migration_lang.php */ \ No newline at end of file
diff --git a/system/language/english/number_lang.php b/system/language/english/number_lang.php
index 429c64738..019013a49 100644
--- a/system/language/english/number_lang.php
+++ b/system/language/english/number_lang.php
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
$lang['terabyte_abbr'] = 'TB';
$lang['gigabyte_abbr'] = 'GB';
diff --git a/system/language/english/profiler_lang.php b/system/language/english/profiler_lang.php
index 112527faa..6ffcd9349 100644
--- a/system/language/english/profiler_lang.php
+++ b/system/language/english/profiler_lang.php
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
$lang['profiler_database'] = 'DATABASE';
$lang['profiler_controller_info'] = 'CLASS/METHOD';
diff --git a/system/language/english/unit_test_lang.php b/system/language/english/unit_test_lang.php
index 146ec25b4..ed452615f 100644
--- a/system/language/english/unit_test_lang.php
+++ b/system/language/english/unit_test_lang.php
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
$lang['ut_test_name'] = 'Test Name';
$lang['ut_test_datatype'] = 'Test Datatype';
diff --git a/system/language/english/upload_lang.php b/system/language/english/upload_lang.php
index d70e7f20f..88f9ac372 100644
--- a/system/language/english/upload_lang.php
+++ b/system/language/english/upload_lang.php
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
$lang['upload_userfile_not_set'] = 'Unable to find a post variable called userfile.';
$lang['upload_file_exceeds_limit'] = 'The uploaded file exceeds the maximum allowed size in your PHP configuration file.';
diff --git a/system/libraries/Cache/Cache.php b/system/libraries/Cache/Cache.php
index 7ec2380a5..e76fdc557 100644
--- a/system/libraries/Cache/Cache.php
+++ b/system/libraries/Cache/Cache.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -18,12 +18,13 @@
*
* @package CodeIgniter
* @author EllisLab Dev Team
- * @copyright Copyright (c) 2006 - 2012 EllisLab, Inc.
+ * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
* @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* @link http://codeigniter.com
* @since Version 2.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* CodeIgniter Caching Class
diff --git a/system/libraries/Cache/drivers/Cache_apc.php b/system/libraries/Cache/drivers/Cache_apc.php
index c85034f95..46e633463 100644
--- a/system/libraries/Cache/drivers/Cache_apc.php
+++ b/system/libraries/Cache/drivers/Cache_apc.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -18,12 +18,13 @@
*
* @package CodeIgniter
* @author EllisLab Dev Team
- * @copyright Copyright (c) 2006 - 2012 EllisLab, Inc.
+ * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
* @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* @link http://codeigniter.com
* @since Version 2.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* CodeIgniter APC Caching Class
diff --git a/system/libraries/Cache/drivers/Cache_dummy.php b/system/libraries/Cache/drivers/Cache_dummy.php
index 3f2b4b956..a3bdc3c80 100644
--- a/system/libraries/Cache/drivers/Cache_dummy.php
+++ b/system/libraries/Cache/drivers/Cache_dummy.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -18,12 +18,13 @@
*
* @package CodeIgniter
* @author EllisLab Dev Team
- * @copyright Copyright (c) 2006 - 2012 EllisLab, Inc.
+ * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
* @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* @link http://codeigniter.com
* @since Version 2.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* CodeIgniter Dummy Caching Class
diff --git a/system/libraries/Cache/drivers/Cache_file.php b/system/libraries/Cache/drivers/Cache_file.php
index 37d77c268..5d370380e 100644
--- a/system/libraries/Cache/drivers/Cache_file.php
+++ b/system/libraries/Cache/drivers/Cache_file.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -18,12 +18,13 @@
*
* @package CodeIgniter
* @author EllisLab Dev Team
- * @copyright Copyright (c) 2006 - 2012 EllisLab, Inc.
+ * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
* @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* @link http://codeigniter.com
* @since Version 2.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* CodeIgniter File Caching Class
diff --git a/system/libraries/Cache/drivers/Cache_memcached.php b/system/libraries/Cache/drivers/Cache_memcached.php
index bf90f6197..fae002347 100644
--- a/system/libraries/Cache/drivers/Cache_memcached.php
+++ b/system/libraries/Cache/drivers/Cache_memcached.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -18,12 +18,13 @@
*
* @package CodeIgniter
* @author EllisLab Dev Team
- * @copyright Copyright (c) 2006 - 2012 EllisLab, Inc.
+ * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
* @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* @link http://codeigniter.com
* @since Version 2.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* CodeIgniter Memcached Caching Class
diff --git a/system/libraries/Cache/drivers/Cache_redis.php b/system/libraries/Cache/drivers/Cache_redis.php
index e4a26b5f0..60033344b 100644
--- a/system/libraries/Cache/drivers/Cache_redis.php
+++ b/system/libraries/Cache/drivers/Cache_redis.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -18,12 +18,13 @@
*
* @package CodeIgniter
* @author EllisLab Dev Team
- * @copyright Copyright (c) 2006 - 2012 EllisLab, Inc.
+ * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
* @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* @link http://codeigniter.com
* @since Version 3.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* CodeIgniter Redis Caching Class
diff --git a/system/libraries/Cache/drivers/Cache_wincache.php b/system/libraries/Cache/drivers/Cache_wincache.php
index 89e9f77c8..383b3afdd 100644
--- a/system/libraries/Cache/drivers/Cache_wincache.php
+++ b/system/libraries/Cache/drivers/Cache_wincache.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -18,12 +18,13 @@
*
* @package CodeIgniter
* @author EllisLab Dev Team
- * @copyright Copyright (c) 2006 - 2012 EllisLab, Inc.
+ * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
* @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* @link http://codeigniter.com
* @since Version 3.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* CodeIgniter Wincache Caching Class
diff --git a/system/libraries/Calendar.php b/system/libraries/Calendar.php
index 95f537e42..caa496a5e 100644
--- a/system/libraries/Calendar.php
+++ b/system/libraries/Calendar.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* CodeIgniter Calendar Class
diff --git a/system/libraries/Cart.php b/system/libraries/Cart.php
index d4b17fa36..035a6a42b 100644
--- a/system/libraries/Cart.php
+++ b/system/libraries/Cart.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Shopping Cart Class
@@ -193,7 +194,7 @@ class CI_Cart {
$items['qty'] = (float) $items['qty'];
// If the quantity is zero or blank there's nothing for us to do
- if ( ! is_numeric($items['qty']) OR $items['qty'] == 0)
+ if ($items['qty'] == 0)
{
return FALSE;
}
@@ -224,15 +225,6 @@ class CI_Cart {
// Prep the price. Remove leading zeros and anything that isn't a number or decimal point.
$items['price'] = (float) $items['price'];
- // Is the price a valid number?
- if ( ! is_numeric($items['price']))
- {
- log_message('error', 'An invalid price was submitted for product ID: '.$items['id']);
- return FALSE;
- }
-
- // --------------------------------------------------------------------
-
// We now need to create a unique identifier for the item being inserted into the cart.
// Every time something is added to the cart it is stored in the master cart array.
// Each row in the cart array, however, must have a unique index that identifies not only
@@ -350,12 +342,6 @@ class CI_Cart {
// Prep the quantity
$items['qty'] = (float) $items['qty'];
- // Is the quantity a number?
- if ( ! is_numeric($items['qty']))
- {
- return FALSE;
- }
-
// Is the quantity zero? If so we will remove the item from the cart.
// If the quantity is greater than zero we are updating
if ($items['qty'] == 0)
diff --git a/system/libraries/Driver.php b/system/libraries/Driver.php
index 5d642b982..621d22631 100644
--- a/system/libraries/Driver.php
+++ b/system/libraries/Driver.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* CodeIgniter Driver Library Class
diff --git a/system/libraries/Email.php b/system/libraries/Email.php
index 7280466a5..d23be1af1 100644
--- a/system/libraries/Email.php
+++ b/system/libraries/Email.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* CodeIgniter Email Class
@@ -38,55 +39,340 @@
*/
class CI_Email {
+ /**
+ * Used as the User-Agent and X-Mailer headers' value.
+ *
+ * @var string
+ */
public $useragent = 'CodeIgniter';
+
+ /**
+ * Path to the Sendmail binary.
+ *
+ * @var string
+ */
public $mailpath = '/usr/sbin/sendmail'; // Sendmail path
+
+ /**
+ * Which method to use for sending e-mails.
+ *
+ * @var string 'mail', 'sendmail' or 'smtp'
+ */
public $protocol = 'mail'; // mail/sendmail/smtp
- public $smtp_host = ''; // SMTP Server. Example: mail.earthlink.net
- public $smtp_user = ''; // SMTP Username
- public $smtp_pass = ''; // SMTP Password
- public $smtp_port = 25; // SMTP Port
- public $smtp_timeout = 5; // SMTP Timeout in seconds
- public $smtp_crypto = ''; // SMTP Encryption. Can be null, tls or ssl.
- public $wordwrap = TRUE; // TRUE/FALSE - Turns word-wrap on/off
- public $wrapchars = 76; // Number of characters to wrap at.
- public $mailtype = 'text'; // text/html - Defines email formatting
- public $charset = 'utf-8'; // Default char set: iso-8859-1 or us-ascii
+
+ /**
+ * STMP Server host
+ *
+ * @var string
+ */
+ public $smtp_host = '';
+
+ /**
+ * SMTP Username
+ *
+ * @var string
+ */
+ public $smtp_user = '';
+
+ /**
+ * SMTP Password
+ *
+ * @var string
+ */
+ public $smtp_pass = '';
+
+ /**
+ * SMTP Server port
+ *
+ * @var int
+ */
+ public $smtp_port = 25;
+
+ /**
+ * SMTP connection timeout in seconds
+ *
+ * @var int
+ */
+ public $smtp_timeout = 5;
+
+ /**
+ * SMTP Encryption
+ *
+ * @var string NULL, 'tls' or 'ssl'
+ */
+ public $smtp_crypto = NULL;
+
+ /**
+ * Whether to apply word-wrapping to the message body.
+ *
+ * @var bool
+ */
+ public $wordwrap = TRUE;
+
+ /**
+ * Number of characters to wrap at.
+ *
+ * @see CI_Email::$wordwrap
+ * @var int
+ */
+ public $wrapchars = 76;
+
+ /**
+ * Message format.
+ *
+ * @var string 'text' or 'html'
+ */
+ public $mailtype = 'text';
+
+ /**
+ * Character set (default: utf-8)
+ *
+ * @var string
+ */
+ public $charset = 'utf-8';
+
+ /**
+ * Multipart message
+ *
+ * @var string 'mixed' (in the body) or 'related' (separate)
+ */
public $multipart = 'mixed'; // "mixed" (in the body) or "related" (separate)
- public $alt_message = ''; // Alternative message for HTML emails
- public $validate = FALSE; // TRUE/FALSE - Enables email validation
+
+ /**
+ * Alternative message (for HTML messages only)
+ *
+ * @var string
+ */
+ public $alt_message = '';
+
+ /**
+ * Whether to validate e-mail addresses.
+ *
+ * @var bool
+ */
+ public $validate = FALSE;
+
+ /**
+ * X-Priority header value.
+ *
+ * @var int 1-5
+ */
public $priority = 3; // Default priority (1 - 5)
+
+ /**
+ * Newline character sequence.
+ * Use "\r\n" to comply with RFC 822.
+ *
+ * @link http://www.ietf.org/rfc/rfc822.txt
+ * @var string "\r\n" or "\n"
+ */
public $newline = "\n"; // Default newline. "\r\n" or "\n" (Use "\r\n" to comply with RFC 822)
- public $crlf = "\n"; // The RFC 2045 compliant CRLF for quoted-printable is "\r\n". Apparently some servers,
- // even on the receiving end think they need to muck with CRLFs, so using "\n", while
- // distasteful, is the only thing that seems to work for all environments.
- public $dsn = FALSE; // Delivery Status Notification
- public $send_multipart = TRUE; // TRUE/FALSE - Yahoo does not like multipart alternative, so this is an override. Set to FALSE for Yahoo.
- public $bcc_batch_mode = FALSE; // TRUE/FALSE - Turns on/off Bcc batch feature
- public $bcc_batch_size = 200; // If bcc_batch_mode = TRUE, sets max number of Bccs in each batch
+ /**
+ * CRLF character sequence
+ *
+ * RFC 2045 specifies that for 'quoted-printable' encoding,
+ * "\r\n" must be used. However, it appears that some servers
+ * (even on the receiving end) don't handle it properly and
+ * switching to "\n", while improper, is the only solution
+ * that seems to work for all environments.
+ *
+ * @link http://www.ietf.org/rfc/rfc822.txt
+ * @var string
+ */
+ public $crlf = "\n";
+
+ /**
+ * Whether to use Delivery Status Notification.
+ *
+ * @var bool
+ */
+ public $dsn = FALSE;
+
+ /**
+ * Whether to send multipart alternatives.
+ * Yahoo! doesn't seem to like these.
+ *
+ * @var bool
+ */
+ public $send_multipart = TRUE;
+
+ /**
+ * Whether to send messages to BCC recipients in batches.
+ *
+ * @var bool
+ */
+ public $bcc_batch_mode = FALSE;
+
+ /**
+ * BCC Batch max number size.
+ *
+ * @see CI_Email::$bcc_batch_mode
+ * @var int
+ */
+ public $bcc_batch_size = 200;
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Whether PHP is running in safe mode. Initialized by the class constructor.
+ *
+ * @var bool
+ */
protected $_safe_mode = FALSE;
+
+ /**
+ * Subject header
+ *
+ * @var string
+ */
protected $_subject = '';
+
+ /**
+ * Message body
+ *
+ * @var string
+ */
protected $_body = '';
+
+ /**
+ * Final message body to be sent.
+ *
+ * @var string
+ */
protected $_finalbody = '';
+
+ /**
+ * multipart/alternative boundary
+ *
+ * @var string
+ */
protected $_alt_boundary = '';
+
+ /**
+ * Attachment boundary
+ *
+ * @var string
+ */
protected $_atc_boundary = '';
+
+ /**
+ * Final headers to send
+ *
+ * @var string
+ */
protected $_header_str = '';
+
+ /**
+ * SMTP Connection socket placeholder
+ *
+ * @var resource
+ */
protected $_smtp_connect = '';
+
+ /**
+ * Mail encoding
+ *
+ * @var string '8bit' or '7bit'
+ */
protected $_encoding = '8bit';
- protected $_IP = FALSE;
+
+ /**
+ * Whether to perform SMTP authentication
+ *
+ * @var bool
+ */
protected $_smtp_auth = FALSE;
+
+ /**
+ * Whether to send a Reply-To header
+ *
+ * @var bool
+ */
protected $_replyto_flag = FALSE;
+
+ /**
+ * Debug messages
+ *
+ * @see CI_Email::print_debugger()
+ * @var string
+ */
protected $_debug_msg = array();
+
+ /**
+ * Recipients
+ *
+ * @var string[]
+ */
protected $_recipients = array();
+
+ /**
+ * CC Recipients
+ *
+ * @var string[]
+ */
protected $_cc_array = array();
+
+ /**
+ * BCC Recipients
+ *
+ * @var string[]
+ */
protected $_bcc_array = array();
+
+ /**
+ * Message headers
+ *
+ * @var string[]
+ */
protected $_headers = array();
+
+ /**
+ * Attachment data
+ *
+ * @var array
+ */
protected $_attachments = array();
+
+ /**
+ * Valid $protocol values
+ *
+ * @see CI_Email::$protocol
+ * @var string[]
+ */
protected $_protocols = array('mail', 'sendmail', 'smtp');
- protected $_base_charsets = array('us-ascii', 'iso-2022-'); // 7-bit charsets (excluding language suffix)
+
+ /**
+ * Base charsets
+ *
+ * Character sets valid for 7-bit encoding,
+ * excluding language suffix.
+ *
+ * @var string[]
+ */
+ protected $_base_charsets = array('us-ascii', 'iso-2022-');
+
+ /**
+ * Bit depths
+ *
+ * Valid mail encodings
+ *
+ * @see CI_Email::$_encoding
+ * @var string[]
+ */
protected $_bit_depths = array('7bit', '8bit');
+
+ /**
+ * $priority translations
+ *
+ * Actual values to send with the X-Priority header
+ *
+ * @var string[]
+ */
protected $_priorities = array('1 (Highest)', '2 (High)', '3 (Normal)', '4 (Low)', '5 (Lowest)');
+ // --------------------------------------------------------------------
+
/**
* Constructor - Sets Email Preferences
*
@@ -771,7 +1057,7 @@ class CI_Email {
}
// Reduce multiple spaces
- $str = preg_replace('| +|', ' ', $str);
+ $body = preg_replace('| +|', ' ', $body);
return ($this->wordwrap)
? $this->word_wrap($body, 76)
@@ -1446,11 +1732,14 @@ class CI_Email {
*/
protected function _send_with_sendmail()
{
- $fp = @popen($this->mailpath.' -oi -f '.$this->clean_email($this->_headers['From']).' -t'.' -r '.$this->clean_email($this->_headers['Return-Path']), 'w');
-
- if ($fp === FALSE OR $fp === NULL)
+ // is popen() enabled?
+ if ( ! function_usable('popen')
+ OR FALSE === ($fp = @popen(
+ $this->mailpath.' -oi -f '.$this->clean_email($this->_headers['From'])
+ .' -t -r '.$this->clean_email($this->_headers['Return-Path'])
+ , 'w'))
+ ) // server probably has popen disabled, so nothing we can do to get a verbose error.
{
- // server probably has popen disabled, so nothing we can do to get a verbose error.
return FALSE;
}
diff --git a/system/libraries/Encrypt.php b/system/libraries/Encrypt.php
index 73ab8ca7d..cdb0a6452 100644
--- a/system/libraries/Encrypt.php
+++ b/system/libraries/Encrypt.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* CodeIgniter Encryption Class
diff --git a/system/libraries/Form_validation.php b/system/libraries/Form_validation.php
index c1bf51935..e50eee4f2 100644
--- a/system/libraries/Form_validation.php
+++ b/system/libraries/Form_validation.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Form Validation Class
@@ -439,11 +440,10 @@ class CI_Form_validation {
// Load the language file containing error messages
$this->CI->lang->load('form_validation');
- // Cycle through the rules for each field, match the
- // corresponding $_POST item and test for errors
+ // Cycle through the rules for each field and match the corresponding $validation_data item
foreach ($this->_field_data as $field => $row)
{
- // Fetch the data from the corresponding $_POST or validation array and cache it in the _field_data array.
+ // Fetch the data from the validation_data array item and cache it in the _field_data array.
// Depending on whether the field name is an array or a string will determine where we get it from.
if ($row['is_array'] === TRUE)
{
@@ -453,7 +453,13 @@ class CI_Form_validation {
{
$this->_field_data[$field]['postdata'] = $validation_array[$field];
}
+ }
+ // Execute validation rules
+ // Note: A second foreach (for now) is required in order to avoid false-positives
+ // for rules like 'matches', which correlate to other validation fields.
+ foreach ($this->_field_data as $field => $row)
+ {
// Don't try to validate if we have no rules set
if (empty($row['rules']))
{
@@ -1323,6 +1329,11 @@ class CI_Form_validation {
*/
public function prep_for_form($data = '')
{
+ if ($this->_safe_form_data === FALSE OR empty($data))
+ {
+ return $data;
+ }
+
if (is_array($data))
{
foreach ($data as $key => $val)
@@ -1333,11 +1344,6 @@ class CI_Form_validation {
return $data;
}
- if ($this->_safe_form_data === FALSE OR $data === '')
- {
- return $data;
- }
-
return str_replace(array("'", '"', '<', '>'), array('&#39;', '&quot;', '&lt;', '&gt;'), stripslashes($data));
}
diff --git a/system/libraries/Ftp.php b/system/libraries/Ftp.php
index ae85fdf37..60c03b5ad 100644
--- a/system/libraries/Ftp.php
+++ b/system/libraries/Ftp.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* FTP Class
@@ -36,18 +37,63 @@
*/
class CI_FTP {
+ /**
+ * FTP Server hostname
+ *
+ * @var string
+ */
public $hostname = '';
+
+ /**
+ * FTP Username
+ *
+ * @var string
+ */
public $username = '';
+
+ /**
+ * FTP Password
+ *
+ * @var string
+ */
public $password = '';
+
+ /**
+ * FTP Server port
+ *
+ * @var int
+ */
public $port = 21;
+
+ /**
+ * Passive mode flag
+ *
+ * @var bool
+ */
public $passive = TRUE;
+
+ /**
+ * Debug flag
+ *
+ * Specifies whether to display error messages.
+ *
+ * @var bool
+ */
public $debug = FALSE;
+
+ /**
+ * Connection
+ *
+ * @var resource
+ */
public $conn_id = FALSE;
+ // --------------------------------------------------------------------
+
/**
* Constructor
*
- * @param array $config = array()
+ * @param array $config
* @return void
*/
public function __construct($config = array())
@@ -65,7 +111,7 @@ class CI_FTP {
/**
* Initialize preferences
*
- * @param array
+ * @param array $config
* @return void
*/
public function initialize($config = array())
@@ -87,7 +133,7 @@ class CI_FTP {
/**
* FTP Connect
*
- * @param array the connection values
+ * @param array $config Connection values
* @return bool
*/
public function connect($config = array())
@@ -167,8 +213,8 @@ class CI_FTP {
* so we do it by trying to change to a particular directory.
* Internally, this parameter is only used by the "mirror" function below.
*
- * @param string
- * @param bool
+ * @param string $path
+ * @param bool $supress_debug
* @return bool
*/
public function changedir($path = '', $supress_debug = FALSE)
@@ -197,8 +243,8 @@ class CI_FTP {
/**
* Create a directory
*
- * @param string
- * @param int
+ * @param string $path
+ * @param int $permissions
* @return bool
*/
public function mkdir($path = '', $permissions = NULL)
@@ -233,10 +279,10 @@ class CI_FTP {
/**
* Upload a file to the server
*
- * @param string
- * @param string
- * @param string
- * @param int
+ * @param string $locpath
+ * @param string $rempath
+ * @param string $mode
+ * @param int $permissions
* @return bool
*/
public function upload($locpath, $rempath, $mode = 'auto', $permissions = NULL)
@@ -287,9 +333,9 @@ class CI_FTP {
/**
* Download a file from a remote server to the local server
*
- * @param string
- * @param string
- * @param string
+ * @param string $rempath
+ * @param string $locpath
+ * @param string $mode
* @return bool
*/
public function download($rempath, $locpath, $mode = 'auto')
@@ -328,9 +374,9 @@ class CI_FTP {
/**
* Rename (or move) a file
*
- * @param string
- * @param string
- * @param bool
+ * @param string $old_file
+ * @param string $new_file
+ * @param bool $move
* @return bool
*/
public function rename($old_file, $new_file, $move = FALSE)
@@ -359,8 +405,8 @@ class CI_FTP {
/**
* Move a file
*
- * @param string
- * @param string
+ * @param string $old_file
+ * @param string $new_file
* @return bool
*/
public function move($old_file, $new_file)
@@ -373,7 +419,7 @@ class CI_FTP {
/**
* Rename (or move) a file
*
- * @param string
+ * @param string $filepath
* @return bool
*/
public function delete_file($filepath)
@@ -403,7 +449,7 @@ class CI_FTP {
* Delete a folder and recursively delete everything (including sub-folders)
* containted within it.
*
- * @param string
+ * @param string $filepath
* @return bool
*/
public function delete_dir($filepath)
@@ -450,8 +496,8 @@ class CI_FTP {
/**
* Set file permissions
*
- * @param string the file path
- * @param int the permissions
+ * @param string $path File path
+ * @param int $perm Permissions
* @return bool
*/
public function chmod($path, $perm)
@@ -480,7 +526,7 @@ class CI_FTP {
/**
* FTP List files in the specified directory
*
- * @param string $path = '.'
+ * @param string $path
* @return array
*/
public function list_files($path = '.')
@@ -503,8 +549,8 @@ class CI_FTP {
* Whatever the directory structure of the original file path will be
* recreated on the server.
*
- * @param string path to source with trailing slash
- * @param string path to destination - include the base folder with trailing slash
+ * @param string $locpath Path to source with trailing slash
+ * @param string $rempath Path to destination - include the base folder with trailing slash
* @return bool
*/
public function mirror($locpath, $rempath)
@@ -550,7 +596,7 @@ class CI_FTP {
/**
* Extract the file extension
*
- * @param string
+ * @param string $filename
* @return string
*/
protected function _getext($filename)
@@ -569,7 +615,7 @@ class CI_FTP {
/**
* Set the upload type
*
- * @param string
+ * @param string $ext Filename extension
* @return string
*/
protected function _settype($ext)
@@ -616,7 +662,7 @@ class CI_FTP {
/**
* Display error message
*
- * @param string
+ * @param string $line
* @return void
*/
protected function _error($line)
diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php
index ef4187847..9379e3ec8 100644
--- a/system/libraries/Image_lib.php
+++ b/system/libraries/Image_lib.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Image Manipulation class
@@ -866,7 +867,11 @@ class CI_Image_lib {
}
$retval = 1;
- @exec($cmd, $output, $retval);
+ // exec() might be disabled
+ if (function_usable('exec'))
+ {
+ @exec($cmd, $output, $retval);
+ }
// Did it work?
if ($retval > 0)
@@ -946,7 +951,11 @@ class CI_Image_lib {
$cmd = $this->library_path.$cmd_in.' '.$this->full_src_path.' | '.$cmd_inner.' | '.$cmd_out.' > '.$this->dest_folder.'netpbm.tmp';
$retval = 1;
- @exec($cmd, $output, $retval);
+ // exec() might be disabled
+ if (function_usable('exec'))
+ {
+ @exec($cmd, $output, $retval);
+ }
// Did it work?
if ($retval > 0)
@@ -958,7 +967,7 @@ class CI_Image_lib {
// With NetPBM we have to create a temporary image.
// If you try manipulating the original it fails so
// we have to rename the temp file.
- copy ($this->dest_folder.'netpbm.tmp', $this->full_dst_path);
+ copy($this->dest_folder.'netpbm.tmp', $this->full_dst_path);
unlink($this->dest_folder.'netpbm.tmp');
@chmod($this->full_dst_path, FILE_WRITE_MODE);
diff --git a/system/libraries/Javascript.php b/system/libraries/Javascript.php
index 60309cd83..9a15cddaa 100644
--- a/system/libraries/Javascript.php
+++ b/system/libraries/Javascript.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Javascript Class
@@ -36,12 +37,19 @@
*/
class CI_Javascript {
+ /**
+ * JavaScript location
+ *
+ * @var string
+ */
protected $_javascript_location = 'js';
+ // --------------------------------------------------------------------
+
/**
* Constructor
*
- * @param array $params = array()
+ * @param array $params
* @return void
*/
public function __construct($params = array())
@@ -586,8 +594,8 @@ class CI_Javascript {
*
* gather together all script needing to be output
*
- * @param string $view_var = 'script_foot'
- * @param bool $script_tags = TRUE
+ * @param string $view_var
+ * @param bool $script_tags
* @return string
*/
public function compile($view_var = 'script_foot', $script_tags = TRUE)
@@ -616,8 +624,8 @@ class CI_Javascript {
*
* Outputs a <script> tag with the source as an external js file
*
- * @param string $external_file = ''
- * @param bool $relative = FALSE
+ * @param string $external_file
+ * @param bool $relative
* @return string
*/
public function external($external_file = '', $relative = FALSE)
diff --git a/system/libraries/Migration.php b/system/libraries/Migration.php
index f67725c18..275aeb048 100644
--- a/system/libraries/Migration.php
+++ b/system/libraries/Migration.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 3.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Migration Class
diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php
index 36b57b332..ae8dba072 100644
--- a/system/libraries/Pagination.php
+++ b/system/libraries/Pagination.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Pagination Class
@@ -36,46 +37,269 @@
*/
class CI_Pagination {
- protected $base_url = ''; // The page we are linking to
- protected $prefix = ''; // A custom prefix added to the path.
- protected $suffix = ''; // A custom suffix added to the path.
- protected $total_rows = 0; // Total number of items (database results)
- protected $per_page = 10; // Max number of items you want shown per page
- protected $num_links = 2; // Number of "digit" links to show before/after the currently viewed page
- protected $cur_page = 0; // The current page being viewed
- protected $use_page_numbers = FALSE; // Use page number for segment instead of offset
- protected $first_link = '&lsaquo; First';
- protected $next_link = '&gt;';
- protected $prev_link = '&lt;';
- protected $last_link = 'Last &rsaquo;';
- protected $uri_segment = 3;
- protected $full_tag_open = '';
- protected $full_tag_close = '';
- protected $first_tag_open = '';
- protected $first_tag_close = '';
- protected $last_tag_open = '';
- protected $last_tag_close = '';
- protected $first_url = ''; // Alternative URL for the First Page.
- protected $cur_tag_open = '<strong>';
- protected $cur_tag_close = '</strong>';
- protected $next_tag_open = '';
- protected $next_tag_close = '';
- protected $prev_tag_open = '';
- protected $prev_tag_close = '';
- protected $num_tag_open = '';
- protected $num_tag_close = '';
+ /**
+ * Base URL
+ *
+ * The page that we're linking to
+ *
+ * @var string
+ */
+ protected $base_url = '';
+
+ /**
+ * Prefix
+ *
+ * @var string
+ */
+ protected $prefix = '';
+
+ /**
+ * Suffix
+ *
+ * @var string
+ */
+ protected $suffix = '';
+
+ /**
+ * Total number of items
+ *
+ * @var int
+ */
+ protected $total_rows = 0;
+
+ /**
+ * Items per page
+ *
+ * @var int
+ */
+ protected $per_page = 10;
+
+ /**
+ * Number of links to show
+ *
+ * Relates to "digit" type links shown before/after
+ * the currently viewed page.
+ *
+ * @var int
+ */
+ protected $num_links = 2;
+
+ /**
+ * Current page
+ *
+ * @var int
+ */
+ protected $cur_page = 0;
+
+ /**
+ * Use page numbers flag
+ *
+ * Whether to use actual page numbers instead of an offset
+ *
+ * @var bool
+ */
+ protected $use_page_numbers = FALSE;
+
+ /**
+ * First link
+ *
+ * @var string
+ */
+ protected $first_link = '&lsaquo; First';
+
+ /**
+ * Next link
+ *
+ * @var string
+ */
+ protected $next_link = '&gt;';
+
+ /**
+ * Previous link
+ *
+ * @var string
+ */
+ protected $prev_link = '&lt;';
+
+ /**
+ * Last link
+ *
+ * @var string
+ */
+ protected $last_link = 'Last &rsaquo;';
+
+ /**
+ * URI Segment
+ *
+ * @var int
+ */
+ protected $uri_segment = 3;
+
+ /**
+ * Full tag open
+ *
+ * @var string
+ */
+ protected $full_tag_open = '';
+
+ /**
+ * Full tag close
+ *
+ * @var string
+ */
+ protected $full_tag_close = '';
+
+ /**
+ * First tag open
+ *
+ * @var string
+ */
+ protected $first_tag_open = '';
+
+ /**
+ * First tag close
+ *
+ * @var string
+ */
+ protected $first_tag_close = '';
+
+ /**
+ * Last tag open
+ *
+ * @var string
+ */
+ protected $last_tag_open = '';
+
+ /**
+ * Last tag close
+ *
+ * @var string
+ */
+ protected $last_tag_close = '';
+
+ /**
+ * First URL
+ *
+ * An alternative URL for the first page
+ *
+ * @var string
+ */
+ protected $first_url = '';
+
+ /**
+ * Current tag open
+ *
+ * @var string
+ */
+ protected $cur_tag_open = '<strong>';
+
+ /**
+ * Current tag close
+ *
+ * @var string
+ */
+ protected $cur_tag_close = '</strong>';
+
+ /**
+ * Next tag open
+ *
+ * @var string
+ */
+ protected $next_tag_open = '';
+
+ /**
+ * Next tag close
+ *
+ * @var string
+ */
+ protected $next_tag_close = '';
+
+ /**
+ * Previous tag open
+ *
+ * @var string
+ */
+ protected $prev_tag_open = '';
+
+ /**
+ * Previous tag close
+ *
+ * @var string
+ */
+ protected $prev_tag_close = '';
+
+ /**
+ * Number tag open
+ *
+ * @var string
+ */
+ protected $num_tag_open = '';
+
+ /**
+ * Number tag close
+ *
+ * @var string
+ */
+ protected $num_tag_close = '';
+
+ /**
+ * Page query string flag
+ *
+ * @var bool
+ */
protected $page_query_string = FALSE;
+
+ /**
+ * Query string segment
+ *
+ * @var string
+ */
protected $query_string_segment = 'per_page';
- protected $display_pages = TRUE;
- protected $_attributes = '';
- protected $_link_types = array();
+
+ /**
+ * Display pages flag
+ *
+ * @var bool
+ */
+ protected $display_pages = TRUE;
+
+ /**
+ * Attributes
+ *
+ * @var string
+ */
+ protected $_attributes = '';
+
+ /**
+ * Link types
+ *
+ * "rel" attribute
+ *
+ * @see CI_Pagination::_attr_rel()
+ * @var array
+ */
+ protected $_link_types = array();
+
+ /**
+ * Reuse query string flag
+ *
+ * @var bool
+ */
protected $reuse_query_string = FALSE;
- protected $data_page_attr = 'data-ci-pagination-page';
+
+ /**
+ * Data page attribute
+ *
+ * @var string
+ */
+ protected $data_page_attr = 'data-ci-pagination-page';
+
+ // --------------------------------------------------------------------
/**
* Constructor
*
- * @param array initialization parameters
+ * @param array $params Initialization parameters
* @return void
*/
public function __construct($params = array())
@@ -89,7 +313,7 @@ class CI_Pagination {
/**
* Initialize Preferences
*
- * @param array initialization parameters
+ * @param array $params Initialization parameters
* @return void
*/
public function initialize($params = array())
@@ -352,7 +576,7 @@ class CI_Pagination {
/**
* Parse attributes
*
- * @param array
+ * @param array $attributes
* @return void
*/
protected function _parse_attributes($attributes)
@@ -376,7 +600,7 @@ class CI_Pagination {
* Add "rel" attribute
*
* @link http://www.w3.org/TR/html5/links.html#linkTypes
- * @param string
+ * @param string $type
* @return string
*/
protected function _attr_rel($type)
diff --git a/system/libraries/Parser.php b/system/libraries/Parser.php
index b64c78254..d29eede02 100644
--- a/system/libraries/Parser.php
+++ b/system/libraries/Parser.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Parser Class
diff --git a/system/libraries/Profiler.php b/system/libraries/Profiler.php
index 1e961f6df..1c97e3481 100644
--- a/system/libraries/Profiler.php
+++ b/system/libraries/Profiler.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* CodeIgniter Profiler Class
@@ -74,12 +75,14 @@ class CI_Profiler {
*/
protected $CI;
+ // --------------------------------------------------------------------
+
/**
- * Constructor
+ * Class constructor
*
* Initialize Profiler
*
- * @param array $config
+ * @param array $config Parameters
*/
public function __construct($config = array())
{
@@ -111,7 +114,7 @@ class CI_Profiler {
*
* Sets the private _compile_* properties to enable/disable Profiler sections
*
- * @param mixed
+ * @param mixed $config
* @return void
*/
public function set_sections($config)
@@ -190,11 +193,24 @@ class CI_Profiler {
$dbs = array();
// Let's determine which databases are currently connected to
- foreach (get_object_vars($this->CI) as $CI_object)
+ foreach (get_object_vars($this->CI) as $name => $cobject)
{
- if (is_object($CI_object) && is_subclass_of(get_class($CI_object), 'CI_DB'))
+ if (is_object($cobject))
{
- $dbs[] = $CI_object;
+ if ($cobject instanceof CI_DB)
+ {
+ $dbs[get_class($this->CI).':$'.$name] = $cobject;
+ }
+ elseif ($cobject instanceof CI_Model)
+ {
+ foreach (get_object_vars($cobject) as $mname => $mobject)
+ {
+ if ($mobject instanceof CI_DB)
+ {
+ $dbs[get_class($cobject).':$'.$mname] = $mobject;
+ }
+ }
+ }
}
}
@@ -219,7 +235,7 @@ class CI_Profiler {
$output = "\n\n";
$count = 0;
- foreach ($dbs as $db)
+ foreach ($dbs as $name => $db)
{
$hide_queries = (count($db->queries) > $this->_query_toggle_count) ? ' display:none' : '';
@@ -233,7 +249,7 @@ class CI_Profiler {
$output .= '<fieldset style="border:1px solid #0000FF;padding:6px 10px 10px 10px;margin:20px 0 20px 0;background-color:#eee;">'
."\n"
.'<legend style="color:#0000FF;">&nbsp;&nbsp;'.$this->CI->lang->line('profiler_database')
- .':&nbsp; '.$db->database.'&nbsp;&nbsp;&nbsp;'.$this->CI->lang->line('profiler_queries')
+ .':&nbsp; '.$db->database.' ('.$name.')&nbsp;&nbsp;&nbsp;'.$this->CI->lang->line('profiler_queries')
.': '.count($db->queries).'&nbsp;&nbsp;'.$show_hide_js."</legend>\n\n\n"
.'<table style="width:100%;'.$hide_queries.'" id="ci_profiler_queries_db_'.$count."\">\n";
diff --git a/system/libraries/Session/Session.php b/system/libraries/Session/Session.php
index fec9b5b31..96e65f154 100755
--- a/system/libraries/Session/Session.php
+++ b/system/libraries/Session/Session.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -18,12 +18,13 @@
*
* @package CodeIgniter
* @author EllisLab Dev Team
- * @copyright Copyright (c) 2006 - 2012 EllisLab, Inc.
+ * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
* @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* @link http://codeigniter.com
* @since Version 2.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* CodeIgniter Session Class
@@ -51,10 +52,29 @@
*/
class CI_Session extends CI_Driver_Library {
+ /**
+ * Initialization parameters
+ *
+ * @var array
+ */
public $params = array();
+
+ /**
+ * Current driver in use
+ *
+ * @var string
+ */
protected $current = NULL;
+
+ /**
+ * User data
+ *
+ * @var array
+ */
protected $userdata = array();
+ // ------------------------------------------------------------------------
+
const FLASHDATA_KEY = 'flash';
const FLASHDATA_NEW = ':new:';
const FLASHDATA_OLD = ':old:';
@@ -62,6 +82,8 @@ class CI_Session extends CI_Driver_Library {
const EXPIRATION_KEY = '__expirations';
const TEMP_EXP_DEF = 300;
+ // ------------------------------------------------------------------------
+
/**
* CI_Session constructor
*
@@ -506,7 +528,7 @@ class CI_Session extends CI_Driver_Library {
foreach ($this->all_userdata() as $name => $value)
{
$parts = explode(self::FLASHDATA_NEW, $name);
- if (is_array($parts) && count($parts) === 2)
+ if (count($parts) === 2)
{
$new_name = self::FLASHDATA_KEY.self::FLASHDATA_OLD.$parts[1];
$this->set_userdata($new_name, $value);
@@ -595,8 +617,16 @@ class CI_Session extends CI_Driver_Library {
*/
abstract class CI_Session_driver extends CI_Driver {
+ /**
+ * CI Singleton
+ *
+ * @see get_instance()
+ * @var object
+ */
protected $CI;
+ // ------------------------------------------------------------------------
+
/**
* Constructor
*
diff --git a/system/libraries/Session/drivers/Session_cookie.php b/system/libraries/Session/drivers/Session_cookie.php
index 2f1bf3531..3c4848265 100755
--- a/system/libraries/Session/drivers/Session_cookie.php
+++ b/system/libraries/Session/drivers/Session_cookie.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -9,7 +9,7 @@
* Licensed under the Open Software License version 3.0
*
* This source file is subject to the Open Software License (OSL 3.0) that is
- * bundled with this package in the files license.txt / license.rst. It is
+ * bundled with this package in the files license.txt / license.rst. It is
* also available through the world wide web at this URL:
* http://opensource.org/licenses/OSL-3.0
* If you did not receive a copy of the license and are unable to obtain it
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Cookie-based session management driver
@@ -540,11 +541,25 @@ class CI_Session_cookie extends CI_Session_driver {
// Check for database
if ($this->sess_use_database === TRUE)
{
+ $this->CI->db->where('session_id', $old_sessid);
+
+ if ($this->sess_match_ip === TRUE)
+ {
+ $this->CI->db->where('ip_address', $this->CI->input->ip_address());
+ }
+
+ if ($this->sess_match_useragent === TRUE)
+ {
+ $this->CI->db->where('user_agent', trim(substr($this->CI->input->user_agent(), 0, 120)));
+ }
+
// Update the session ID and last_activity field in the DB
- $this->CI->db->update($this->sess_table_name, array(
- 'last_activity' => $this->now,
- 'session_id' => $this->userdata['session_id']
- ), array('session_id' => $old_sessid));
+ $this->CI->db->update($this->sess_table_name,
+ array(
+ 'last_activity' => $this->now,
+ 'session_id' => $this->userdata['session_id']
+ )
+ );
}
// Write the cookie
@@ -590,7 +605,19 @@ class CI_Session_cookie extends CI_Session_driver {
// Run the update query
// Any time we change the session id, it gets updated immediately,
// so our where clause below is always safe
- $this->CI->db->update($this->sess_table_name, $set, array('session_id' => $this->userdata['session_id']));
+ $this->CI->db->where('session_id', $this->userdata['session_id']);
+
+ if ($this->sess_match_ip === TRUE)
+ {
+ $this->CI->db->where('ip_address', $this->CI->input->ip_address());
+ }
+
+ if ($this->sess_match_useragent === TRUE)
+ {
+ $this->CI->db->where('user_agent', trim(substr($this->CI->input->user_agent(), 0, 120)));
+ }
+
+ $this->CI->db->update($this->sess_table_name, $set);
// Clear dirty flag to prevent double updates
$this->data_dirty = FALSE;
diff --git a/system/libraries/Session/drivers/Session_native.php b/system/libraries/Session/drivers/Session_native.php
index a837b89f6..3e700ad5d 100755
--- a/system/libraries/Session/drivers/Session_native.php
+++ b/system/libraries/Session/drivers/Session_native.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -9,7 +9,7 @@
* Licensed under the Open Software License version 3.0
*
* This source file is subject to the Open Software License (OSL 3.0) that is
- * bundled with this package in the files license.txt / license.rst. It is
+ * bundled with this package in the files license.txt / license.rst. It is
* also available through the world wide web at this URL:
* http://opensource.org/licenses/OSL-3.0
* If you did not receive a copy of the license and are unable to obtain it
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Native PHP session management driver
diff --git a/system/libraries/Table.php b/system/libraries/Table.php
index 0f8404d85..886fb6581 100644
--- a/system/libraries/Table.php
+++ b/system/libraries/Table.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.3.1
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* HTML Table Generating Class
diff --git a/system/libraries/Trackback.php b/system/libraries/Trackback.php
index 7bd7cba04..c923a6220 100644
--- a/system/libraries/Trackback.php
+++ b/system/libraries/Trackback.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Trackback Class
@@ -38,12 +39,45 @@
*/
class CI_Trackback {
- public $time_format = 'local';
+ /**
+ * Character set
+ *
+ * @var string
+ */
public $charset = 'UTF-8';
- public $data = array('url' => '', 'title' => '', 'excerpt' => '', 'blog_name' => '', 'charset' => '');
+
+ /**
+ * Trackback data
+ *
+ * @var array
+ */
+ public $data = array('url' => '', 'title' => '', 'excerpt' => '', 'blog_name' => '', 'charset' => '');
+
+ /**
+ * Convert ASCII flag
+ *
+ * Whether to convert high-ASCII and MS Word
+ * characters to HTML entities.
+ *
+ * @var bool
+ */
public $convert_ascii = TRUE;
- public $response = '';
- public $error_msg = array();
+
+ /**
+ * Response
+ *
+ * @var string
+ */
+ public $response = '';
+
+ /**
+ * Error messages list
+ *
+ * @var string[]
+ */
+ public $error_msg = array();
+
+ // --------------------------------------------------------------------
/**
* Constructor
diff --git a/system/libraries/Typography.php b/system/libraries/Typography.php
index a50934f2c..d83bf519b 100644
--- a/system/libraries/Typography.php
+++ b/system/libraries/Typography.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Typography Class
diff --git a/system/libraries/Unit_test.php b/system/libraries/Unit_test.php
index 7b99dee0d..842b4aebd 100644
--- a/system/libraries/Unit_test.php
+++ b/system/libraries/Unit_test.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.3.1
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Unit Testing Class
@@ -38,13 +39,52 @@
*/
class CI_Unit_test {
+ /**
+ * Active flag
+ *
+ * @var bool
+ */
public $active = TRUE;
+
+ /**
+ * Test results
+ *
+ * @var array
+ */
public $results = array();
+
+ /**
+ * Strict comparison flag
+ *
+ * Whether to use === or == when comparing
+ *
+ * @var bool
+ */
public $strict = FALSE;
+
+ /**
+ * Template
+ *
+ * @var string
+ */
protected $_template = NULL;
+
+ /**
+ * Template rows
+ *
+ * @var string
+ */
protected $_template_rows = NULL;
+
+ /**
+ * List of visible test items
+ *
+ * @var array
+ */
protected $_test_items_visible = array();
+ // --------------------------------------------------------------------
+
/**
* Constructor
*
@@ -92,9 +132,9 @@ class CI_Unit_test {
* Runs the supplied tests
*
* @param mixed $test
- * @param mixed $expected = TRUE
- * @param string $test_name = 'undefined'
- * @param string $notes = ''
+ * @param mixed $expected
+ * @param string $test_name
+ * @param string $notes
* @return string
*/
public function run($test, $expected = TRUE, $test_name = 'undefined', $notes = '')
@@ -112,13 +152,13 @@ class CI_Unit_test {
}
else
{
- $result = ($this->strict === TRUE) ? ($test === $expected) : ($test === $expected);
+ $result = ($this->strict === TRUE) ? ($test === $expected) : ($test == $expected);
$extype = gettype($expected);
}
$back = $this->_backtrace();
- $report[] = array (
+ $report = array (
'test_name' => $test_name,
'test_datatype' => gettype($test),
'res_datatype' => $extype,
@@ -130,7 +170,7 @@ class CI_Unit_test {
$this->results[] = $report;
- return $this->report($this->result($report));
+ return $this->report($this->result(array($report)));
}
// --------------------------------------------------------------------
@@ -140,7 +180,7 @@ class CI_Unit_test {
*
* Displays a table with the test data
*
- * @param array $result = array()
+ * @param array $result
* @return string
*/
public function report($result = array())
@@ -220,7 +260,7 @@ class CI_Unit_test {
*
* Returns the raw result data
*
- * @param array $results = array()
+ * @param array $results
* @return array
*/
public function result($results = array())
@@ -244,30 +284,11 @@ class CI_Unit_test {
continue;
}
- if (is_array($val))
- {
- foreach ($val as $k => $v)
- {
- if ( ! in_array($k, $this->_test_items_visible))
- {
- continue;
- }
-
- if (FALSE !== ($line = $CI->lang->line(strtolower('ut_'.$v))))
- {
- $v = $line;
- }
- $temp[$CI->lang->line('ut_'.$k)] = $v;
- }
- }
- else
+ if (FALSE !== ($line = $CI->lang->line(strtolower('ut_'.$val))))
{
- if (FALSE !== ($line = $CI->lang->line(strtolower('ut_'.$val))))
- {
- $val = $line;
- }
- $temp[$CI->lang->line('ut_'.$key)] = $val;
+ $val = $line;
}
+ $temp[$CI->lang->line('ut_'.$key)] = $val;
}
$retval[] = $temp;
@@ -375,4 +396,4 @@ function is_false($test)
}
/* End of file Unit_test.php */
-/* Location: ./system/libraries/Unit_test.php */ \ No newline at end of file
+/* Location: ./system/libraries/Unit_test.php */
diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php
index 76bbc244e..b3e9f7515 100644
--- a/system/libraries/Upload.php
+++ b/system/libraries/Upload.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* File Uploading Class
@@ -36,40 +37,210 @@
*/
class CI_Upload {
+ /**
+ * Maximum file size
+ *
+ * @var int
+ */
public $max_size = 0;
+
+ /**
+ * Maximum image width
+ *
+ * @var int
+ */
public $max_width = 0;
+
+ /**
+ * Maximum image height
+ *
+ * @var int
+ */
public $max_height = 0;
+
+ /**
+ * Maximum filename length
+ *
+ * @var int
+ */
public $max_filename = 0;
+
+ /**
+ * Maximum duplicate filename increment ID
+ *
+ * @var int
+ */
public $max_filename_increment = 100;
+
+ /**
+ * Allowed file types
+ *
+ * @var string
+ */
public $allowed_types = '';
+
+ /**
+ * Temporary filename
+ *
+ * @var string
+ */
public $file_temp = '';
+
+ /**
+ * Filename
+ *
+ * @var string
+ */
public $file_name = '';
+
+ /**
+ * Original filename
+ *
+ * @var string
+ */
public $orig_name = '';
+
+ /**
+ * File type
+ *
+ * @var string
+ */
public $file_type = '';
- public $file_size = '';
+
+ /**
+ * File size
+ *
+ * @var int
+ */
+ public $file_size = NULL;
+
+ /**
+ * Filename extension
+ *
+ * @var string
+ */
public $file_ext = '';
+
+ /**
+ * Upload path
+ *
+ * @var string
+ */
public $upload_path = '';
+
+ /**
+ * Overwrite flag
+ *
+ * @var bool
+ */
public $overwrite = FALSE;
+
+ /**
+ * Obfuscate filename flag
+ *
+ * @var bool
+ */
public $encrypt_name = FALSE;
+
+ /**
+ * Is image flag
+ *
+ * @var bool
+ */
public $is_image = FALSE;
- public $image_width = '';
- public $image_height = '';
+
+ /**
+ * Image width
+ *
+ * @var int
+ */
+ public $image_width = NULL;
+
+ /**
+ * Image height
+ *
+ * @var int
+ */
+ public $image_height = NULL;
+
+ /**
+ * Image type
+ *
+ * @var string
+ */
public $image_type = '';
+
+ /**
+ * Image size string
+ *
+ * @var string
+ */
public $image_size_str = '';
+
+ /**
+ * Error messages list
+ *
+ * @var array
+ */
public $error_msg = array();
+
+ /**
+ * MIME types list
+ *
+ * @var array
+ */
public $mimes = array();
+
+ /**
+ * Remove spaces flag
+ *
+ * @var bool
+ */
public $remove_spaces = TRUE;
+
+ /**
+ * MIME detection flag
+ *
+ * @var bool
+ */
public $detect_mime = TRUE;
+
+ /**
+ * XSS filter flag
+ *
+ * @var bool
+ */
public $xss_clean = FALSE;
+
+ /**
+ * Temporary filename prefix
+ *
+ * @var string
+ */
public $temp_prefix = 'temp_file_';
+
+ /**
+ * Filename sent by the client
+ *
+ * @var bool
+ */
public $client_name = '';
+ // --------------------------------------------------------------------
+
+ /**
+ * Filename override
+ *
+ * @var string
+ */
protected $_file_name_override = '';
+ // --------------------------------------------------------------------
+
/**
* Constructor
*
- * @param array
+ * @param array $props
* @return void
*/
public function __construct($props = array())
@@ -89,7 +260,7 @@ class CI_Upload {
/**
* Initialize preferences
*
- * @param array
+ * @param array $config
* @return void
*/
public function initialize($config = array())
@@ -105,14 +276,14 @@ class CI_Upload {
'file_name' => '',
'orig_name' => '',
'file_type' => '',
- 'file_size' => '',
+ 'file_size' => NULL,
'file_ext' => '',
'upload_path' => '',
'overwrite' => FALSE,
'encrypt_name' => FALSE,
'is_image' => FALSE,
- 'image_width' => '',
- 'image_height' => '',
+ 'image_width' => NULL,
+ 'image_height' => NULL,
'image_type' => '',
'image_size_str' => '',
'error_msg' => array(),
@@ -154,7 +325,7 @@ class CI_Upload {
/**
* Perform the file upload
*
- * @param string $field = 'userfile'
+ * @param string $field
* @return bool
*/
public function do_upload($field = 'userfile')
@@ -356,7 +527,7 @@ class CI_Upload {
* Returns an associative array containing all of the information
* related to the upload, allowing the developer easy access in one array.
*
- * @param string
+ * @param string $index
* @return mixed
*/
public function data($index = NULL)
@@ -391,7 +562,7 @@ class CI_Upload {
/**
* Set Upload Path
*
- * @param string
+ * @param string $path
* @return void
*/
public function set_upload_path($path)
@@ -409,8 +580,8 @@ class CI_Upload {
* existence of a file with the same name. If found, it will append a
* number to the end of the filename to avoid overwriting a pre-existing file.
*
- * @param string
- * @param string
+ * @param string $path
+ * @param string $filename
* @return string
*/
public function set_filename($path, $filename)
@@ -454,7 +625,7 @@ class CI_Upload {
/**
* Set Maximum File Size
*
- * @param int
+ * @param int $n
* @return void
*/
public function set_max_filesize($n)
@@ -467,7 +638,7 @@ class CI_Upload {
/**
* Set Maximum File Name Length
*
- * @param int
+ * @param int $n
* @return void
*/
public function set_max_filename($n)
@@ -480,7 +651,7 @@ class CI_Upload {
/**
* Set Maximum Image Width
*
- * @param int
+ * @param int $n
* @return void
*/
public function set_max_width($n)
@@ -493,7 +664,7 @@ class CI_Upload {
/**
* Set Maximum Image Height
*
- * @param int
+ * @param int $n
* @return void
*/
public function set_max_height($n)
@@ -506,7 +677,7 @@ class CI_Upload {
/**
* Set Allowed File Types
*
- * @param string
+ * @param string $types
* @return void
*/
public function set_allowed_types($types)
@@ -526,7 +697,7 @@ class CI_Upload {
*
* Uses GD to determine the width/height/type of image
*
- * @param string
+ * @param string $path
* @return void
*/
public function set_image_properties($path = '')
@@ -558,7 +729,7 @@ class CI_Upload {
* Enables the XSS flag so that the file that was uploaded
* will be run through the XSS filter.
*
- * @param bool
+ * @param bool $flag
* @return void
*/
public function set_xss_clean($flag = FALSE)
@@ -600,7 +771,7 @@ class CI_Upload {
/**
* Verify that the filetype is allowed
*
- * @param bool
+ * @param bool $ignore_mime
* @return bool
*/
public function is_allowed_filetype($ignore_mime = FALSE)
@@ -737,7 +908,7 @@ class CI_Upload {
/**
* Extract the file extension
*
- * @param string
+ * @param string $filename
* @return string
*/
public function get_extension($filename)
@@ -751,7 +922,7 @@ class CI_Upload {
/**
* Clean the file name for security
*
- * @param string
+ * @param string $filename
* @return string
*/
public function clean_file_name($filename)
@@ -885,7 +1056,7 @@ class CI_Upload {
/**
* Set an error message
*
- * @param string
+ * @param string $msg
* @return void
*/
public function set_error($msg)
@@ -915,8 +1086,8 @@ class CI_Upload {
/**
* Display the error message
*
- * @param string
- * @param string
+ * @param string $open
+ * @param string $close
* @return string
*/
public function display_errors($open = '<p>', $close = '</p>')
@@ -932,7 +1103,7 @@ class CI_Upload {
* This is a list of mime types. We use it to validate
* the "allowed types" set by the developer
*
- * @param string
+ * @param string $mime
* @return string
*/
public function mimes_types($mime)
@@ -945,10 +1116,12 @@ class CI_Upload {
/**
* Prep Filename
*
- * Prevents possible script execution from Apache's handling of files multiple extensions
- * http://httpd.apache.org/docs/1.3/mod/mod_mime.html#multipleext
+ * Prevents possible script execution from Apache's handling
+ * of files' multiple extensions.
+ *
+ * @link http://httpd.apache.org/docs/1.3/mod/mod_mime.html#multipleext
*
- * @param string
+ * @param string $filename
* @return string
*/
protected function _prep_filename($filename)
@@ -985,7 +1158,7 @@ class CI_Upload {
* Detects the (actual) MIME type of the uploaded file, if possible.
* The input array is expected to be $_FILES[$field]
*
- * @param array
+ * @param array $file
* @return void
*/
protected function _file_mime_type($file)
@@ -1035,7 +1208,7 @@ class CI_Upload {
? 'file --brief --mime '.escapeshellarg($file['tmp_name']).' 2>&1'
: 'file --brief --mime '.$file['tmp_name'].' 2>&1';
- if (function_exists('exec'))
+ if (function_usable('exec'))
{
/* This might look confusing, as $mime is being populated with all of the output when set in the second parameter.
* However, we only neeed the last line, which is the actual return value of exec(), and as such - it overwrites
@@ -1050,7 +1223,7 @@ class CI_Upload {
}
}
- if ( (bool) @ini_get('safe_mode') === FALSE && function_exists('shell_exec'))
+ if ( (bool) @ini_get('safe_mode') === FALSE && function_usable('shell_exec'))
{
$mime = @shell_exec($cmd);
if (strlen($mime) > 0)
@@ -1064,7 +1237,7 @@ class CI_Upload {
}
}
- if (function_exists('popen'))
+ if (function_usable('popen'))
{
$proc = @popen($cmd, 'r');
if (is_resource($proc))
diff --git a/system/libraries/User_agent.php b/system/libraries/User_agent.php
index 3387d4aa6..e920578d9 100644
--- a/system/libraries/User_agent.php
+++ b/system/libraries/User_agent.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* User Agent Class
diff --git a/system/libraries/Xmlrpc.php b/system/libraries/Xmlrpc.php
index 3ed050a2e..3ef823e29 100755
--- a/system/libraries/Xmlrpc.php
+++ b/system/libraries/Xmlrpc.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,14 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
+
+if ( ! function_exists('xml_parser_create'))
+{
+ show_error('Your PHP installation does not support XML');
+}
+
+// ------------------------------------------------------------------------
/**
* XML-RPC request handler class
@@ -34,56 +42,212 @@
* @author EllisLab Dev Team
* @link http://codeigniter.com/user_guide/libraries/xmlrpc.html
*/
-
-if ( ! function_exists('xml_parser_create'))
-{
- show_error('Your PHP installation does not support XML');
-}
-
-// ------------------------------------------------------------------------
-
class CI_Xmlrpc {
- public $debug = FALSE; // Debugging on or off
+ /**
+ * Debug flag
+ *
+ * @var bool
+ */
+ public $debug = FALSE;
+
+ /**
+ * I4 data type
+ *
+ * @var string
+ */
public $xmlrpcI4 = 'i4';
+
+ /**
+ * Integer data type
+ *
+ * @var string
+ */
public $xmlrpcInt = 'int';
+
+ /**
+ * Boolean data type
+ *
+ * @var string
+ */
public $xmlrpcBoolean = 'boolean';
+
+ /**
+ * Double data type
+ *
+ * @var string
+ */
public $xmlrpcDouble = 'double';
+
+ /**
+ * String data type
+ *
+ * @var string
+ */
public $xmlrpcString = 'string';
+
+ /**
+ * DateTime format
+ *
+ * @var string
+ */
public $xmlrpcDateTime = 'dateTime.iso8601';
+
+ /**
+ * Base64 data type
+ *
+ * @var string
+ */
public $xmlrpcBase64 = 'base64';
+
+ /**
+ * Array data type
+ *
+ * @var string
+ */
public $xmlrpcArray = 'array';
+
+ /**
+ * Struct data type
+ *
+ * @var string
+ */
public $xmlrpcStruct = 'struct';
+ /**
+ * Data types list
+ *
+ * @var array
+ */
public $xmlrpcTypes = array();
+
+ /**
+ * Valid parents list
+ *
+ * @var array
+ */
public $valid_parents = array();
- public $xmlrpcerr = array(); // Response numbers
- public $xmlrpcstr = array(); // Response strings
+ /**
+ * Response error numbers list
+ *
+ * @var array
+ */
+ public $xmlrpcerr = array();
+
+ /**
+ * Response error messages list
+ *
+ * @var string[]
+ */
+ public $xmlrpcstr = array();
+
+ /**
+ * Encoding charset
+ *
+ * @var string
+ */
public $xmlrpc_defencoding = 'UTF-8';
+
+ /**
+ * XML-RPC client name
+ *
+ * @var string
+ */
public $xmlrpcName = 'XML-RPC for CodeIgniter';
+
+ /**
+ * XML-RPC version
+ *
+ * @var string
+ */
public $xmlrpcVersion = '1.1';
- public $xmlrpcerruser = 800; // Start of user errors
- public $xmlrpcerrxml = 100; // Start of XML Parse errors
- public $xmlrpc_backslash = ''; // formulate backslashes for escaping regexp
+ /**
+ * Start of user errors
+ *
+ * @var int
+ */
+ public $xmlrpcerruser = 800;
+
+ /**
+ * Start of XML parse errors
+ *
+ * @var int
+ */
+ public $xmlrpcerrxml = 100;
+
+ /**
+ * Backslash replacement value
+ *
+ * @var string
+ */
+ public $xmlrpc_backslash = '';
+
+ /**
+ * XML-RPC Client object
+ *
+ * @var object
+ */
public $client;
+
+ /**
+ * XML-RPC Method name
+ *
+ * @var string
+ */
public $method;
+
+ /**
+ * XML-RPC Data
+ *
+ * @var array
+ */
public $data;
+
+ /**
+ * XML-RPC Message
+ *
+ * @var string
+ */
public $message = '';
- public $error = ''; // Error string for request
+
+ /**
+ * Request error message
+ *
+ * @var string
+ */
+ public $error = '';
+
+ /**
+ * XML-RPC result object
+ *
+ * @var object
+ */
public $result;
+
+ /**
+ * XML-RPC Reponse
+ *
+ * @var array
+ */
public $response = array(); // Response from remote server
+ /**
+ * XSS Filter flag
+ *
+ * @var bool
+ */
public $xss_clean = TRUE;
+ // --------------------------------------------------------------------
/**
* Constructor
*
* Initializes property default values
*
- * @param array
+ * @param array $config
* @return void
*/
public function __construct($config = array())
@@ -148,7 +312,7 @@ class CI_Xmlrpc {
/**
* Initialize
*
- * @param array
+ * @param array $config
* @return void
*/
public function initialize($config = array())
@@ -171,9 +335,9 @@ class CI_Xmlrpc {
* Parse server URL
*
* @param string $url
- * @param int $port = 80
- * @param string $proxy = FALSE
- * @param int $proxy_port = 8080
+ * @param int $port
+ * @param string $proxy
+ * @param int $proxy_port
* @return void
*/
public function server($url, $port = 80, $proxy = FALSE, $proxy_port = 8080)
@@ -200,7 +364,7 @@ class CI_Xmlrpc {
/**
* Set Timeout
*
- * @param int seconds
+ * @param int $seconds
* @return void
*/
public function timeout($seconds = 5)
@@ -216,7 +380,7 @@ class CI_Xmlrpc {
/**
* Set Methods
*
- * @param string method name
+ * @param string $function Method name
* @return void
*/
public function method($function)
@@ -229,7 +393,7 @@ class CI_Xmlrpc {
/**
* Take Array of Data and Create Objects
*
- * @param array
+ * @param array $incoming
* @return void
*/
public function request($incoming)
@@ -253,7 +417,7 @@ class CI_Xmlrpc {
/**
* Set Debug
*
- * @param bool
+ * @param bool $flag
* @return void
*/
public function set_debug($flag = TRUE)
@@ -266,7 +430,7 @@ class CI_Xmlrpc {
/**
* Values Parsing
*
- * @param mixed
+ * @param mixed $value
* @return object
*/
public function values_parsing($value)
@@ -349,8 +513,8 @@ class CI_Xmlrpc {
/**
* Sends an Error Message for Server Request
*
- * @param int
- * @param string
+ * @param int $number
+ * @param string $message
* @return object
*/
public function send_error_message($number, $message)
@@ -363,7 +527,7 @@ class CI_Xmlrpc {
/**
* Send Response for Server Request
*
- * @param array
+ * @param array $response
* @return object
*/
public function send_response($response)
@@ -384,24 +548,79 @@ class CI_Xmlrpc {
*/
class XML_RPC_Client extends CI_Xmlrpc
{
+ /**
+ * Path
+ *
+ * @var string
+ */
public $path = '';
+
+ /**
+ * Server hostname
+ *
+ * @var string
+ */
public $server = '';
+
+ /**
+ * Server port
+ *
+ * @var int
+ */
public $port = 80;
+
+ /**
+ * Proxy hostname
+ *
+ * @var string
+ */
public $proxy = FALSE;
+
+ /**
+ * Proxy port
+ *
+ * @var int
+ */
public $proxy_port = 8080;
+
+ /**
+ * Error number
+ *
+ * @var string
+ */
public $errno = '';
+
+ /**
+ * Error message
+ *
+ * @var string
+ */
public $errstring = '';
+
+ /**
+ * Timeout in seconds
+ *
+ * @var int
+ */
public $timeout = 5;
+
+ /**
+ * No Multicall flag
+ *
+ * @var bool
+ */
public $no_multicall = FALSE;
+ // --------------------------------------------------------------------
+
/**
* Constructor
*
* @param string $path
* @param object $server
- * @param int $port = 80
- * @param string $proxy = FALSE
- * @param int $proxy_port = 8080
+ * @param int $port
+ * @param string $proxy
+ * @param int $proxy_port
* @return void
*/
public function __construct($path, $server, $port = 80, $proxy = FALSE, $proxy_port = 8080)
@@ -420,7 +639,7 @@ class XML_RPC_Client extends CI_Xmlrpc
/**
* Send message
*
- * @param mixed
+ * @param mixed $msg
* @return object
*/
public function send($msg)
@@ -439,7 +658,7 @@ class XML_RPC_Client extends CI_Xmlrpc
/**
* Send payload
*
- * @param object
+ * @param object $msg
* @return object
*/
public function sendPayload($msg)
@@ -499,18 +718,50 @@ class XML_RPC_Client extends CI_Xmlrpc
*/
class XML_RPC_Response
{
+
+ /**
+ * Value
+ *
+ * @var mixed
+ */
public $val = 0;
+
+ /**
+ * Error number
+ *
+ * @var int
+ */
public $errno = 0;
+
+ /**
+ * Error message
+ *
+ * @var string
+ */
public $errstr = '';
+
+ /**
+ * Headers list
+ *
+ * @var array
+ */
public $headers = array();
+
+ /**
+ * XSS Filter flag
+ *
+ * @var bool
+ */
public $xss_clean = TRUE;
+ // --------------------------------------------------------------------
+
/**
* Constructor
*
- * @param mixed
- * @param int
- * @param string
+ * @param mixed $val
+ * @param int $code
+ * @param string $fstr
* @return void
*/
public function __construct($val, $code = 0, $fstr = '')
@@ -716,16 +967,42 @@ class XML_RPC_Response
*/
class XML_RPC_Message extends CI_Xmlrpc
{
+
+ /**
+ * Payload
+ *
+ * @var string
+ */
public $payload;
+
+ /**
+ * Method name
+ *
+ * @var string
+ */
public $method_name;
+
+ /**
+ * Parameter list
+ *
+ * @var array
+ */
public $params = array();
+
+ /**
+ * XH?
+ *
+ * @var array
+ */
public $xh = array();
+ // --------------------------------------------------------------------
+
/**
* Constructor
*
- * @param string method name
- * @param array
+ * @param string $method
+ * @param array $pars
* @return void
*/
public function __construct($method, $pars = FALSE)
@@ -1303,14 +1580,27 @@ class XML_RPC_Message extends CI_Xmlrpc
*/
class XML_RPC_Values extends CI_Xmlrpc
{
+ /**
+ * Value data
+ *
+ * @var array
+ */
public $me = array();
+
+ /**
+ * Value type
+ *
+ * @var int
+ */
public $mytype = 0;
+ // --------------------------------------------------------------------
+
/**
* Constructor
*
- * @param mixed
- * @param string
+ * @param mixed $val
+ * @param string $type
* @return void
*/
public function __construct($val = -1, $type = '')
diff --git a/system/libraries/Xmlrpcs.php b/system/libraries/Xmlrpcs.php
index 5d01d374d..3c3337bf2 100644
--- a/system/libraries/Xmlrpcs.php
+++ b/system/libraries/Xmlrpcs.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
if ( ! function_exists('xml_parser_create'))
{
diff --git a/system/libraries/Zip.php b/system/libraries/Zip.php
index 5c4c257f8..9ecd0de9f 100644
--- a/system/libraries/Zip.php
+++ b/system/libraries/Zip.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Zip Compression Class
diff --git a/system/libraries/javascript/Jquery.php b/system/libraries/javascript/Jquery.php
index ed02fadb7..2bf47957f 100644
--- a/system/libraries/javascript/Jquery.php
+++ b/system/libraries/javascript/Jquery.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Jquery Class
@@ -36,14 +37,57 @@
*/
class CI_Jquery extends CI_Javascript {
+ /**
+ * JavaScript directory location
+ *
+ * @var string
+ */
protected $_javascript_folder = 'js';
+
+ /**
+ * JQuery code for load
+ *
+ * @var array
+ */
public $jquery_code_for_load = array();
+
+ /**
+ * JQuery code for compile
+ *
+ * @var array
+ */
public $jquery_code_for_compile = array();
+
+ /**
+ * JQuery corner active flag
+ *
+ * @var bool
+ */
public $jquery_corner_active = FALSE;
+
+ /**
+ * JQuery table sorter active flag
+ *
+ * @var bool
+ */
public $jquery_table_sorter_active = FALSE;
+
+ /**
+ * JQuery table sorder pager active
+ *
+ * @var bool
+ */
public $jquery_table_sorter_pager_active = FALSE;
+
+ /**
+ * JQuery AJAX image
+ *
+ * @var string
+ */
public $jquery_ajax_img = '';
+ // --------------------------------------------------------------------
+
/**
* Constructor
*
@@ -382,8 +426,8 @@ class CI_Jquery extends CI_Javascript {
*
* Outputs a jQuery addClass event
*
- * @param string $element = 'this'
- * @param string $class = ''
+ * @param string $element
+ * @param string $class
* @return string
*/
protected function _addClass($element = 'this', $class = '')
@@ -399,10 +443,10 @@ class CI_Jquery extends CI_Javascript {
*
* Outputs a jQuery animate event
*
- * @param string $element = 'this'
- * @param array $params = array()
- * @param string $speed = '' 'slow', 'normal', 'fast', or time in milliseconds
- * @param string $extra = ''
+ * @param string $element
+ * @param array $params
+ * @param string $speed 'slow', 'normal', 'fast', or time in milliseconds
+ * @param string $extra
* @return string
*/
protected function _animate($element = 'this', $params = array(), $speed = '', $extra = '')
@@ -514,8 +558,8 @@ class CI_Jquery extends CI_Javascript {
*
* Outputs a jQuery remove class event
*
- * @param string $element = 'this'
- * @param string $class = ''
+ * @param string $element
+ * @param string $class
* @return string
*/
protected function _removeClass($element = 'this', $class = '')
@@ -622,8 +666,8 @@ class CI_Jquery extends CI_Javascript {
*
* Outputs a jQuery toggle class event
*
- * @param string $element = 'this'
- * @param string $class = ''
+ * @param string $element
+ * @param string $class
* @return string
*/
protected function _toggleClass($element = 'this', $class = '')
@@ -707,9 +751,9 @@ class CI_Jquery extends CI_Javascript {
/**
* Zebra tables
*
- * @param string $class = ''
- * @param string $odd = 'odd'
- * @param string $hover = ''
+ * @param string $class
+ * @param string $odd
+ * @param string $hover
* @return string
*/
protected function _zebraTables($class = '', $odd = 'odd', $hover = '')
@@ -734,10 +778,9 @@ class CI_Jquery extends CI_Javascript {
/**
* Corner Plugin
*
- * http://www.malsup.com/jquery/corner/
- *
- * @param string $element = ''
- * @param string $corner_style = ''
+ * @link http://www.malsup.com/jquery/corner/
+ * @param string $element
+ * @param string $corner_style
* @return string
*/
public function corner($element = '', $corner_style = '')
@@ -761,7 +804,7 @@ class CI_Jquery extends CI_Javascript {
* Load a thickbox modal window
*
* @param string $src
- * @param bool $relative = FALSE
+ * @param bool $relative
* @return void
*/
public function modal($src, $relative = FALSE)
@@ -777,7 +820,7 @@ class CI_Jquery extends CI_Javascript {
* Load an Effect library
*
* @param string $src
- * @param bool $relative = FALSE
+ * @param bool $relative
* @return void
*/
public function effect($src, $relative = FALSE)
@@ -793,7 +836,7 @@ class CI_Jquery extends CI_Javascript {
* Load a plugin library
*
* @param string $src
- * @param bool $relative = FALSE
+ * @param bool $relative
* @return void
*/
public function plugin($src, $relative = FALSE)
@@ -809,7 +852,7 @@ class CI_Jquery extends CI_Javascript {
* Load a user interface library
*
* @param string $src
- * @param bool $relative = FALSE
+ * @param bool $relative
* @return void
*/
public function ui($src, $relative = FALSE)
@@ -825,7 +868,7 @@ class CI_Jquery extends CI_Javascript {
* Creates a jQuery sortable
*
* @param string $element
- * @param array $options = array()
+ * @param array $options
* @return string
*/
public function sortable($element, $options = array())
@@ -896,8 +939,8 @@ class CI_Jquery extends CI_Javascript {
* As events are specified, they are stored in an array
* This funciton compiles them all for output on a page
*
- * @param string $view_var = 'script_foot'
- * @param bool $script_tags = TRUE
+ * @param string $view_var
+ * @param bool $script_tags
* @return void
*/
protected function _compile($view_var = 'script_foot', $script_tags = TRUE)
@@ -963,8 +1006,8 @@ class CI_Jquery extends CI_Javascript {
*
* Outputs the script tag that loads the jquery.js file into an HTML document
*
- * @param string $library_src = ''
- * @param bool $relative = FALSE
+ * @param string $library_src
+ * @param bool $relative
* @return string
*/
public function script($library_src = '', $relative = FALSE)
diff --git a/tests/codeigniter/core/Loader_test.php b/tests/codeigniter/core/Loader_test.php
index 816587a49..ecc5ca933 100644
--- a/tests/codeigniter/core/Loader_test.php
+++ b/tests/codeigniter/core/Loader_test.php
@@ -493,7 +493,6 @@ class Loader_test extends CI_TestCase {
);
$this->ci_vfs_create('autoload', '<?php $autoload = '.var_export($cfg, TRUE).';', $this->ci_app_root, 'config');
- // Run initialize and autoloader
$this->load->initialize();
// Verify path
diff --git a/tests/codeigniter/database/DB_driver_test.php b/tests/codeigniter/database/DB_driver_test.php
index 9e16e29b4..1f48ca984 100644
--- a/tests/codeigniter/database/DB_driver_test.php
+++ b/tests/codeigniter/database/DB_driver_test.php
@@ -5,7 +5,7 @@ class DB_driver_test extends CI_TestCase {
public function test_initialize()
{
$config = Mock_Database_DB::config(DB_DRIVER);
- $driver_name = current(explode('/', DB_DRIVER));
+ sscanf(DB_DRIVER, '%[^/]/', $driver_name);
$driver = $this->$driver_name($config[DB_DRIVER]);
$this->assertTrue($driver->initialize());
diff --git a/tests/codeigniter/helpers/directory_helper_test.php b/tests/codeigniter/helpers/directory_helper_test.php
index c39ccd8d0..41370e6e7 100644
--- a/tests/codeigniter/helpers/directory_helper_test.php
+++ b/tests/codeigniter/helpers/directory_helper_test.php
@@ -28,9 +28,9 @@ class Directory_helper_test extends CI_TestCase {
// test default recursive behavior
$expected = array(
- 'libraries' => array(
+ 'libraries/' => array(
'benchmark.html',
- 'database' => array('active_record.html', 'binds.html'),
+ 'database/' => array('active_record.html', 'binds.html'),
'email.html',
'0'
)
@@ -39,12 +39,12 @@ class Directory_helper_test extends CI_TestCase {
$this->assertEquals($expected, directory_map(vfsStream::url('testDir')));
// test detection of hidden files
- $expected['libraries'][] = '.hiddenfile.txt';
+ $expected['libraries/'][] = '.hiddenfile.txt';
$this->assertEquals($expected, directory_map(vfsStream::url('testDir'), FALSE, TRUE));
// test recursion depth behavior
- $this->assertEquals(array('libraries'), directory_map(vfsStream::url('testDir'), 1));
+ $this->assertEquals(array('libraries/'), directory_map(vfsStream::url('testDir'), 1));
}
}
diff --git a/tests/codeigniter/helpers/form_helper_test.php b/tests/codeigniter/helpers/form_helper_test.php
index 03278581d..89165271e 100644
--- a/tests/codeigniter/helpers/form_helper_test.php
+++ b/tests/codeigniter/helpers/form_helper_test.php
@@ -272,6 +272,21 @@ EOH;
$this->assertEquals($expected, form_close('</div></div>'));
}
+ // ------------------------------------------------------------------------
+
+ public function test_form_prep()
+ {
+ $this->assertEquals(
+ 'Here is a string containing &quot;quoted&quot; text.',
+ form_prep('Here is a string containing "quoted" text.')
+ );
+
+ $this->assertEquals(
+ 'Here is a string containing a &lt;tag&gt;.',
+ form_prep('Here is a string containing a <tag>.', TRUE)
+ );
+ }
+
}
/* End of file form_helper_test.php */ \ No newline at end of file
diff --git a/tests/mocks/autoloader.php b/tests/mocks/autoloader.php
index 5b202f159..3d216da1f 100644
--- a/tests/mocks/autoloader.php
+++ b/tests/mocks/autoloader.php
@@ -16,7 +16,7 @@ function autoload($class)
$ci_core = array(
'Benchmark', 'Config', 'Controller',
'Exceptions', 'Hooks', 'Input',
- 'Lang', 'Loader', 'Model',
+ 'Lang', 'Loader', 'Log', 'Model',
'Output', 'Router', 'Security',
'URI', 'Utf8',
);
@@ -25,11 +25,10 @@ function autoload($class)
'Calendar', 'Cart', 'Driver_Library',
'Email', 'Encrypt', 'Form_validation',
'Ftp', 'Image_lib', 'Javascript',
- 'Log', 'Migration', 'Pagination',
- 'Parser', 'Profiler', 'Table',
- 'Trackback', 'Typography', 'Unit_test',
- 'Upload', 'User_agent', 'Xmlrpc',
- 'Zip',
+ 'Migration', 'Pagination', 'Parser',
+ 'Profiler', 'Table', 'Trackback',
+ 'Typography', 'Unit_test', 'Upload',
+ 'User_agent', 'Xmlrpc', 'Zip'
);
$ci_drivers = array(
@@ -38,13 +37,11 @@ function autoload($class)
if (strpos($class, 'Mock_') === 0)
{
- $class = str_replace(array('Mock_', '_'), array('', DIRECTORY_SEPARATOR), $class);
- $class = strtolower($class);
+ $class = strtolower(str_replace(array('Mock_', '_'), array('', DIRECTORY_SEPARATOR), $class));
}
elseif (strpos($class, 'CI_') === 0)
{
- $fragments = explode('_', $class, 2);
- $subclass = next($fragments);
+ $subclass = substr($class, 3);
if (in_array($subclass, $ci_core))
{
@@ -88,7 +85,7 @@ function autoload($class)
}
}
- $file = (isset($file)) ? $file : $dir.$class.'.php';
+ $file = isset($file) ? $file : $dir.$class.'.php';
if ( ! file_exists($file))
{
diff --git a/tests/mocks/database/db/driver.php b/tests/mocks/database/db/driver.php
index 65ac2c4cc..2cf54b97b 100644
--- a/tests/mocks/database/db/driver.php
+++ b/tests/mocks/database/db/driver.php
@@ -34,6 +34,7 @@ class Mock_Database_DB_Driver extends CI_DB_driver {
return call_user_func_array(array($this->ci_db_driver, $method), $arguments);
}
+
}
class CI_DB extends Mock_Database_DB_QueryBuilder {} \ No newline at end of file
diff --git a/tests/mocks/database/schema/skeleton.php b/tests/mocks/database/schema/skeleton.php
index d72244528..e5c536090 100644
--- a/tests/mocks/database/schema/skeleton.php
+++ b/tests/mocks/database/schema/skeleton.php
@@ -69,7 +69,7 @@ class Mock_Database_Schema_Skeleton {
)
));
static::$forge->add_key('id', TRUE);
- static::$forge->create_table('user', (strpos(static::$driver, 'pgsql') === FALSE));
+ static::$forge->create_table('user', TRUE);
// Job Table
static::$forge->add_field(array(
@@ -86,7 +86,7 @@ class Mock_Database_Schema_Skeleton {
)
));
static::$forge->add_key('id', TRUE);
- static::$forge->create_table('job', (strpos(static::$driver, 'pgsql') === FALSE));
+ static::$forge->create_table('job', TRUE);
// Misc Table
static::$forge->add_field(array(
@@ -103,7 +103,7 @@ class Mock_Database_Schema_Skeleton {
)
));
static::$forge->add_key('id', TRUE);
- static::$forge->create_table('misc', (strpos(static::$driver, 'pgsql') === FALSE));
+ static::$forge->create_table('misc', TRUE);
}
/**
diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst
index f45cc5cd7..707d8b3ea 100644
--- a/user_guide_src/source/changelog.rst
+++ b/user_guide_src/source/changelog.rst
@@ -39,14 +39,16 @@ Release Date: Not Released
- Updated support for zip files in mimes.php.
- Updated support for csv files in mimes.php.
- Added some more doctypes.
+ - Added Romanian, Greek, Vietnamese and Cyrilic characters in *application/config/foreign_characters.php*.
- Added Romanian, Greek and Vietnamese characters in *foreign_characters.php*.
- Changed logger to only chmod when file is first created.
- Removed previously deprecated SHA1 Library.
- - Removed previously deprecated use of ``$autoload['core']`` in application/config/autoload.php.
+ - Removed previously deprecated use of ``$autoload['core']`` in *application/config/autoload.php*.
Only entries in ``$autoload['libraries']`` are auto-loaded now.
- Removed previously deprecated EXT constant.
- Updated all classes to be written in PHP 5 style, with visibility declarations and no ``var`` usage for properties.
- - Moved error templates to "application/views/errors"
+ - Moved error templates to *application/views/errors/*.
+ - Moved the Log class to *application/core/*
- Global config files are loaded first, then environment ones. Environment config keys overwrite base ones, allowing to only set the keys we want changed per environment.
- Changed detection of ``$view_folder`` so that if it's not found in the current path, it will now also be searched for under the application folder.
- Path constants BASEPATH, APPPATH and VIEWPATH are now (internally) defined as absolute paths.
@@ -54,6 +56,7 @@ Release Date: Not Released
- Changed environment defaults to report all errors in *development* and only fatal ones in *testing*, *production* but only display them in *development*.
- Updated *ip_address* database field lengths from 16 to 45 for supporting IPv6 address on :doc:`Trackback Library <libraries/trackback>` and :doc:`Captcha Helper <helpers/captcha_helper>`.
- Removed *cheatsheets* and *quick_reference* PDFs from the documentation.
+ - Added availability checks where usage of dangerous functions like ``eval()`` and ``exec()`` is required.
- Helpers
@@ -65,35 +68,63 @@ Release Date: Not Released
- Added function ``date_range()`` that generates a list of dates between a specified period.
- ``create_captcha()`` accepts additional colors parameter, allowing for color customization.
- :doc:`URL Helper <helpers/url_helper>` changes include:
- - ``url_title()`` will now trim extra dashes from beginning and end.
- - ``anchor_popup()`` will now fill the *href* attribute with the URL and its JS code will return FALSE instead.
- - Added JS window name support to ``anchor_popup()`` function.
- - Added support (auto-detection) for HTTP/1.1 response code 303 in ``redirect()``.
- - "auto" method in ``redirect()`` now chooses the "refresh" method only on IIS servers, instead of all servers on Windows.
+ - Deprecated *separator* options **dash** and **underscore** for function :php:func:`url_title()` (they are only aliases for '-' and '_' respectively).
+ - :php:func:`url_title()` will now trim extra dashes from beginning and end.
+ - :php:func:`anchor_popup()` will now fill the *href* attribute with the URL and its JS code will return FALSE instead.
+ - Added JS window name support to the :php:func:`anchor_popup()` function.
+ - Added support (auto-detection) for HTTP/1.1 response code 303 in :php:func:`redirect()`.
+ - Changed :php:func:`redirect()` to only choose the **refresh** method only on IIS servers, instead of all servers on Windows (when **auto** is used).
- Added XHTML Basic 1.1 doctype to :doc:`HTML Helper <helpers/html_helper>`.
- - Changed ``humanize()`` to include a second param for the separator.
- - Refactored ``plural()`` and ``singular()`` to avoid double pluralization and support more words.
+ - :doc:`Inflector Helper <helpers/inflector_helper>` changes include:
+ - Changed :php:func:`humanize()` to allow passing an input separator as its second parameter.
+ - Refactored :php:func:`plural()` and :php:func:`singular()` to avoid double pluralization and support more words.
- Added an optional third parameter to ``force_download()`` that enables/disables sending the actual file MIME type in the Content-Type header (disabled by default).
- Added a work-around in ``force_download()`` for a bug Android <= 2.1, where the filename extension needs to be in uppercase.
- :doc:`Form Helper <helpers/form_helper>` changes include:
- - ``form_dropdown()`` will now also take an array for unity with other form helpers.
- - ``form_prep()`` is now **DEPRECATED** and only acts as an alias for :doc:`common function <general/common_functions>` ``html_escape()``.
- - ``do_hash()`` now uses PHP's native ``hash()`` function (supporting more algorithms) and is deprecated.
+ - :php:func:`form_dropdown()` will now also take an array for unity with other form helpers.
+ - :php:func:`form_prep()`'s second argument now only accepts a boolean value, which determines whether the value is escaped for a <textarea> or a regular <input> element.
+ - :doc:`Security Helper <helpers/security_helper>` changes include:
+ - :php:func:`do_hash()` now uses PHP's native ``hash()`` function (supporting more algorithms) and is deprecated.
+ - :php:func:`strip_image_tags()` is now an alias for the same method in the :doc:`Security Library <libraries/security>`.
- Removed previously deprecated helper function ``js_insert_smiley()`` from :doc:`Smiley Helper <helpers/smiley_helper>`.
- :doc:`File Helper <helpers/file_helper>` changes include:
- - ``set_realpath()`` can now also handle file paths as opposed to just directories.
- - Added an optional paramater to ``delete_files()`` to enable it to skip deleting files such as .htaccess and index.html.
- - ``read_file()`` is now a deprecated alias of ``file_get_contents()``.
- - :doc:`Security Helper <helpers/security_helper>` function ``strip_image_tags()`` is now an alias for the same method in the :doc:`Security Library <libraries/security>`.
- - Deprecated :doc:`String Helper <helpers/string_helper>` function ``repeater()`` - it's just an alias for PHP's native ``str_repeat()``.
+ - :php:func:`set_realpath()` can now also handle file paths as opposed to just directories.
+ - Added an optional paramater to :php:func:`delete_files()` to enable it to skip deleting files such as *.htaccess* and *index.html*.
+ - Deprecated function ``read_file()`` - it's just an alias for PHP's native ``file_get_contents()``.
+ - :doc:`String Helper <helpers/string_helper>` changes include:
+ - Deprecated function ``repeater()`` - it's just an alias for PHP's native ``str_repeat()``.
+ - Deprecated function ``trim_slashes()`` - it's just an alias for PHP's native ``trim()`` (with a slash as its second argument).
+ - Deprecated randomization type options **unique** and **encrypt** for funcion :php:func:`random_string()` (they are only aliases for **md5** and **sha1** respectively).
+ - :doc:`Directory Helper <helpers/directory_helper>` ``directory_map()`` will now append DIRECTORY_SEPARATOR to directory names in the returned array.
+ - Deprecated the :doc:`Email Helper <helpers/email_helper>` as its ``valid_email()``, ``send_email()`` functions are now only aliases for PHP native functions ``filter_var()`` and ``mail()`` respectively.
- Database
+ - Added **dsn** configuration setting for drivers that support DSN strings (PDO, PostgreSQL, Oracle, ODBC, CUBRID).
+ - Added **schema** configuration setting (defaults to *public*) for drivers that might need it (currently used by PostgreSQL and ODBC).
+ - Added subdrivers support (currently only used by PDO).
+ - Added an optional database name parameter to ``db_select()``.
+ - Added a constructor to the ``DB_result`` class and moved all driver-specific properties and logic out of the base ``DB_driver`` class to allow better abstraction.
+ - Removed ``protect_identifiers()`` and renamed internal method ``_protect_identifiers()`` to it instead - it was just an alias.
+ - Renamed internal method ``_escape_identifiers()`` to ``escape_identifiers()``.
+ - Updated ``escape_identifiers()`` to accept an array of fields as well as strings.
+ - MySQL and MySQLi drivers now require at least MySQL version 5.1.
+ - ``db_set_charset()`` now only requires one parameter (collation was only needed due to legacy support for MySQL versions prior to 5.1).
+ - Replaced the ``_error_message()`` and ``_error_number()`` methods with ``error()``, which returns an array containing the last database error code and message.
+ - Improved ``version()`` implementation so that drivers that have a native function to get the version number don't have to be defined in the core ``DB_driver`` class.
+ - Added ``unbuffered_row()`` method for getting a row without prefetching whole result (consume less memory).
+ - Added capability for packages to hold *database.php* config files.
+ - Added MySQL client compression support.
+ - Added encrypted connections support (for *mysql*, *sqlsrv* and PDO with *sqlsrv*).
+ - Removed :doc:`Loader Class <libraries/loader>` from Database error tracing to better find the likely culprit.
+ - Added support for SQLite3 database driver.
+ - Added Interbase/Firebird database support via the *ibase* driver.
+ - Added ODBC support for ``create_database()``, ``drop_database()`` and ``drop_table()`` in :doc:`Database Forge <database/forge>`.
- :doc:`Query Builder <database/query_builder>` changes include:
- Renamed the Active Record class to Query Builder to remove confusion with the Active Record design pattern.
- Added the ability to insert objects with ``insert_batch()``.
- Added new methods that return the SQL string of queries without executing them: ``get_compiled_select()``, ``get_compiled_insert()``, ``get_compiled_update()``, ``get_compiled_delete()``.
- - Added an optional parameter that allows to disable escaping (useful for custom fields) for methods ``join()``, ``order_by()``, ``where_in()``, ``or_where_in()``, ``where_not_in()``, ``or_where_not_in()``.
+ - Added an optional parameter that allows to disable escaping (useful for custom fields) for methods ``join()``, ``order_by()``, ``where_in()``, ``or_where_in()``, ``where_not_in()``, ``or_where_not_in()``, ``insert()``, ``insert_batch()``.
- Added support for ``join()`` with multiple conditions.
- Added support for *USING* in ``join()``.
- Changed ``limit()`` to ignore NULL values instead of always casting to integer.
@@ -104,13 +135,10 @@ Release Date: Not Released
- Server version checking is now done via ``mysqli::$server_info`` instead of running an SQL query.
- Added persistent connections support for PHP >= 5.3.
- Added support for ``backup()`` in :doc:`Database Utilities <database/utilities>`.
- - Added **dsn** configuration setting for drivers that support DSN strings (PDO, PostgreSQL, Oracle, ODBC, CUBRID).
- - Added **schema** configuration setting (defaults to *public*) for drivers that might need it (currently used by PostgreSQL and ODBC).
- - Improved PDO database support.
- - Added Interbase/Firebird database support via the *ibase* driver.
- - Added an optional database name parameter to ``db_select()``.
- - Replaced the ``_error_message()`` and ``_error_number()`` methods with ``error()``, which returns an array containing the last database error code and message.
- - Improved ``version()`` implementation so that drivers that have a native function to get the version number don't have to be defined in the core ``DB_driver`` class.
+ - Improved support of the PDO driver, including:
+ - Added support for ``create_database()``, ``drop_database()`` and ``drop_table()`` in :doc:`Database Forge <database/forge>`.
+ - Added support for ``list_fields()`` in :doc:`Database Results <database/results>`.
+ - Subdrivers are now isolated from each other instead of being in one large class.
- Improved support of the PostgreSQL driver, including:
- ``pg_version()`` is now used to get the database version number, when possible.
- Added ``db_set_charset()`` support.
@@ -119,13 +147,6 @@ Release Date: Not Released
- Added ``update_batch()`` support.
- Removed ``limit()`` and ``order_by()`` support for *UPDATE* and *DELETE* queries as PostgreSQL does not support those features.
- Added a work-around for dead persistent connections to be re-created after a database restart.
- - Added a constructor to the ``DB_result`` class and moved all driver-specific properties and logic out of the base ``DB_driver`` class to allow better abstraction.
- - Removed ``protect_identifiers()`` and renamed internal method ``_protect_identifiers()`` to it instead - it was just an alias.
- - Renamed internal method ``_escape_identifiers()`` to ``escape_identifiers()``.
- - Updated ``escape_identifiers()`` to accept an array of fields as well as strings.
- - MySQL and MySQLi drivers now require at least MySQL version 5.1.
- - ``db_set_charset()`` now only requires one parameter (collation was only needed due to legacy support for MySQL versions prior to 5.1).
- - Added support for SQLite3 database driver.
- Improved support of the CUBRID driver, including:
- Added DSN string support.
- Added persistent connections support.
@@ -145,15 +166,16 @@ Release Date: Not Released
- Improved support of the SQLite driver, including:
- Added support for ``replace()`` in :doc:`Query Builder <database/query_builder>`.
- Added support for ``drop_table()`` in :doc:`Database Forge <database/forge>`.
- - Added ODBC support for ``create_database()``, ``drop_database()`` and ``drop_table()`` in :doc:`Database Forge <database/forge>`.
- - Added PDO support for ``create_database()``, ``drop_database()`` and ``drop_table()`` in :doc:`Database Forge <database/forge>`.
- - Added ``unbuffered_row()`` method for getting a row without prefetching whole result (consume less memory).
- - Added PDO support for ``list_fields()`` in :doc:`Database Results <database/results>`.
- - Added capability for packages to hold *database.php* config files
- - Added subdrivers support (currently only used by PDO).
- - Added MySQL client compression support.
- - Added encrypted connections support (for *mysql*, *sqlsrv* and PDO with *sqlsrv*).
- - Removed :doc:`Loader Class <libraries/loader>` from Database error tracing to better find the likely culprit.
+ - :doc:`Database Forge <database/forge>` changes include:
+ - Added an optional second parameter to ``drop_table()`` that allows adding the **IF EXISTS** condition, which is no longer the default.
+ - Added support for passing a custom database object to the loader.
+ - Deprecated ``add_column()``'s third method. *AFTER* clause should now be added to the field definition array instead.
+ - Added support for usage of the *FIRST* clause in ``add_column()`` for MySQL and CUBRID.
+ - Overall improved support for all of the drivers.
+ - :doc:`Database Utility <database/utilities>` chages include:
+ - Added support for passing a custom database object to the loader.
+ - Modified the class to no longer extend :doc:`Database Forge <database/forge>`, which has been a deprecated behavior for awhile.
+ - Overall improved support for all of the drivers.
- Libraries
@@ -182,7 +204,7 @@ Release Date: Not Released
- Added method ``remove()`` to remove a cart item, updating with quantity of 0 seemed like a hack but has remained to retain compatibility.
- Added method ``get_item()`` to enable retrieving data for a single cart item.
- :doc:`Image Manipulation library <libraries/image_lib>` changes include:
- - The initialize() method now only sets existing class properties.
+ - The ``initialize()`` method now only sets existing class properties.
- Added support for 3-length hex color values for *wm_font_color* and *wm_shadow_color* properties, as well as validation for them.
- Class properties *wm_font_color*, *wm_shadow_color* and *wm_use_drop_shadow* are now protected, to avoid breaking the ``text_watermark()`` method if they are set manually after initialization.
- If property *maintain_ratio* is set to TRUE, ``image_reproportion()`` now doesn't need both width and height to be specified.
@@ -227,13 +249,20 @@ Release Date: Not Released
- Added support for hashing algorithms other than SHA1 and MD5.
- Removed previously deprecated ``sha1()`` method.
- Changed :doc:`Language Library <libraries/language>` method ``load()`` to filter the language name with ``ctype_digit()``.
+ - :doc:`Profiler Library <general/profiling>` now also displays database object names.
- :doc:`Migration Library <libraries/migration>` changes include:
- Added support for timestamp-based migrations (enabled by default)
- Added ``$config['migration_style']`` to allow switching between sequential migrations and timestamp migrations
- Core
- - Changed private methods in the :doc:`URI Library <libraries/uri>` to protected so MY_URI can override them.
+ - :doc:`URI Library <libraries/uri>` changes include:
+ - Changed private methods to protected so that MY_URI can override them.
+ - Renamed internal method ``_parse_cli_args()`` to ``_parse_argv()``.
+ - Renamed internal method ``_detect_uri()`` to ``_parse_request_uri()``.
+ - Changed ``_parse_request_uri()`` to accept absolute URIs for compatibility with HTTP/1.1 as per `RFC2616 <http://www.ietf.org/rfc/rfc2616.txt>`.
+ - Added protected method ``_parse_query_string()`` to URI paths in the the **QUERY_STRING** value, like ``_parse_request_uri()`` does.
+ - Changed ``_fetch_uri_string()`` to try the **PATH_INFO** variable first when auto-detecting.
- Removed ``CI_CORE`` boolean constant from *CodeIgniter.php* (no longer Reactor and Core versions).
- :doc:`Loader Library <libraries/loader>` changes include:
- Added method ``get_vars()`` to the Loader to retrieve all variables loaded with ``$this->load->vars()``.
@@ -245,15 +274,17 @@ Release Date: Not Released
- :doc:`Input Library <libraries/input>` changes include:
- Added ``method()`` to retrieve ``$_SERVER['REQUEST_METHOD']``.
- Added support for arrays and network addresses (e.g. 192.168.1.1/24) for use with the *proxy_ips* setting.
+ - Added method ``input_stream()`` to aid in using **php://input** stream data such as one passed via PUT, DELETE and PATCH requests.
- Changed method ``valid_ip()`` to use PHP's native ``filter_var()`` function.
- Changed internal method ``_sanitize_globals()`` to skip enforcing reversal of *register_globals* in PHP 5.4+, where this functionality no longer exists.
- Changed methods ``get()``, ``post()``, ``get_post()``, ``cookie()``, ``server()``, ``user_agent()`` to return NULL instead of FALSE when no value is found.
- :doc:`Common functions <general/common_functions>` changes include:
- - Added function ``get_mimes()`` to return the *config/mimes.php* array.
- - Added support for HTTP code 303 ("See Other") in ``set_status_header()``.
- - Removed redundant conditional to determine HTTP server protocol in ``set_status_header()``.
+ - Added function :php:func:`get_mimes()` to return the *application/config/mimes.php* array.
+ - Added support for HTTP code 303 ("See Other") in :php:func:`set_status_header()`.
+ - Removed redundant conditional to determine HTTP server protocol in :php:func:`set_status_header()`.
- Changed ``_exception_handler()`` to respect php.ini *display_errors* setting.
- - Added function ``is_https()`` to check if a secure connection is used.
+ - Added function :php:func:`is_https()` to check if a secure connection is used.
+ - Added function :php:func:`function_usable()` to check if a function exists and is not disabled by `Suhosin <http://www.hardened-php.net/suhosin/>`.
- Added support for HTTP-Only cookies with new config option *cookie_httponly* (default FALSE).
- Renamed method ``_call_hook()`` to ``call_hook()`` in the :doc:`Hooks Library <general/hooks>`.
- :doc:`Output Library <libraries/output>` changes include:
@@ -267,6 +298,9 @@ Release Date: Not Released
- Added method ``strip_image_tags()``.
- Added ``$config['csrf_regeneration']``, which makes token regeneration optional.
- Added ``$config['csrf_exclude_uris']``, which allows you list URIs which will not have the CSRF validation methods run.
+ - :doc:`URI Routing <general/routing>` changes include:
+ - Added possibility to route requests using callbacks.
+ - Added possibility to use dashes in the controller and method URI segments (translated to underscores).
Bug fixes for 3.0
------------------
@@ -403,7 +437,14 @@ Bug fixes for 3.0
- Fixed a bug (#142) - :doc:`Form Helper <helpers/form_helper>` function ``form_dropdown()`` didn't escape HTML entities in option values.
- Fixed a bug (#50) - :doc:`Session Library <libraries/sessions>` unnecessarily stripped slashed from serialized data, making it impossible to read objects in a namespace.
- Fixed a bug (#658) - :doc:`Routing <general/routing>` wildcard **:any** didn't work as advertised and matched multiple URI segments instead of all characters within a single segment.
-- Fixed a bug (#1938) - :doc:`Email <libraries/email>` where the email library removed multiple spaces inside a pre-formatted plain text message.
+- Fixed a bug (#1938) - :doc:`Email Library <libraries/email>` removed multiple spaces inside a pre-formatted plain text message.
+- Fixed a bug (#388, #705) - :doc:`URI Library <libraries/uri>` didn't apply URL-decoding to URI segments that it got from **REQUEST_URI** and/or **QUERY_STRING**.
+- Fixed a bug (#122) - :doc:`URI Library <libraries/uri>` method ``ruri_string()`` didn't include a directory if one is used.
+- Fixed a bug - :doc:`Routing Library <general/routing>` didn't properly handle *default_controller* in a subdirectory when a method is also specified.
+- Fixed a bug (#953) - :doc:`post_controller_constructor hook <general/hooks>` wasn't called with a *404_override*.
+- Fixed a bug (#1220) - :doc:`Profiler Library <general/profiling>` didn't display information for database objects that are instantiated inside models.
+- Fixed a bug (#1978) - :doc:`Directory Helper <helpers/directory_helper>` function :php:func:`directory_map()`'s return array didn't make a distinction between directories and file indexes when a directory with a numeric name is present.
+- Fixed a bug (#777) - :doc:`Loader Library <libraries/loader>` didn't look for helper extensions in added package paths.
Version 2.1.3
=============
diff --git a/user_guide_src/source/contributing/index.rst b/user_guide_src/source/contributing/index.rst
index 2ede0e6e5..0771a4192 100644
--- a/user_guide_src/source/contributing/index.rst
+++ b/user_guide_src/source/contributing/index.rst
@@ -102,4 +102,4 @@ it.
By signing your work in this manner, you certify to a "Developer's Certificate
or Origin". The current version of this certificate is in the :doc:`/DCO` file
-in the root of this documentation.
+in the root of this documentation. \ No newline at end of file
diff --git a/user_guide_src/source/database/forge.rst b/user_guide_src/source/database/forge.rst
index bf17e2918..ca904ed00 100644
--- a/user_guide_src/source/database/forge.rst
+++ b/user_guide_src/source/database/forge.rst
@@ -2,7 +2,7 @@
Database Forge Class
####################
-The Database Forge Class contains functions that help you manage your
+The Database Forge Class contains methods that help you manage your
database.
.. contents:: Table of Contents
@@ -18,13 +18,25 @@ Load the Forge Class as follows::
$this->load->dbforge()
-Once initialized you will access the functions using the $this->dbforge
+You can also pass another database object to the DB Forge loader, in case
+the database you want to manage isn't the default one::
+
+ $this->myforge = $this->load->dbforge($this->other_db, TRUE);
+
+In the above example, we're passing a custom database object as the first
+parameter and then tell it to return the dbforge object, instead of
+assigning it directly to ``$this->dbforge``.
+
+.. note:: Both of the parameters can be used individually, just pass an empty
+ value as the first one if you wish to skip it.
+
+Once initialized you will access the methods using the ``$this->dbforge``
object::
- $this->dbforge->some_function()
+ $this->dbforge->some_method();
$this->dbforge->create_database('db_name')
-============================================
+==========================================
Permits you to create the database specified in the first parameter.
Returns TRUE/FALSE based on success or failure::
@@ -108,13 +120,13 @@ Additionally, the following key/values can be used:
After the fields have been defined, they can be added using
-$this->dbforge->add_field($fields); followed by a call to the
-create_table() function.
+``$this->dbforge->add_field($fields);`` followed by a call to the
+``create_table()`` method.
$this->dbforge->add_field()
-----------------------------
+---------------------------
-The add fields function will accept the above array.
+The add fields method will accept the above array.
Passing strings as fields
-------------------------
@@ -193,13 +205,15 @@ into the definition
Dropping a table
================
-Executes a DROP TABLE sql
+Execute a DROP TABLE statement and optionally add an IF EXISTS clause.
::
+ // Produces: DROP TABLE table_name
$this->dbforge->drop_table('table_name');
- // gives DROP TABLE IF EXISTS table_name
+ // Produces: DROP TABLE IF EXISTS table_name
+ $this->dbforge->drop_table('table_name');
Renaming a table
================
@@ -217,9 +231,9 @@ Modifying Tables
****************
$this->dbforge->add_column()
-=============================
+============================
-The add_column() function is used to modify an existing table. It
+The ``add_column()`` method is used to modify an existing table. It
accepts the same field array as above, and can be used for an unlimited
number of additional fields.
@@ -229,18 +243,25 @@ number of additional fields.
'preferences' => array('type' => 'TEXT')
);
$this->dbforge->add_column('table_name', $fields);
- // gives ALTER TABLE table_name ADD preferences TEXT
+ // Executes: ALTER TABLE table_name ADD preferences TEXT
-An optional third parameter can be used to specify which existing column
-to add the new column after.
+If you are using MySQL or CUBIRD, then you can take advantage of their
+AFTER and FIRST clauses to position the new column.
-::
+Examples::
- $this->dbforge->add_column('table_name', $fields, 'after_field');
+ // Will place the new column after the `another_field` column:
+ $fields = array(
+ 'preferences' => array('type' => 'TEXT', 'after' => 'another_field')
+ );
+ // Will place the new column at the start of the table definition:
+ $fields = array(
+ 'preferences' => array('type' => 'TEXT', 'first' => TRUE)
+ );
$this->dbforge->drop_column()
-==============================
+=============================
Used to remove a column from a table.
@@ -250,9 +271,9 @@ Used to remove a column from a table.
$this->dbforge->modify_column()
-================================
+===============================
-The usage of this function is identical to add_column(), except it
+The usage of this method is identical to ``add_column()``, except it
alters an existing column rather than adding a new one. In order to
change the name you can add a "name" key into the field defining array.
diff --git a/user_guide_src/source/database/utilities.rst b/user_guide_src/source/database/utilities.rst
index 4e83929b2..06ecb2da1 100644
--- a/user_guide_src/source/database/utilities.rst
+++ b/user_guide_src/source/database/utilities.rst
@@ -2,7 +2,7 @@
Database Utility Class
######################
-The Database Utility Class contains functions that help you manage your
+The Database Utility Class contains methods that help you manage your
database.
.. contents:: Table of Contents
@@ -22,12 +22,24 @@ Load the Utility Class as follows::
$this->load->dbutil()
-Once initialized you will access the functions using the $this->dbutil
+You can also pass another database object to the DB Utility loader, in case
+the database you want to manage isn't the default one::
+
+ $this->myutil = $this->load->dbutil($this->other_db, TRUE);
+
+In the above example, we're passing a custom database object as the first
+parameter and then tell it to return the dbutil object, instead of
+assigning it directly to ``$this->dbutil``.
+
+.. note:: Both of the parameters can be used individually, just pass an empty
+ value as the first one if you wish to skip it.
+
+Once initialized you will access the methods using the ``$this->dbutil``
object::
- $this->dbutil->some_function()
+ $this->dbutil->some_method()
-$this->dbutil->list_databases()
+$this->dbutil->list_databases();
================================
Returns an array of database names::
@@ -40,7 +52,7 @@ Returns an array of database names::
}
$this->dbutil->database_exists();
-==================================
+=================================
Sometimes it's helpful to know whether a particular database exists.
Returns a boolean TRUE/FALSE. Usage example::
@@ -50,13 +62,11 @@ Returns a boolean TRUE/FALSE. Usage example::
// some code...
}
-Note: Replace *database_name* with the name of the table you are
-looking for. This function is case sensitive.
+.. note:: Replace *database_name* with the name of the table you are
+ looking for. This method is case sensitive.
$this->dbutil->optimize_table('table_name');
-==============================================
-
-.. note:: This features is only available for MySQL/MySQLi databases.
+============================================
Permits you to optimize a table using the table name specified in the
first parameter. Returns TRUE/FALSE based on success or failure::
@@ -66,12 +76,11 @@ first parameter. Returns TRUE/FALSE based on success or failure::
echo 'Success!';
}
-.. note:: Not all database platforms support table optimization.
+.. note:: Not all database platforms support table optimization. It is
+ mostly for use with MySQL.
$this->dbutil->repair_table('table_name');
-============================================
-
-.. note:: This features is only available for MySQL/MySQLi databases.
+==========================================
Permits you to repair a table using the table name specified in the
first parameter. Returns TRUE/FALSE based on success or failure::
@@ -86,8 +95,6 @@ first parameter. Returns TRUE/FALSE based on success or failure::
$this->dbutil->optimize_database();
====================================
-.. note:: This features is only available for MySQL/MySQLi databases.
-
Permits you to optimize the database your DB class is currently
connected to. Returns an array containing the DB status messages or
FALSE on failure.
@@ -101,13 +108,14 @@ FALSE on failure.
print_r($result);
}
-.. note:: Not all database platforms support table optimization.
+.. note:: Not all database platforms support table optimization. It
+ it is mostly for use with MySQL.
-$this->dbutil->csv_from_result($db_result)
-=============================================
+$this->dbutil->csv_from_result($db_result);
+===========================================
Permits you to generate a CSV file from a query result. The first
-parameter of the function must contain the result object from your
+parameter of the method must contain the result object from your
query. Example::
$this->load->dbutil();
@@ -127,12 +135,12 @@ is used as the enclosure. Example::
echo $this->dbutil->csv_from_result($query, $delimiter, $newline, $enclosure);
-.. important:: This function will NOT write the CSV file for you. It
+.. important:: This method will NOT write the CSV file for you. It
simply creates the CSV layout. If you need to write the file
use the :doc:`File Helper <../helpers/file_helper>`.
-$this->dbutil->xml_from_result($db_result)
-=============================================
+$this->dbutil->xml_from_result($db_result);
+===========================================
Permits you to generate an XML file from a query result. The first
parameter expects a query result object, the second may contain an
@@ -151,17 +159,17 @@ optional array of config parameters. Example::
echo $this->dbutil->xml_from_result($query, $config);
-.. important:: This function will NOT write the XML file for you. It
+.. important:: This method will NOT write the XML file for you. It
simply creates the XML layout. If you need to write the file
use the :doc:`File Helper <../helpers/file_helper>`.
-$this->dbutil->backup()
-=======================
+$this->dbutil->backup();
+========================
Permits you to backup your full database or individual tables. The
backup data can be compressed in either Zip or Gzip format.
-.. note:: This features is only available for MySQL and Interbase/Firebird databases.
+.. note:: This feature is only available for MySQL and Interbase/Firebird databases.
.. note:: For Interbase/Firebird databases, the backup file name is the only parameter.
@@ -196,16 +204,16 @@ Setting Backup Preferences
--------------------------
Backup preferences are set by submitting an array of values to the first
-parameter of the backup function. Example::
+parameter of the ``backup()`` method. Example::
$prefs = array(
- 'tables' => array('table1', 'table2'), // Array of tables to backup.
- 'ignore' => array(), // List of tables to omit from the backup
- 'format' => 'txt', // gzip, zip, txt
- 'filename' => 'mybackup.sql', // File name - NEEDED ONLY WITH ZIP FILES
- 'add_drop' => TRUE, // Whether to add DROP TABLE statements to backup file
- 'add_insert' => TRUE, // Whether to add INSERT data to backup file
- 'newline' => "\n" // Newline character used in backup file
+ 'tables' => array('table1', 'table2'), // Array of tables to backup.
+ 'ignore' => array(), // List of tables to omit from the backup
+ 'format' => 'txt', // gzip, zip, txt
+ 'filename' => 'mybackup.sql', // File name - NEEDED ONLY WITH ZIP FILES
+ 'add_drop' => TRUE, // Whether to add DROP TABLE statements to backup file
+ 'add_insert' => TRUE, // Whether to add INSERT data to backup file
+ 'newline' => "\n" // Newline character used in backup file
);
$this->dbutil->backup($prefs);
diff --git a/user_guide_src/source/general/alternative_php.rst b/user_guide_src/source/general/alternative_php.rst
index 4dc857a50..418d2e6eb 100644
--- a/user_guide_src/source/general/alternative_php.rst
+++ b/user_guide_src/source/general/alternative_php.rst
@@ -17,12 +17,12 @@ Automatic Short Tag Support
work on your server it might be that "short tags" are disabled in your
PHP ini file. CodeIgniter will optionally rewrite short tags on-the-fly,
allowing you to use that syntax even if your server doesn't support it.
- This feature can be enabled in your config/config.php file.
+ This feature can be enabled in your *config/config.php* file.
Please note that if you do use this feature, if PHP errors are
encountered in your **view files**, the error message and line number
will not be accurately shown. Instead, all errors will be shown as
-eval() errors.
+``eval()`` errors.
Alternative Echos
=================
@@ -39,13 +39,13 @@ Alternative Control Structures
==============================
Controls structures, like if, for, foreach, and while can be written in
-a simplified format as well. Here is an example using foreach::
+a simplified format as well. Here is an example using ``foreach``::
<ul>
<?php foreach ($todo as $item): ?>
- <li><?=$item?></li>
+ <li><?=$item?></li>
<?php endforeach; ?>
@@ -60,17 +60,16 @@ Also notice that instead of using a semicolon after each structure
Here is another example, using ``if``/``elseif``/``else``. Notice the colons::
- <?php if ($username == 'sally'): ?>
+ <?php if ($username === 'sally'): ?>
- <h3>Hi Sally</h3>
+ <h3>Hi Sally</h3>
- <?php elseif ($username == 'joe'): ?>
+ <?php elseif ($username === 'joe'): ?>
- <h3>Hi Joe</h3>
+ <h3>Hi Joe</h3>
<?php else: ?>
- <h3>Hi unknown user</h3>
-
- <?php endif; ?>
+ <h3>Hi unknown user</h3>
+ <?php endif; ?> \ No newline at end of file
diff --git a/user_guide_src/source/general/ancillary_classes.rst b/user_guide_src/source/general/ancillary_classes.rst
index f7c87011b..a4befc7b3 100644
--- a/user_guide_src/source/general/ancillary_classes.rst
+++ b/user_guide_src/source/general/ancillary_classes.rst
@@ -7,31 +7,35 @@ controllers but have the ability to utilize all of CodeIgniter's
resources. This is easily possible as you'll see.
get_instance()
-===============
+==============
-**Any class that you instantiate within your controller functions can
+.. php:function:: get_instance()
+
+ :returns: object of class CI_Controller
+
+**Any class that you instantiate within your controller methods can
access CodeIgniter's native resources** simply by using the
-get_instance() function. This function returns the main CodeIgniter
-object.
+``get_instance()`` function. This function returns the main
+CodeIgniter object.
-Normally, to call any of the available CodeIgniter functions requires
-you to use the $this construct::
+Normally, to call any of the available CodeIgniter methods requires
+you to use the ``$this`` construct::
$this->load->helper('url');
$this->load->library('session');
$this->config->item('base_url');
// etc.
-$this, however, only works within your controllers, your models, or your
-views. If you would like to use CodeIgniter's classes from within your
-own custom classes you can do so as follows:
+``$this``, however, only works within your controllers, your models,
+or your views. If you would like to use CodeIgniter's classes from
+within your own custom classes you can do so as follows:
First, assign the CodeIgniter object to a variable::
$CI =& get_instance();
Once you've assigned the object to a variable, you'll use that variable
-*instead* of $this::
+*instead* of ``$this``::
$CI =& get_instance();
@@ -40,10 +44,45 @@ Once you've assigned the object to a variable, you'll use that variable
$CI->config->item('base_url');
// etc.
-.. note:: You'll notice that the above get_instance() function is being
+.. note:: You'll notice that the above get_instance() ``function`` is being
passed by reference::
$CI =& get_instance();
This is very important. Assigning by reference allows you to use the
original CodeIgniter object rather than creating a copy of it.
+
+Furthermore, if you'll be using ``get_intance()`` inside anoter class,
+then it would be better if you assign it to a property. This way, you
+won't need to call ``get_instance()`` in every single method.
+
+Example::
+
+class Example {
+
+ protected $CI;
+
+ // We'll use a constructor, as you can't directly call a function
+ // from a property definition.
+ public function __construct()
+ {
+ // Assign the CodeIgniter super-object
+ $this->CI =& get_instance();
+ }
+
+ public function foo()
+ {
+ $this->CI->load->helper('url');
+ redirect();
+ }
+
+ public function bar()
+ {
+ $this->CI->config_item('base_url');
+ }
+
+}
+
+In the above example, both methods ``foo()`` and ``bar()`` will work
+after you instantiate the Example class, without the need to call
+``get_instance()`` in each of them. \ No newline at end of file
diff --git a/user_guide_src/source/general/autoloader.rst b/user_guide_src/source/general/autoloader.rst
index 8ecc13cb6..e5cec723b 100644
--- a/user_guide_src/source/general/autoloader.rst
+++ b/user_guide_src/source/general/autoloader.rst
@@ -9,15 +9,15 @@ application you should consider auto-loading them for convenience.
The following items can be loaded automatically:
-- Classes found in the "libraries" folder
-- Helper files found in the "helpers" folder
-- Custom config files found in the "config" folder
-- Language files found in the "system/language" folder
-- Models found in the "models" folder
+- Classes found in the *libraries/* directory
+- Helper files found in the *helpers/* directory
+- Custom config files found in the *config/* directory
+- Language files found in the *system/language/* directory
+- Models found in the *models/* folder
-To autoload resources, open the application/config/autoload.php file and
-add the item you want loaded to the autoload array. You'll find
-instructions in that file corresponding to each type of item.
+To autoload resources, open the *application/config/autoload.php*
+file and add the item you want loaded to the autoload array. You'll
+find instructions in that file corresponding to each type of item.
.. note:: Do not include the file extension (.php) when adding items to
- the autoload array.
+ the autoload array. \ No newline at end of file
diff --git a/user_guide_src/source/general/caching.rst b/user_guide_src/source/general/caching.rst
index bf6ed50f6..c40f652ac 100644
--- a/user_guide_src/source/general/caching.rst
+++ b/user_guide_src/source/general/caching.rst
@@ -23,36 +23,38 @@ will be retrieved and sent to the requesting user's browser. If it has
expired, it will be deleted and refreshed before being sent to the
browser.
-Note: The Benchmark tag is not cached so you can still view your page
-load speed when caching is enabled.
+.. note: The Benchmark tag is not cached so you can still view your page
+ load speed when caching is enabled.
Enabling Caching
================
To enable caching, put the following tag in any of your controller
-functions::
+methods::
- $this->output->cache(n);
+ $this->output->cache($n);
-Where n is the number of **minutes** you wish the page to remain cached
-between refreshes.
+Where ``$n`` is the number of **minutes** you wish the page to remain
+cached between refreshes.
-The above tag can go anywhere within a function. It is not affected by
+The above tag can go anywhere within a method. It is not affected by
the order that it appears, so place it wherever it seems most logical to
you. Once the tag is in place, your pages will begin being cached.
.. important:: Because of the way CodeIgniter stores content for output,
- caching will only work if you are generating display for your controller
- with a :doc:`view <./views>`.
+ caching will only work if you are generating display for your
+ controller with a :doc:`view <./views>`.
.. note:: Before the cache files can be written you must set the file
- permissions on your application/cache folder such that it is writable.
+ permissions on your *application/cache/* directory such that
+ it is writable.
Deleting Caches
===============
If you no longer wish to cache a file you can remove the caching tag and
-it will no longer be refreshed when it expires. Note: Removing the tag
-will not delete the cache immediately. It will have to expire normally.
-If you need to remove it earlier you will need to manually delete it
-from your cache folder.
+it will no longer be refreshed when it expires.
+
+.. note:: Removing the tag will not delete the cache immediately. It will
+ have to expire normally. If you need to remove it earlier you
+ will need to manually delete it from your cache directory. \ No newline at end of file
diff --git a/user_guide_src/source/general/cli.rst b/user_guide_src/source/general/cli.rst
index 649d5d548..998d2a907 100644
--- a/user_guide_src/source/general/cli.rst
+++ b/user_guide_src/source/general/cli.rst
@@ -21,7 +21,7 @@ Why run via the command-line?
There are many reasons for running CodeIgniter from the command-line,
but they are not always obvious.
-- Run your cron-jobs without needing to use wget or curl
+- Run your cron-jobs without needing to use *wget* or *curl*
- Make your cron-jobs inaccessible from being loaded in the URL by
checking for ``$this->input->is_cli_request()``
- Make interactive "tasks" that can do things like set permissions,
@@ -44,9 +44,8 @@ in it::
echo "Hello {$to}!".PHP_EOL;
}
}
- ?>
-Then save the file to your application/controllers/ folder.
+Then save the file to your *application/controllers/* folder.
Now normally you would visit the your site using a URL similar to this::
@@ -60,19 +59,20 @@ in Windows and navigate to our CodeIgniter project.
$ cd /path/to/project;
$ php index.php tools message
-If you did it right, you should see Hello World!.
+If you did it right, you should see *Hello World!* printed.
.. code-block:: bash
$ php index.php tools message "John Smith"
Here we are passing it a argument in the same way that URL parameters
-work. "John Smith" is passed as a argument and output is: Hello John
-Smith!.
+work. "John Smith" is passed as a argument and output is::
+
+ Hello John Smith!
That's it!
==========
That, in a nutshell, is all there is to know about controllers on the
command line. Remember that this is just a normal controller, so routing
-and _remap works fine.
+and ``_remap()`` works fine. \ No newline at end of file
diff --git a/user_guide_src/source/general/common_functions.rst b/user_guide_src/source/general/common_functions.rst
index f3d48ac91..66dabd95e 100644
--- a/user_guide_src/source/general/common_functions.rst
+++ b/user_guide_src/source/general/common_functions.rst
@@ -6,59 +6,119 @@ CodeIgniter uses a few functions for its operation that are globally
defined, and are available to you at any point. These do not require
loading any libraries or helpers.
-is_php('version_number')
-========================
+is_php()
+========
-is_php() determines of the PHP version being used is greater than the
-supplied version_number.
+.. php:function:: is_php($version = '5.3.0')
-::
+ :param string $version: Version number
+ :returns: bool
- if (is_php('5.3.0'))
+Determines of the PHP version being used is greater than the
+supplied version number.
+
+Example::
+
+ if (is_php('5.3'))
{
- $str = quoted_printable_encode($str);
+ $str = quoted_printable_encode($str);
}
Returns boolean TRUE if the installed version of PHP is equal to or
greater than the supplied version number. Returns FALSE if the installed
version of PHP is lower than the supplied version number.
-is_really_writable('path/to/file')
-==================================
+is_really_writable()
+====================
+
+.. php:function:: is_really_writeable($file)
-is_writable() returns TRUE on Windows servers when you really can't
+ :param string $file: File path
+ :returns: bool
+
+``is_writable()`` returns TRUE on Windows servers when you really can't
write to the file as the OS reports to PHP as FALSE only if the
-read-only attribute is marked. This function determines if a file is
-actually writable by attempting to write to it first. Generally only
-recommended on platforms where this information may be unreliable.
+read-only attribute is marked.
+
+This function determines if a file is actually writable by attempting
+to write to it first. Generally only recommended on platforms where
+this information may be unreliable.
-::
+Example::
if (is_really_writable('file.txt'))
{
- echo "I could write to this if I wanted to";
+ echo "I could write to this if I wanted to";
}
else
{
- echo "File is not writable";
+ echo "File is not writable";
}
-config_item('item_key')
-=======================
+config_item()
+=============
+
+.. php:function:: config_item($key)
+
+ :param string $key: Config item key
+ :returns: mixed
+
+The :doc:`Config Library <../libraries/config>` is the preferred way of
+accessing configuration information, however ``config_item()`` can be used
+to retrieve single keys. See :doc:`Config Library <../libraries/config>`
+documentation for more information.
+
+.. important:: This function only returns values set in your configuration
+ files. It does not take into account config values that are
+ dynamically set at runtime.
+
+show_error()
+============
-The :doc:`Config library <../libraries/config>` is the preferred way of
-accessing configuration information, however config_item() can be used
-to retrieve single keys. See Config library documentation for more
-information.
+.. php:function:: show_error($message, $status_code, $heading = 'An Error Was Encountered')
-show_error('message'), show_404('page'), log_message('level', 'message')
-========================================================================
+ :param mixed $message: Error message
+ :param int $status_code: HTTP Response status code
+ :param string $heading: Error page heading
+ :returns: void
-These are each outlined on the :doc:`Error Handling <errors>` page.
+This function calls ``CI_Exception::show_error()``. For more info,
+please see the :doc:`Error Handling <errors>` documentation.
-set_status_header(code, 'text')
+show_404()
+==========
+
+.. php:function:: show_404($page = '', $log_error = TRUE)
+
+ :param string $page: URI string
+ :param bool $log_error: Whether to log the error
+ :returns: void
+
+This function calls ``CI_Exception::show_404()``. For more info,
+please see the :doc:`Error Handling <errors>` documentation.
+
+log_message()
+=============
+
+.. php:function:: log_message($level = 'error', $message, $php_error = FALSE)
+
+ :param string $level: Log level
+ :param string $message: Message to log
+ :param bool $php_error: Whether we're loggin a native PHP error message
+ :returns: void
+
+This function is an alias for ``CI_Log::write_log()``. For more info,
+please see the :doc:`Error Handling <errors>` documentation.
+
+set_status_header()
===============================
+.. php:function:: set_status_header($code, $text = '')
+
+ :param int $code: HTTP Reponse status code
+ :param string $text: A custom message to set with the status code
+ :returns: void
+
Permits you to manually set a server status header. Example::
set_status_header(401);
@@ -67,26 +127,71 @@ Permits you to manually set a server status header. Example::
`See here <http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html>`_ for
a full list of headers.
-remove_invisible_characters($str)
-=================================
+remove_invisible_characters()
+=============================
+
+.. php:function:: remove_invisible_characters($str, $url_encoded = TRUE)
+
+ :param string $str: Input string
+ :param bool $url_encoded: Whether to remove URL-encoded characters as well
+ :returns: string
-This function prevents inserting null characters between ascii
+This function prevents inserting NULL characters between ASCII
characters, like Java\\0script.
-html_escape($mixed)
-===================
+Example::
+
+ remove_invisible_characters('Java\\0script');
+ // Returns: 'Javascript'
+
+html_escape()
+=============
-This function provides short cut for ``htmlspecialchars()`` function. It
-accepts string and array. To prevent Cross Site Scripting (XSS), it is
-very useful.
+.. php:function:: html_escape($var)
+
+ :param mixed $var: Variable to escape
+ (string or array)
+ :returns: mixed
+
+This function acts as an alias for PHP's native ``htmlspecialchars()``
+function, with the advantage of being able to accept an array of strings.
+
+It is useful in preventing Cross Site Scripting (XSS).
get_mimes()
===========
-This function returns the MIMEs array *from config/mimes.php*.
+.. php:function:: get_mimes()
+
+ :returns: array
+
+This function returns a *reference* to the MIMEs array from
+*application/config/mimes.php*.
is_https()
==========
+.. php:function:: is_https()
+
+ :returns: bool
+
Returns TRUE if a secure (HTTPS) connection is used and FALSE
-in any other case (including non-HTTP requests). \ No newline at end of file
+in any other case (including non-HTTP requests).
+
+function_usable($function_name)
+===============================
+
+.. php:function:: function_usable($function_name)
+
+ :param string $function_name: Function name
+ :returns: bool
+
+Returns TRUE if a function exists and is usable, FALSE otherwise.
+
+This function runs a ``function_exists()`` check and if the
+`Suhosin extension <http://www.hardened-php.net/suhosin/>` is loaded,
+checks if it doesn't disable the function being checked.
+
+It is useful if you want to check for the availability of functions
+such as ``eval()`` and ``exec()``, which are dangerous and might be
+disabled on servers with highly restrictive security policies. \ No newline at end of file
diff --git a/user_guide_src/source/general/controllers.rst b/user_guide_src/source/general/controllers.rst
index 6e5079419..729b08417 100644
--- a/user_guide_src/source/general/controllers.rst
+++ b/user_guide_src/source/general/controllers.rst
@@ -38,50 +38,49 @@ in it::
echo 'Hello World!';
}
}
- ?>
-Then save the file to your application/controllers/ folder.
+Then save the file to your *application/controllers/* directory.
Now visit the your site using a URL similar to this::
example.com/index.php/blog/
-If you did it right, you should see Hello World!.
+If you did it right, you should see:
-Note: Class names must start with an uppercase letter. In other words,
-this is valid::
+ Hello World!
+
+.. important:: Class names must start with an uppercase letter.
+
+This is valid::
<?php
class Blog extends CI_Controller {
}
- ?>
-
This is **not** valid::
<?php
class blog extends CI_Controller {
}
- ?>
Also, always make sure your controller extends the parent controller
-class so that it can inherit all its functions.
+class so that it can inherit all its methods.
-Functions
-=========
+Methods
+=======
-In the above example the function name is index(). The "index" function
+In the above example the method name is ``index()``. The "index" method
is always loaded by default if the **second segment** of the URI is
empty. Another way to show your "Hello World" message would be this::
example.com/index.php/blog/index/
-**The second segment of the URI determines which function in the
+**The second segment of the URI determines which method in the
controller gets called.**
-Let's try it. Add a new function to your controller::
+Let's try it. Add a new method to your controller::
<?php
class Blog extends CI_Controller {
@@ -96,39 +95,37 @@ Let's try it. Add a new function to your controller::
echo 'Look at this!';
}
}
- ?>
-Now load the following URL to see the comment function::
+Now load the following URL to see the comment method::
example.com/index.php/blog/comments/
You should see your new message.
-Passing URI Segments to your Functions
-======================================
+Passing URI Segments to your methods
+====================================
If your URI contains more then two segments they will be passed to your
-function as parameters.
+method as parameters.
For example, lets say you have a URI like this::
example.com/index.php/products/shoes/sandals/123
-Your function will be passed URI segments 3 and 4 ("sandals" and "123")::
+Your method will be passed URI segments 3 and 4 ("sandals" and "123")::
<?php
class Products extends CI_Controller {
- public function shoes($sandals, $id)
- {
- echo $sandals;
- echo $id;
- }
+ public function shoes($sandals, $id)
+ {
+ echo $sandals;
+ echo $id;
+ }
}
- ?>
.. important:: If you are using the :doc:`URI Routing <routing>`
- feature, the segments passed to your function will be the re-routed
+ feature, the segments passed to your method will be the re-routed
ones.
Defining a Default Controller
@@ -139,59 +136,59 @@ present, as will be the case when only your site root URL is requested.
To specify a default controller, open your **application/config/routes.php**
file and set this variable::
- $route['default_controller'] = 'Blog';
+ $route['default_controller'] = 'blog';
Where Blog is the name of the controller class you want used. If you now
load your main index.php file without specifying any URI segments you'll
see your Hello World message by default.
-Remapping Function Calls
-========================
+Remapping Method Calls
+======================
As noted above, the second segment of the URI typically determines which
-function in the controller gets called. CodeIgniter permits you to
-override this behavior through the use of the _remap() function::
+method in the controller gets called. CodeIgniter permits you to override
+this behavior through the use of the ``_remap()`` method::
public function _remap()
{
- // Some code here...
+ // Some code here...
}
-.. important:: If your controller contains a function named _remap(),
+.. important:: If your controller contains a method named _remap(),
it will **always** get called regardless of what your URI contains. It
- overrides the normal behavior in which the URI determines which function
- is called, allowing you to define your own function routing rules.
+ overrides the normal behavior in which the URI determines which method
+ is called, allowing you to define your own method routing rules.
-The overridden function call (typically the second segment of the URI)
-will be passed as a parameter to the _remap() function::
+The overridden method call (typically the second segment of the URI) will
+be passed as a parameter to the ``_remap()`` method::
public function _remap($method)
{
- if ($method == 'some_method')
- {
- $this->$method();
- }
- else
- {
- $this->default_method();
- }
+ if ($method === 'some_method')
+ {
+ $this->$method();
+ }
+ else
+ {
+ $this->default_method();
+ }
}
-Any extra segments after the method name are passed into _remap() as an
+Any extra segments after the method name are passed into ``_remap()`` as an
optional second parameter. This array can be used in combination with
-PHP's `call_user_func_array <http://php.net/call_user_func_array>`_
+PHP's `call_user_func_array() <http://php.net/call_user_func_array>`_
to emulate CodeIgniter's default behavior.
-::
+Example::
public function _remap($method, $params = array())
{
- $method = 'process_'.$method;
- if (method_exists($this, $method))
- {
- return call_user_func_array(array($this, $method), $params);
- }
- show_404();
+ $method = 'process_'.$method;
+ if (method_exists($this, $method))
+ {
+ return call_user_func_array(array($this, $method), $params);
+ }
+ show_404();
}
Processing Output
@@ -199,69 +196,75 @@ Processing Output
CodeIgniter has an output class that takes care of sending your final
rendered data to the web browser automatically. More information on this
-can be found in the :doc:`Views <views>` and :doc:`Output class <../libraries/output>` pages. In some cases, however, you
-might want to post-process the finalized data in some way and send it to
-the browser yourself. CodeIgniter permits you to add a function named
-_output() to your controller that will receive the finalized output
-data.
+can be found in the :doc:`Views <views>` and :doc:`Output Class
+<../libraries/output>` pages. In some cases, however, you might want to
+post-process the finalized data in some way and send it to the browser
+yourself. CodeIgniter permits you to add a method named ``_output()``
+to your controller that will receive the finalized output data.
-.. important:: If your controller contains a function named _output(),
- it will **always** be called by the output class instead of echoing the
- finalized data directly. The first parameter of the function will
- contain the finalized output.
+.. important:: If your controller contains a method named ``_output()``,
+ it will **always** be called by the output class instead of
+ echoing the finalized data directly. The first parameter of the
+ method will contain the finalized output.
Here is an example::
public function _output($output)
{
- echo $output;
+ echo $output;
}
-.. note:: Please note that your _output() function will receive the data in its
- finalized state. Benchmark and memory usage data will be rendered, cache
- files written (if you have caching enabled), and headers will be sent
- (if you use that :doc:`feature <../libraries/output>`) before it is
- handed off to the _output() function.
- To have your controller's output cached properly, its _output() method
- can use::
+.. note:: Please note that your ``_output()`` method will receive the
+ data in its finalized state. Benchmark and memory usage data
+ will be rendered, cache files written (if you have caching
+ enabled), and headers will be sent (if you use that
+ :doc:`feature <../libraries/output>`) before it is handed off
+ to the ``_output()`` method.
+ To have your controller's output cached properly, its
+ ``_output()`` method can use::
if ($this->output->cache_expiration > 0)
{
- $this->output->_write_cache($output);
+ $this->output->_write_cache($output);
}
- If you are using this feature the page execution timer and memory usage
- stats might not be perfectly accurate since they will not take into
- acccount any further processing you do. For an alternate way to control
- output *before* any of the final processing is done, please see the
- available methods in the :doc:`Output Class <../libraries/output>`.
+ If you are using this feature the page execution timer and
+ memory usage stats might not be perfectly accurate since they
+ will not take into account any further processing you do.
+ For an alternate way to control output *before* any of the
+ final processing is done, please see the available methods
+ in the :doc:`Output Library <../libraries/output>`.
-Private Functions
-=================
+Private methods
+===============
-In some cases you may want certain functions hidden from public access.
-To make a function private, simply add an underscore as the name prefix
-and it will not be served via a URL request. For example, if you were to
-have a function like this::
+In some cases you may want certain methods hidden from public access.
+In order to achieve this, simply declare the method as being private
+or protected and it will not be served via a URL request. For example,
+if you were to have a method like this::
private function _utility()
{
- // some code
+ // some code
}
Trying to access it via the URL, like this, will not work::
example.com/index.php/blog/_utility/
-Organizing Your Controllers into Sub-folders
-============================================
+.. note:: Prefixing method names with an underscore will also prevent
+ them from being called. This is a legacy feature that is left
+ for backwards-compatibility.
+
+Organizing Your Controllers into Sub-directories
+================================================
If you are building a large application you might find it convenient to
-organize your controllers into sub-folders. CodeIgniter permits you to
-do this.
+organize your controllers into sub-directories. CodeIgniter permits you
+to do this.
-Simply create folders within your application/controllers directory and
-place your controller classes within them.
+Simply create folders within your *application/controllers/* directory
+and place your controller classes within them.
.. note:: When using this feature the first segment of your URI must
specify the folder. For example, lets say you have a controller located
@@ -273,9 +276,9 @@ place your controller classes within them.
example.com/index.php/products/shoes/show/123
-Each of your sub-folders may contain a default controller which will be
+Each of your sub-directories may contain a default controller which will be
called if the URL contains only the sub-folder. Simply name your default
-controller as specified in your application/config/routes.php file
+controller as specified in your *application/config/routes.php* file.
CodeIgniter also permits you to remap your URIs using its :doc:`URI
Routing <routing>` feature.
@@ -292,33 +295,38 @@ The reason this line is necessary is because your local constructor will
be overriding the one in the parent controller class so we need to
manually call it.
-::
+Example::
<?php
class Blog extends CI_Controller {
- public function __construct()
- {
- parent::__construct();
- // Your own constructor code
- }
+ public function __construct()
+ {
+ parent::__construct();
+ // Your own constructor code
+ }
}
- ?>
Constructors are useful if you need to set some default values, or run a
default process when your class is instantiated. Constructors can't
return a value, but they can do some default work.
-Reserved Function Names
-=======================
+Reserved method names
+=====================
Since your controller classes will extend the main application
-controller you must be careful not to name your functions identically to
+controller you must be careful not to name your methods identically to
the ones used by that class, otherwise your local functions will
override them. See :doc:`Reserved Names <reserved_names>` for a full
list.
+.. important:: You should also never have a method named identically
+ to its class name. If you do, and there is no ``__construct()``
+ method in the same class, then your e.g. ``Index::index()``
+ method will be executed as a class constructor! This is a PHP4
+ backwards-compatibility feature.
+
That's it!
==========
-That, in a nutshell, is all there is to know about controllers.
+That, in a nutshell, is all there is to know about controllers. \ No newline at end of file
diff --git a/user_guide_src/source/general/core_classes.rst b/user_guide_src/source/general/core_classes.rst
index 4aa6693f7..ce57aeef0 100644
--- a/user_guide_src/source/general/core_classes.rst
+++ b/user_guide_src/source/general/core_classes.rst
@@ -39,9 +39,9 @@ Replacing Core Classes
======================
To use one of your own system classes instead of a default one simply
-place your version inside your local application/core directory::
+place your version inside your local *application/core/* directory::
- application/core/some-class.php
+ application/core/some_class.php
If this directory does not exist you can create it.
@@ -59,7 +59,7 @@ Extending Core Class
====================
If all you need to do is add some functionality to an existing library -
-perhaps add a function or two - then it's overkill to replace the entire
+perhaps add a method or two - then it's overkill to replace the entire
library with your version. In this case it's better to simply extend the
class. Extending a class is nearly identical to replacing a class with a
couple exceptions:
@@ -75,19 +75,19 @@ application/core/MY_Input.php, and declare your class with::
}
-Note: If you need to use a constructor in your class make sure you
+.. note:: If you need to use a constructor in your class make sure you
extend the parent constructor::
class MY_Input extends CI_Input {
- function __construct()
- {
- parent::__construct();
- }
+ public function __construct()
+ {
+ parent::__construct();
+ }
}
**Tip:** Any functions in your class that are named identically to the
-functions in the parent class will be used instead of the native ones
+methods in the parent class will be used instead of the native ones
(this is known as "method overriding"). This allows you to substantially
alter the CodeIgniter core.
@@ -98,24 +98,24 @@ your new class in your application controller's constructors.
class Welcome extends MY_Controller {
- function __construct()
- {
- parent::__construct();
- }
+ public function __construct()
+ {
+ parent::__construct();
+ }
- function index()
- {
- $this->load->view('welcome_message');
- }
+ public function index()
+ {
+ $this->load->view('welcome_message');
+ }
}
Setting Your Own Prefix
-----------------------
To set your own sub-class prefix, open your
-application/config/config.php file and look for this item::
+*application/config/config.php* file and look for this item::
$config['subclass_prefix'] = 'MY_';
-Please note that all native CodeIgniter libraries are prefixed with CI\_
-so DO NOT use that as your prefix.
+Please note that all native CodeIgniter libraries are prefixed
+with CI\_ so DO NOT use that as your prefix. \ No newline at end of file
diff --git a/user_guide_src/source/general/creating_drivers.rst b/user_guide_src/source/general/creating_drivers.rst
index 0e22e4f14..cf4ea5d7f 100644
--- a/user_guide_src/source/general/creating_drivers.rst
+++ b/user_guide_src/source/general/creating_drivers.rst
@@ -16,5 +16,6 @@ Sample driver directory and file structure layout:
- Driver_name_subclass_2.php
- Driver_name_subclass_3.php
-**NOTE:** In order to maintain compatibility on case-sensitive file
-systems, the Driver_name directory must be ucfirst()
+.. note:: In order to maintain compatibility on case-sensitive
+ file systems, the Driver_name directory must be
+ named in the format returned by ``ucfirst()``. \ No newline at end of file
diff --git a/user_guide_src/source/general/creating_libraries.rst b/user_guide_src/source/general/creating_libraries.rst
index 673fbd4bb..8bafd4532 100644
--- a/user_guide_src/source/general/creating_libraries.rst
+++ b/user_guide_src/source/general/creating_libraries.rst
@@ -12,7 +12,7 @@ your local resources and the global framework resources.
As an added bonus, CodeIgniter permits your libraries to extend native
classes if you simply need to add some functionality to an existing
library. Or you can even replace native libraries just by placing
-identically named versions in your application/libraries folder.
+identically named versions in your *application/libraries* directory.
In summary:
@@ -28,8 +28,8 @@ The page below explains these three concepts in detail.
Storage
=======
-Your library classes should be placed within your application/libraries
-folder, as this is where CodeIgniter will look for them when they are
+Your library classes should be placed within your *application/libraries*
+directory, as this is where CodeIgniter will look for them when they are
initialized.
Naming Conventions
@@ -49,9 +49,9 @@ Someclass purely as an example)::
class Someclass {
- public function some_function()
- {
- }
+ public function some_method()
+ {
+ }
}
/* End of file Someclass.php */
@@ -59,7 +59,7 @@ Someclass purely as an example)::
Using Your Class
================
-From within any of your :doc:`Controller <controllers>` functions you
+From within any of your :doc:`Controller <controllers>` methods you
can initialize your class using the standard::
$this->load->library('someclass');
@@ -70,12 +70,12 @@ doesn't care.
Once loaded you can access your class using the lower case version::
- $this->someclass->some_function();  // Object instances will always be lower case
+ $this->someclass->some_method();  // Object instances will always be lower case
Passing Parameters When Initializing Your Class
===============================================
-In the library loading function you can dynamically pass data as an
+In the library loading method you can dynamically pass data as an
array via the second parameter and it will be passed to your class
constructor::
@@ -86,21 +86,19 @@ constructor::
If you use this feature you must set up your class constructor to expect
data::
- <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+ <?php defined('BASEPATH') OR exit('No direct script access allowed');
class Someclass {
- public function __construct($params)
- {
- // Do something with $params
- }
+ public function __construct($params)
+ {
+ // Do something with $params
+ }
}
- ?>
-
You can also pass parameters stored in a config file. Simply create a
config file named identically to the class file name and store it in
-your application/config/ folder. Note that if you dynamically pass
+your *application/config/* directory. Note that if you dynamically pass
parameters as described above, the config file option will not be
available.
@@ -108,18 +106,18 @@ Utilizing CodeIgniter Resources within Your Library
===================================================
To access CodeIgniter's native resources within your library use the
-get_instance() function. This function returns the CodeIgniter super
+``get_instance()`` method. This method returns the CodeIgniter super
object.
-Normally from within your controller functions you will call any of the
-available CodeIgniter functions using the $this construct::
+Normally from within your controller methods you will call any of the
+available CodeIgniter methods using the ``$this`` construct::
$this->load->helper('url');
$this->load->library('session');
$this->config->item('base_url');
// etc.
-$this, however, only works directly within your controllers, your
+``$this``, however, only works directly within your controllers, your
models, or your views. If you would like to use CodeIgniter's classes
from within your own custom classes you can do so as follows:
@@ -128,7 +126,7 @@ First, assign the CodeIgniter object to a variable::
$CI =& get_instance();
Once you've assigned the object to a variable, you'll use that variable
-*instead* of $this::
+*instead* of ``$this``::
$CI =& get_instance();
@@ -137,7 +135,7 @@ Once you've assigned the object to a variable, you'll use that variable
$CI->config->item('base_url');
// etc.
-.. note:: You'll notice that the above get_instance() function is being
+.. note:: You'll notice that the above ``get_instance()`` function is being
passed by reference::
$CI =& get_instance();
@@ -145,6 +143,36 @@ Once you've assigned the object to a variable, you'll use that variable
This is very important. Assigning by reference allows you to use the
original CodeIgniter object rather than creating a copy of it.
+However, since a library is a class, it would be better if you
+take full advantage of the OOP principles. So, in order to
+be able to use the CodeIgniter super-object in all of the class
+methods, you're encouraged to assign it to a property instead::
+
+class Example_library {
+
+ protected $CI;
+
+ // We'll use a constructor, as you can't directly call a function
+ // from a property definition.
+ public function __construct()
+ {
+ // Assign the CodeIgniter super-object
+ $this->CI =& get_instance();
+ }
+
+ public function foo()
+ {
+ $this->CI->load->helper('url');
+ redirect();
+ }
+
+ public function bar()
+ {
+ echo $this->CI->config_item('base_url');
+ }
+
+}
+
Replacing Native Libraries with Your Versions
=============================================
@@ -152,8 +180,8 @@ Simply by naming your class files identically to a native library will
cause CodeIgniter to use it instead of the native one. To use this
feature you must name the file and the class declaration exactly the
same as the native library. For example, to replace the native Email
-library you'll create a file named application/libraries/Email.php, and
-declare your class with::
+library you'll create a file named *application/libraries/Email.php*,
+and declare your class with::
class CI_Email {
@@ -161,7 +189,7 @@ declare your class with::
Note that most native classes are prefixed with CI\_.
-To load your library you'll see the standard loading function::
+To load your library you'll see the standard loading method::
$this->load->library('email');
@@ -172,7 +200,7 @@ Extending Native Libraries
==========================
If all you need to do is add some functionality to an existing library -
-perhaps add a function or two - then it's overkill to replace the entire
+perhaps add a method or two - then it's overkill to replace the entire
library with your version. In this case it's better to simply extend the
class. Extending a class is nearly identical to replacing a class with a
couple exceptions:
@@ -182,7 +210,7 @@ couple exceptions:
item is configurable. See below.).
For example, to extend the native Email class you'll create a file named
-application/libraries/MY_Email.php, and declare your class with::
+*application/libraries/MY_Email.php*, and declare your class with::
class MY_Email extends CI_Email {
@@ -200,8 +228,7 @@ extend the parent constructor::
}
-.. note::
- Not all of the libraries have the same (or any) parameters
+.. note:: Not all of the libraries have the same (or any) parameters
in their constructor. Take a look at the library that you're
extending first to see how it should be implemented.
@@ -218,15 +245,15 @@ Once loaded you will use the class variable as you normally would for
the class you are extending. In the case of the email class all calls
will use::
- $this->email->some_function();
+ $this->email->some_method();
Setting Your Own Prefix
-----------------------
To set your own sub-class prefix, open your
-application/config/config.php file and look for this item::
+*application/config/config.php* file and look for this item::
$config['subclass_prefix'] = 'MY_';
Please note that all native CodeIgniter libraries are prefixed with CI\_
-so DO NOT use that as your prefix.
+so DO NOT use that as your prefix. \ No newline at end of file
diff --git a/user_guide_src/source/general/credits.rst b/user_guide_src/source/general/credits.rst
index 2c7459894..03ee83dd6 100644
--- a/user_guide_src/source/general/credits.rst
+++ b/user_guide_src/source/general/credits.rst
@@ -16,4 +16,4 @@ of the Reactor Team.
A hat tip goes to Ruby on Rails for inspiring us to create a PHP
framework, and for bringing frameworks into the general consciousness of
-the web community.
+the web community. \ No newline at end of file
diff --git a/user_guide_src/source/general/drivers.rst b/user_guide_src/source/general/drivers.rst
index e2ded62e2..b64b0e75e 100644
--- a/user_guide_src/source/general/drivers.rst
+++ b/user_guide_src/source/general/drivers.rst
@@ -8,18 +8,18 @@ parent class, but not their siblings. Drivers provide an elegant syntax
in your :doc:`controllers <controllers>` for libraries that benefit
from or require being broken down into discrete classes.
-Drivers are found in the system/libraries folder, in their own folder
-which is identically named to the parent library class. Also inside that
-folder is a subfolder named drivers, which contains all of the possible
-child class files.
+Drivers are found in the *system/libraries/* directory, in their own
+sub-directory which is identically named to the parent library class.
+Also inside that directory is a subdirectory named drivers, which
+contains all of the possible child class files.
To use a driver you will initialize it within a controller using the
-following initialization function::
+following initialization method::
- $this->load->driver('class name');
+ $this->load->driver('class_name');
Where class name is the name of the driver class you want to invoke. For
-example, to load a driver named "Some Parent" you would do this::
+example, to load a driver named "Some_parent" you would do this::
$this->load->driver('some_parent');
@@ -37,4 +37,4 @@ Creating Your Own Drivers
=========================
Please read the section of the user guide that discusses how to :doc:`create
-your own drivers <creating_drivers>`.
+your own drivers <creating_drivers>`. \ No newline at end of file
diff --git a/user_guide_src/source/general/environments.rst b/user_guide_src/source/general/environments.rst
index fa1b096e2..d74ebb8d5 100644
--- a/user_guide_src/source/general/environments.rst
+++ b/user_guide_src/source/general/environments.rst
@@ -11,8 +11,8 @@ when "live".
The ENVIRONMENT Constant
========================
-By default, CodeIgniter comes with the environment constant set to use
-the value provided in ``$_SERVER['CI_ENV']``, otherwise defaults to
+By default, CodeIgniter comes with the environment constant set to use
+the value provided in ``$_SERVER['CI_ENV']``, otherwise defaults to
'development'. At the top of index.php, you will see::
define('ENVIRONMENT', isset($_SERVER['CI_ENV']) ? $_SERVER['CI_ENV'] : 'development');
@@ -49,4 +49,4 @@ Optionally, you can have CodeIgniter load environment-specific
configuration files. This may be useful for managing things like
differing API keys across multiple environments. This is described in
more detail in the environment section of the `Config
-Class <../libraries/config.html#environments>`_ documentation.
+Class <../libraries/config.html#environments>`_ documentation. \ No newline at end of file
diff --git a/user_guide_src/source/general/errors.rst b/user_guide_src/source/general/errors.rst
index 91b59140f..8c941aadb 100644
--- a/user_guide_src/source/general/errors.rst
+++ b/user_guide_src/source/general/errors.rst
@@ -20,47 +20,69 @@ without having to worry about class/function scoping.
The following functions let you generate errors:
-show_error('message' [, int $status_code= 500 ] )
-===================================================
+show_error()
+============
+
+.. php:function:: show_error($message, $status_code, $heading = 'An Error Was Encountered')
+
+ :param mixed $message: Error message
+ :param int $status_code: HTTP Response status code
+ :param string $heading: Error page heading
+ :returns: void
This function will display the error message supplied to it using the
-following error template:
+following error template::
+
+ application/errors/error_general.php
+
+The optional parameter ``$status_code`` determines what HTTP status
+code should be sent with the error.
-application/errors/error_general.php
+show_404()
+==========
-The optional parameter $status_code determines what HTTP status code
-should be sent with the error.
+.. php:function:: show_404($page = '', $log_error = TRUE)
-show_404('page' [, 'log_error'])
-==================================
+ :param string $page: URI string
+ :param bool $log_error: Whether to log the error
+ :returns: void
This function will display the 404 error message supplied to it using
-the following error template:
+the following error template::
-application/errors/error_404.php
+ application/errors/error_404.php
The function expects the string passed to it to be the file path to the
page that isn't found. Note that CodeIgniter automatically shows 404
messages if controllers are not found.
-CodeIgniter automatically logs any show_404() calls. Setting the
+CodeIgniter automatically logs any ``show_404()`` calls. Setting the
optional second parameter to FALSE will skip logging.
-log_message('level', 'message')
-================================
+log_message()
+=============
+
+.. php:function:: log_message($level = 'error', $message, $php_error = FALSE)
+
+ :param string $level: Log level
+ :param string $message: Message to log
+ :param bool $php_error: Whether we're loggin a native PHP error message
+ :returns: void
This function lets you write messages to your log files. You must supply
one of three "levels" in the first parameter, indicating what type of
message it is (debug, error, info), with the message itself in the
-second parameter. Example::
+second parameter.
+
+Example::
- if ($some_var == "")
+ if ($some_var == '')
{
- log_message('error', 'Some variable did not contain a value.');
+ log_message('error', 'Some variable did not contain a value.');
}
else
{
- log_message('debug', 'Some variable was correctly set');
+ log_message('debug', 'Some variable was correctly set');
}
log_message('info', 'The purpose of some variable is to provide some value.');
@@ -77,8 +99,8 @@ There are three message types:
natively generate any info messages but you may want to in your
application.
-.. note:: In order for the log file to actually be written, the "logs"
- folder must be writable. In addition, you must set the "threshold" for
- logging in application/config/config.php. You might, for example, only
- want error messages to be logged, and not the other two types. If you
- set it to zero logging will be disabled.
+.. note:: In order for the log file to actually be written, the *logs*
+ directory must be writable. In addition, you must set the "threshold"
+ for logging in *application/config/config.php*. You might, for example,
+ only want error messages to be logged, and not the other two types.
+ If you set it to zero logging will be disabled. \ No newline at end of file
diff --git a/user_guide_src/source/general/helpers.rst b/user_guide_src/source/general/helpers.rst
index 3a98311a6..d171aa8ed 100644
--- a/user_guide_src/source/general/helpers.rst
+++ b/user_guide_src/source/general/helpers.rst
@@ -23,12 +23,12 @@ Helpers are typically stored in your **system/helpers**, or
**application/helpers directory**. CodeIgniter will look first in your
**application/helpers directory**. If the directory does not exist or the
specified helper is not located there CI will instead look in your
-global system/helpers folder.
+global *system/helpers/* directory.
Loading a Helper
================
-Loading a helper file is quite simple using the following function::
+Loading a helper file is quite simple using the following method::
$this->load->helper('name');
@@ -40,15 +40,15 @@ For example, to load the **URL Helper** file, which is named
$this->load->helper('url');
-A helper can be loaded anywhere within your controller functions (or
+A helper can be loaded anywhere within your controller methods (or
even within your View files, although that's not a good practice), as
long as you load it before you use it. You can load your helpers in your
controller constructor so that they become available automatically in
any function, or you can load a helper in a specific function that needs
it.
-Note: The Helper loading function above does not return a value, so
-don't try to assign it to a variable. Just use it as shown.
+.. note:: The Helper loading method above does not return a value, so
+ don't try to assign it to a variable. Just use it as shown.
Loading Multiple Helpers
========================
@@ -56,14 +56,16 @@ Loading Multiple Helpers
If you need to load more than one helper you can specify them in an
array, like this::
- $this->load->helper( array('helper1', 'helper2', 'helper3') );
+ $this->load->helper(
+ array('helper1', 'helper2', 'helper3')
+ );
Auto-loading Helpers
====================
If you find that you need a particular helper globally throughout your
application, you can tell CodeIgniter to auto-load it during system
-initialization. This is done by opening the **application/config/autoload.php**
+initialization. This is done by opening the **application/config/autoload.php**
file and adding the helper to the autoload array.
Using a Helper
@@ -72,13 +74,13 @@ Using a Helper
Once you've loaded the Helper File containing the function you intend to
use, you'll call it the way you would a standard PHP function.
-For example, to create a link using the anchor() function in one of your
-view files you would do this::
+For example, to create a link using the ``anchor()`` function in one of
+your view files you would do this::
<?php echo anchor('blog/comments', 'Click Here');?>
Where "Click Here" is the name of the link, and "blog/comments" is the
-URI to the controller/function you wish to link to.
+URI to the controller/method you wish to link to.
"Extending" Helpers
===================
@@ -91,11 +93,11 @@ If all you need to do is add some functionality to an existing helper -
perhaps add a function or two, or change how a particular helper
function operates - then it's overkill to replace the entire helper with
your version. In this case it's better to simply "extend" the Helper.
-The term "extend" is used loosely since Helper functions are procedural
-and discrete and cannot be extended in the traditional programmatic
-sense. Under the hood, this gives you the ability to add to the
-functions a Helper provides, or to modify how the native Helper
-functions operate.
+
+.. note:: The term "extend" is used loosely since Helper functions are
+ procedural and discrete and cannot be extended in the traditional
+ programmatic sense. Under the hood, this gives you the ability to
+ add to or or to replace the functions a Helper provides.
For example, to extend the native **Array Helper** you'll create a file
named **application/helpers/MY_array_helper.php**, and add or override
@@ -104,31 +106,31 @@ functions::
// any_in_array() is not in the Array Helper, so it defines a new function
function any_in_array($needle, $haystack)
{
- $needle = (is_array($needle)) ? $needle : array($needle);
-
- foreach ($needle as $item)
- {
- if (in_array($item, $haystack))
- {
- return TRUE;
- }
+ $needle = is_array($needle) ? $needle : array($needle);
+
+ foreach ($needle as $item)
+ {
+ if (in_array($item, $haystack))
+ {
+ return TRUE;
+ }
}
- return FALSE;
+ return FALSE;
}
// random_element() is included in Array Helper, so it overrides the native function
function random_element($array)
{
- shuffle($array);
- return array_pop($array);
+ shuffle($array);
+ return array_pop($array);
}
Setting Your Own Prefix
-----------------------
The filename prefix for "extending" Helpers is the same used to extend
-libraries and Core classes. To set your own prefix, open your
+libraries and core classes. To set your own prefix, open your
**application/config/config.php** file and look for this item::
$config['subclass_prefix'] = 'MY_';
@@ -140,4 +142,4 @@ Now What?
=========
In the Table of Contents you'll find a list of all the available Helper
-Files. Browse each one to see what they do.
+Files. Browse each one to see what they do. \ No newline at end of file
diff --git a/user_guide_src/source/general/hooks.rst b/user_guide_src/source/general/hooks.rst
index 65696f6c7..fc5da5b80 100644
--- a/user_guide_src/source/general/hooks.rst
+++ b/user_guide_src/source/general/hooks.rst
@@ -16,25 +16,26 @@ Enabling Hooks
==============
The hooks feature can be globally enabled/disabled by setting the
-following item in the application/config/config.php file::
+following item in the **application/config/config.php** file::
$config['enable_hooks'] = TRUE;
Defining a Hook
===============
-Hooks are defined in application/config/hooks.php file. Each hook is
-specified as an array with this prototype::
+Hooks are defined in **application/config/hooks.php** file.
+Each hook is specified as an array with this prototype::
$hook['pre_controller'] = array(
- 'class' => 'MyClass',
- 'function' => 'Myfunction',
- 'filename' => 'Myclass.php',
- 'filepath' => 'hooks',
- 'params' => array('beer', 'wine', 'snacks')
- );
+ 'class' => 'MyClass',
+ 'function' => 'Myfunction',
+ 'filename' => 'Myclass.php',
+ 'filepath' => 'hooks',
+ 'params' => array('beer', 'wine', 'snacks')
+ );
**Notes:**
+
The array index correlates to the name of the particular hook point you
want to use. In the above example the hook point is pre_controller. A
list of hook points is found below. The following items should be
@@ -42,14 +43,15 @@ defined in your associative hook array:
- **class** The name of the class you wish to invoke. If you prefer to
use a procedural function instead of a class, leave this item blank.
-- **function** The function name you wish to call.
+- **function** The function (or method) name you wish to call.
- **filename** The file name containing your class/function.
-- **filepath** The name of the directory containing your script. Note:
- Your script must be located in a directory INSIDE your application
- folder, so the file path is relative to that folder. For example, if
- your script is located in application/hooks, you will simply use
- hooks as your filepath. If your script is located in
- application/hooks/utilities you will use hooks/utilities as your
+- **filepath** The name of the directory containing your script.
+ Note:
+ Your script must be located in a directory INSIDE your *application/*
+ directory, so the file path is relative to that directory. For example,
+ if your script is located in *application/hooks/*, you will simply use
+ 'hooks' as your filepath. If your script is located in
+ *application/hooks/utilities/* you will use 'hooks/utilities' as your
filepath. No trailing slash.
- **params** Any parameters you wish to pass to your script. This item
is optional.
@@ -61,20 +63,20 @@ If want to use the same hook point with more then one script, simply
make your array declaration multi-dimensional, like this::
$hook['pre_controller'][] = array(
- 'class' => 'MyClass',
- 'function' => 'Myfunction',
- 'filename' => 'Myclass.php',
- 'filepath' => 'hooks',
- 'params' => array('beer', 'wine', 'snacks')
- );
+ 'class' => 'MyClass',
+ 'function' => 'MyMethod',
+ 'filename' => 'Myclass.php',
+ 'filepath' => 'hooks',
+ 'params' => array('beer', 'wine', 'snacks')
+ );
$hook['pre_controller'][] = array(
- 'class' => 'MyOtherClass',
- 'function' => 'MyOtherfunction',
- 'filename' => 'Myotherclass.php',
- 'filepath' => 'hooks',
- 'params' => array('red', 'yellow', 'blue')
- );
+ 'class' => 'MyOtherClass',
+ 'function' => 'MyOtherMethod',
+ 'filename' => 'Myotherclass.php',
+ 'filepath' => 'hooks',
+ 'params' => array('red', 'yellow', 'blue')
+ );
Notice the brackets after each array index::
@@ -101,18 +103,17 @@ The following is a list of available hook points.
- **post_controller**
Called immediately after your controller is fully executed.
- **display_override**
- Overrides the _display() function, used to send the finalized page
+ Overrides the ``_display()`` method, used to send the finalized page
to the web browser at the end of system execution. This permits you
to use your own display methodology. Note that you will need to
- reference the CI superobject with $this->CI =& get_instance() and
+ reference the CI superobject with ``$this->CI =& get_instance()`` and
then the finalized data will be available by calling
- $this->CI->output->get_output()
+ ``$this->CI->output->get_output()``.
- **cache_override**
- Enables you to call your own function instead of the
- _display_cache() function in the output class. This permits you to
- use your own cache display mechanism.
+ Enables you to call your own method instead of the ``_display_cache()``
+ method in the :doc:`Output Library <../libraries/output>`. This permits
+ you to use your own cache display mechanism.
- **post_system**
Called after the final rendered page is sent to the browser, at the
end of system execution after the finalized data is sent to the
- browser.
-
+ browser. \ No newline at end of file
diff --git a/user_guide_src/source/general/index.rst b/user_guide_src/source/general/index.rst
index 2162b8140..2bc684a1d 100644
--- a/user_guide_src/source/general/index.rst
+++ b/user_guide_src/source/general/index.rst
@@ -29,4 +29,4 @@ General Topics
environments
alternative_php
security
- PHP Style Guide <styleguide>
+ PHP Style Guide <styleguide> \ No newline at end of file
diff --git a/user_guide_src/source/general/libraries.rst b/user_guide_src/source/general/libraries.rst
index 954a5b8f8..6e1c8b6dd 100644
--- a/user_guide_src/source/general/libraries.rst
+++ b/user_guide_src/source/general/libraries.rst
@@ -2,30 +2,31 @@
Using CodeIgniter Libraries
###########################
-All of the available libraries are located in your system/libraries
-folder. In most cases, to use one of these classes involves initializing
+All of the available libraries are located in your *system/libraries/*
+directory. In most cases, to use one of these classes involves initializing
it within a :doc:`controller <controllers>` using the following
-initialization function::
+initialization method::
- $this->load->library('class name');
+ $this->load->library('class_name');
-Where class name is the name of the class you want to invoke. For
-example, to load the form validation class you would do this::
+Where 'class_name' is the name of the class you want to invoke. For
+example, to load the :doc:`Form Validation Library
+<../libraries/form_validation>` you would do this::
- $this->load->library('form_validation');
+ $this->load->library('form_validation');
Once initialized you can use it as indicated in the user guide page
corresponding to that class.
Additionally, multiple libraries can be loaded at the same time by
-passing an array of libraries to the load function.
+passing an array of libraries to the load method.
-::
+Example::
$this->load->library(array('email', 'table'));
Creating Your Own Libraries
===========================
-Please read the section of the user guide that discusses how to :doc:`create
-your own libraries <creating_libraries>`
+Please read the section of the user guide that discusses how to
+:doc:`create your own libraries <creating_libraries>`.
diff --git a/user_guide_src/source/general/managing_apps.rst b/user_guide_src/source/general/managing_apps.rst
index 996481354..afb1aba2e 100644
--- a/user_guide_src/source/general/managing_apps.rst
+++ b/user_guide_src/source/general/managing_apps.rst
@@ -3,41 +3,39 @@ Managing your Applications
##########################
By default it is assumed that you only intend to use CodeIgniter to
-manage one application, which you will build in your application/
+manage one application, which you will build in your *application/*
directory. It is possible, however, to have multiple sets of
applications that share a single CodeIgniter installation, or even to
-rename or relocate your application folder.
+rename or relocate your application directory.
-Renaming the Application Folder
-===============================
-
-If you would like to rename your application folder you may do so as
-long as you open your main index.php file and set its name using the
-$application_folder variable::
+Renaming the Application Directory
+==================================
- $application_folder = "application";
+If you would like to rename your application directory you may do so
+as long as you open your main index.php file and set its name using
+the ``$application_folder`` variable::
-Relocating your Application Folder
-==================================
+ $application_folder = 'application';
-It is possible to move your application folder to a different location
-on your server than your system folder. To do so open your main
-index.php and set a *full server path* in the $application_folder
-variable.
+Relocating your Application Directory
+=====================================
-::
+It is possible to move your application directory to a different
+location on your server than your system directory. To do so open
+your main index.php and set a *full server path* in the
+``$application_folder`` variable::
- $application_folder = "/Path/to/your/application";
+ $application_folder = '/path/to/your/application';
Running Multiple Applications with one CodeIgniter Installation
===============================================================
If you would like to share a common CodeIgniter installation to manage
several different applications simply put all of the directories located
-inside your application folder into their own sub-folder.
+inside your application directory into their own sub-directory.
-For example, let's say you want to create two applications, "foo" and
-"bar". You could structure your application folders like this::
+For example, let's say you want to create two applications, named "foo"
+and "bar". You could structure your application directories like this::
applications/foo/
applications/foo/config/
@@ -55,11 +53,11 @@ For example, let's say you want to create two applications, "foo" and
applications/bar/views/
To select a particular application for use requires that you open your
-main index.php file and set the $application_folder variable. For
+main index.php file and set the ``$application_folder`` variable. For
example, to select the "foo" application for use you would do this::
- $application_folder = "applications/foo";
+ $application_folder = 'applications/foo';
.. note:: Each of your applications will need its own index.php file
which calls the desired application. The index.php file can be named
- anything you want.
+ anything you want. \ No newline at end of file
diff --git a/user_guide_src/source/general/models.rst b/user_guide_src/source/general/models.rst
index 4e52a9648..a028a9569 100644
--- a/user_guide_src/source/general/models.rst
+++ b/user_guide_src/source/general/models.rst
@@ -18,55 +18,56 @@ model class might look like::
class Blog_model extends CI_Model {
- public $title = '';
- public $content = '';
- public $date = '';
-
- function __construct()
- {
- // Call the Model constructor
- parent::__construct();
- }
-
- function get_last_ten_entries()
- {
- $query = $this->db->get('entries', 10);
- return $query->result();
- }
-
- function insert_entry()
- {
- $this->title = $_POST['title']; // please read the below note
- $this->content = $_POST['content'];
- $this->date = time();
-
- $this->db->insert('entries', $this);
- }
-
- function update_entry()
- {
- $this->title = $_POST['title'];
- $this->content = $_POST['content'];
- $this->date = time();
-
- $this->db->update('entries', $this, array('id' => $_POST['id']));
- }
+ public $title;
+ public $content;
+ public $date;
+
+ public function __construct()
+ {
+ // Call the CI_Model constructor
+ parent::__construct();
+ }
+
+ public function get_last_ten_entries()
+ {
+ $query = $this->db->get('entries', 10);
+ return $query->result();
+ }
+
+ public function insert_entry()
+ {
+ $this->title = $_POST['title']; // please read the below note
+ $this->content = $_POST['content'];
+ $this->date = time();
+
+ $this->db->insert('entries', $this);
+ }
+
+ public function update_entry()
+ {
+ $this->title = $_POST['title'];
+ $this->content = $_POST['content'];
+ $this->date = time();
+
+ $this->db->update('entries', $this, array('id' => $_POST['id']));
+ }
}
-.. note:: The functions in the above example use the :doc:`Active
- Record <../database/query_builder>` database functions.
+.. note:: The methods in the above example use the :doc:`Query Builder
+ <../database/query_builder>` database methods.
-.. note:: For the sake of simplicity in this example we're using $_POST
+.. note:: For the sake of simplicity in this example we're using ``$_POST``
directly. This is generally bad practice, and a more common approach
- would be to use the :doc:`Input Class <../libraries/input>`
- $this->input->post('title')
+ would be to use the :doc:`Input Library <../libraries/input>`
+ ``$this->input->post('title')``.
Anatomy of a Model
==================
-Model classes are stored in your **application/models/ folder**. They can be
-nested within sub-folders if you want this type of organization.
+Model classes are stored in your **application/models/** directory.
+They can be nested within sub-directories if you want this type of
+organization.
The basic prototype for a model class is this::
@@ -103,14 +104,14 @@ Loading a Model
===============
Your models will typically be loaded and called from within your
-:doc:`controller <controllers>` functions. To load a model you will use
+:doc:`controller <controllers>` methods. To load a model you will use
the following method::
$this->load->model('model_name');
-If your model is located in a sub-folder, include the relative path from
-your models folder. For example, if you have a model located at
-application/models/blog/queries.php you'll load it using::
+If your model is located in a sub-directory, include the relative path
+from your models directory. For example, if you have a model located at
+*application/models/blog/queries.php* you'll load it using::
$this->load->model('blog/queries');
@@ -141,7 +142,6 @@ view::
$this->load->view('blog', $data);
}
-
}
@@ -163,10 +163,9 @@ database. The following options for connecting are available to you:
- You can connect using the standard database methods :doc:`described
here <../database/connecting>`, either from within your
Controller class or your Model class.
-- You can tell the model loading function to auto-connect by passing
- TRUE (boolean) via the third parameter, and connectivity settings, as
- defined in your database config file will be used:
- ::
+- You can tell the model loading method to auto-connect by passing
+ TRUE (boolean) via the third parameter, and connectivity settings,
+ as defined in your database config file will be used::
$this->load->model('model_name', '', TRUE);
diff --git a/user_guide_src/source/general/profiling.rst b/user_guide_src/source/general/profiling.rst
index 437635289..6dbd0be16 100644
--- a/user_guide_src/source/general/profiling.rst
+++ b/user_guide_src/source/general/profiling.rst
@@ -3,7 +3,7 @@ Profiling Your Application
##########################
The Profiler Class will display benchmark results, queries you have run,
-and $_POST data at the bottom of your pages. This information can be
+and ``$_POST`` data at the bottom of your pages. This information can be
useful during development in order to help with debugging and
optimization.
@@ -11,14 +11,14 @@ Initializing the Class
======================
.. important:: This class does NOT need to be initialized. It is loaded
- automatically by the :doc:`Output Class <../libraries/output>` if
- profiling is enabled as shown below.
+ automatically by the :doc:`Output Library <../libraries/output>`
+ if profiling is enabled as shown below.
Enabling the Profiler
=====================
-To enable the profiler place the following function anywhere within your
-:doc:`Controller <controllers>` functions::
+To enable the profiler place the following line anywhere within your
+:doc:`Controller <controllers>` methods::
$this->output->enable_profiler(TRUE);
@@ -35,8 +35,8 @@ Setting Benchmark Points
In order for the Profiler to compile and display your benchmark data you
must name your mark points using specific syntax.
-Please read the information on setting Benchmark points in :doc:`Benchmark
-Class <../libraries/benchmark>` page.
+Please read the information on setting Benchmark points in the
+:doc:`Benchmark Library <../libraries/benchmark>` page.
Enabling and Disabling Profiler Sections
========================================
@@ -44,21 +44,21 @@ Enabling and Disabling Profiler Sections
Each section of Profiler data can be enabled or disabled by setting a
corresponding config variable to TRUE or FALSE. This can be done one of
two ways. First, you can set application wide defaults with the
-application/config/profiler.php config file.
+*application/config/profiler.php* config file.
-::
+Example::
$config['config'] = FALSE;
$config['queries'] = FALSE;
In your controllers, you can override the defaults and config file
-values by calling the set_profiler_sections() method of the :doc:`Output
-class <../libraries/output>`::
+values by calling the ``set_profiler_sections()`` method of the
+:doc:`Output Library <../libraries/output>`::
$sections = array(
- 'config' => TRUE,
- 'queries' => TRUE
- );
+ 'config' => TRUE,
+ 'queries' => TRUE
+ );
$this->output->set_profiler_sections($sections);
diff --git a/user_guide_src/source/general/requirements.rst b/user_guide_src/source/general/requirements.rst
index d9edfba6d..104923625 100644
--- a/user_guide_src/source/general/requirements.rst
+++ b/user_guide_src/source/general/requirements.rst
@@ -3,7 +3,13 @@ Server Requirements
###################
- `PHP <http://www.php.net/>`_ version 5.2.4 or newer.
-- A Database is required for most web application programming. Current
- supported databases are MySQL (5.1+), MySQLi, Oracle, PostgreSQL,
- MS SQL, SQLSRV (SQL Server 2005+), SQLite, SQLite3, CUBRID, Interbase,
- ODBC and PDO.
+- A Database is required for most web application programming.
+ Currently supported databases are:
+ - MySQL (5.1+) via the *mysql* (deprecated), *mysqli* and *pdo* drivers
+ - Oracle via the *oci8* and *pdo* drivers
+ - PostgreSQL via the *postgre* and *pdo* drivers
+ - MS SQL via the *mssql*, *sqlsrv* (version 2005 and above only) and *pdo* drivers
+ - SQLite via the *sqlite* (version 2), *sqlite3* (version 3) and *pdo* drivers
+ - CUBRID via the *cubrid* and *pdo* drivers
+ - Interbase/Firebird via the *ibase* and *pdo* drivers
+ - ODBC via the *odbc* and *pdo* drivers (you should know that ODBC is actually an abstraction layer) \ No newline at end of file
diff --git a/user_guide_src/source/general/reserved_names.rst b/user_guide_src/source/general/reserved_names.rst
index 3354375c5..d91292363 100644
--- a/user_guide_src/source/general/reserved_names.rst
+++ b/user_guide_src/source/general/reserved_names.rst
@@ -2,16 +2,17 @@
Reserved Names
##############
-In order to help out, CodeIgniter uses a series of functions and names
-in its operation. Because of this, some names cannot be used by a
-developer. Following is a list of reserved names that cannot be used.
+In order to help out, CodeIgniter uses a series of function, method,
+class and variable names in its operation. Because of this, some names
+cannot be used by a developer. Following is a list of reserved names
+that cannot be used.
Controller names
----------------
Since your controller classes will extend the main application
-controller you must be careful not to name your functions identically to
-the ones used by that class, otherwise your local functions will
+controller you must be careful not to name your methods identically to
+the ones used by that class, otherwise your local methods will
override them. The following is a list of reserved names. Do not name
your controller any of these:
@@ -24,22 +25,25 @@ your controller any of these:
Functions
---------
-- is_really_writable()
-- load_class()
-- get_config()
-- config_item()
-- show_error()
-- show_404()
-- log_message()
-- _exception_handler()
-- get_instance()
+- :php:func:`is_really_writable()`
+- ``load_class()``
+- ``get_config()``
+- :php:func:`config_item()`
+- :php:func:`show_error()`
+- :php:func:`show_404()`
+- :php:func:`log_message()`
+- :php:func:`get_mimes()`
+- :php:func:`html_escape()`
+- :php:func:`get_instance()`
+- ``_exception_handler()``
+- ``_stringify_attributes()``
Variables
---------
-- $config
-- $mimes
-- $lang
+- ``$config``
+- ``$db``
+- ``$lang``
Constants
---------
@@ -62,5 +66,4 @@ Constants
- FOPEN_WRITE_CREATE
- FOPEN_READ_WRITE_CREATE
- FOPEN_WRITE_CREATE_STRICT
-- FOPEN_READ_WRITE_CREATE_STRICT
-
+- FOPEN_READ_WRITE_CREATE_STRICT \ No newline at end of file
diff --git a/user_guide_src/source/general/routing.rst b/user_guide_src/source/general/routing.rst
index a6332c90c..2a0332088 100644
--- a/user_guide_src/source/general/routing.rst
+++ b/user_guide_src/source/general/routing.rst
@@ -9,34 +9,34 @@ normally follow this pattern::
example.com/class/function/id/
In some instances, however, you may want to remap this relationship so
-that a different class/function can be called instead of the one
+that a different class/method can be called instead of the one
corresponding to the URL.
-For example, lets say you want your URLs to have this prototype:
+For example, lets say you want your URLs to have this prototype::
-example.com/product/1/
-example.com/product/2/
-example.com/product/3/
-example.com/product/4/
+ example.com/product/1/
+ example.com/product/2/
+ example.com/product/3/
+ example.com/product/4/
-Normally the second segment of the URL is reserved for the function
-name, but in the example above it instead has a product ID. To overcome
-this, CodeIgniter allows you to remap the URI handler.
+Normally the second segment of the URL is reserved for the method
+name, but in the example above it instead has a product ID. To
+overcome this, CodeIgniter allows you to remap the URI handler.
Setting your own routing rules
==============================
-Routing rules are defined in your application/config/routes.php file. In
-it you'll see an array called $route that permits you to specify your
-own routing criteria. Routes can either be specified using wildcards or
-Regular Expressions.
+Routing rules are defined in your *application/config/routes.php* file.
+In it you'll see an array called ``$route`` that permits you to specify
+your own routing criteria. Routes can either be specified using wildcards
+or Regular Expressions.
Wildcards
=========
A typical wildcard route might look something like this::
- $route['product/:num'] = "catalog/product_lookup";
+ $route['product/:num'] = 'catalog/product_lookup';
In a route, the array key contains the URI to be matched, while the
array value contains the destination it should be re-routed to. In the
@@ -66,21 +66,21 @@ Examples
Here are a few routing examples::
- $route['journals'] = "blogs";
+ $route['journals'] = 'blogs';
A URL containing the word "journals" in the first segment will be
remapped to the "blogs" class.
::
- $route['blog/joe'] = "blogs/users/34";
+ $route['blog/joe'] = 'blogs/users/34';
A URL containing the segments blog/joe will be remapped to the "blogs"
class and the "users" method. The ID will be set to "34".
::
- $route['product/(:any)'] = "catalog/product_lookup";
+ $route['product/(:any)'] = 'catalog/product_lookup';
A URL with "product" as the first segment, and anything in the second
will be remapped to the "catalog" class and the "product_lookup"
@@ -88,12 +88,12 @@ method.
::
- $route['product/(:num)'] = "catalog/product_lookup_by_id/$1";
+ $route['product/(:num)'] = 'catalog/product_lookup_by_id/$1';
A URL with "product" as the first segment, and a number in the second
will be remapped to the "catalog" class and the
"product_lookup_by_id" method passing in the match as a variable to
-the function.
+the method.
.. important:: Do not use leading/trailing slashes.
@@ -111,7 +111,7 @@ A typical RegEx route might look something like this::
$route['products/([a-z]+)/(\d+)'] = '$1/id_$2';
In the above example, a URI similar to products/shirts/123 would instead
-call the shirts controller class and the id_123 method.
+call the "shirts" controller class and the "id_123" method.
With regular expressions, you can also catch a segment containing a
forward slash ('/'), which would usually represent the delimiter between
@@ -122,7 +122,7 @@ page after they log in, you may find this example useful::
$route['login/(.+)'] = 'auth/login/$1';
-That will call the auth controller class and its ``login()`` method,
+That will call the "auth" controller class and its ``login()`` method,
passing everything contained in the URI after *login/* as a parameter.
For those of you who don't know regular expressions and want to learn
@@ -131,6 +131,17 @@ might be a good starting point.
..note:: You can also mix and match wildcards with regular expressions.
+Callbacks
+=========
+
+If you are using PHP >= 5.3 you can use callbacks in place of the normal
+routing rules to process the back-references. Example::
+
+ $route['products/([a-z]+)/edit/(\d+)'] = function ($product_type, $id)
+ {
+ return 'catalog/product_edit/' . strtolower($product_type) . '/' . $id;
+ };
+
Reserved Routes
===============
@@ -150,9 +161,9 @@ appear by default.
This route indicates which controller class should be loaded if the
requested controller is not found. It will override the default 404
-error page. It won't affect to the show_404() function, which will
-continue loading the default error_404.php file at
-application/errors/error_404.php.
+error page. It won't affect to the ``show_404()`` function, which will
+continue loading the default *error_404.php* file at
+*application/errors/error_404.php*.
.. important:: The reserved routes must come before any wildcard or
- regular expression routes.
+ regular expression routes. \ No newline at end of file
diff --git a/user_guide_src/source/general/security.rst b/user_guide_src/source/general/security.rst
index 4d7a213d1..984ca840b 100644
--- a/user_guide_src/source/general/security.rst
+++ b/user_guide_src/source/general/security.rst
@@ -13,38 +13,40 @@ in your URI strings in order to help minimize the possibility that
malicious data can be passed to your application. URIs may only contain
the following:
-- Alpha-numeric text
+- Alpha-numeric text (latin characters only)
- Tilde: ~
- Period: .
- Colon: :
- Underscore: \_
- Dash: -
+- Pipe: |
Register_globals
=================
During system initialization all global variables are unset, except
-those found in the $_GET, $_POST, and $_COOKIE arrays. The unsetting
-routine is effectively the same as register_globals = off.
+those found in the ``$_GET``, ``$_POST``, and ``$_COOKIE`` arrays.
+The unsetting routine is effectively the same as
+*register_globals = off*.
-error_reporting
-================
+display_errors
+==============
-In production environments, it is typically desirable to disable PHP's
-error reporting by setting the internal error_reporting flag to a value
+In production environments, it is typically desirable to "disable" PHP's
+error reporting by setting the internal *display_errors* flag to a value
of 0. This disables native PHP errors from being rendered as output,
which may potentially contain sensitive information.
Setting CodeIgniter's **ENVIRONMENT** constant in index.php to a value of
**\'production\'** will turn off these errors. In development mode, it is
recommended that a value of 'development' is used. More information
-about differentiating between environments can be found on the :doc:`Handling
-Environments <environments>` page.
+about differentiating between environments can be found on the
+:doc:`Handling Environments <environments>` page.
magic_quotes_runtime
-======================
+====================
-The magic_quotes_runtime directive is turned off during system
+The *magic_quotes_runtime* directive is turned off during system
initialization so that you don't have to remove slashes when retrieving
data from your database.
@@ -68,7 +70,7 @@ XSS Filtering
=============
CodeIgniter comes with a Cross Site Scripting filter. This filter
-looks for commonly used techniques to embed malicious Javascript into
+looks for commonly used techniques to embed malicious JavaScript into
your data, or other types of code that attempt to hijack cookies or
do other malicious things. The XSS Filter is described
:doc:`here <../libraries/security>`.
@@ -76,15 +78,32 @@ do other malicious things. The XSS Filter is described
Validate the data
=================
-CodeIgniter has a :doc:`Form Validation
-Class <../libraries/form_validation>` that assists you in
+CodeIgniter has a :doc:`Form Validation Library
+<../libraries/form_validation>` that assists you in
validating, filtering, and prepping your data.
Escape all data before database insertion
=========================================
Never insert information into your database without escaping it.
-Please see the section that discusses
-:doc:`queries <../database/queries>` for more information.
+Please see the section that discusses :doc:`database queries
+<../database/queries>` for more information.
+Hide your files
+===============
+Another good security practice is to only leave your *index.php*
+and "assets" (e.g. .js, css and image files) under your server's
+*webroot* directory (most commonly named "htdocs/"). These are
+the only files that you would need to be accessible from the web.
+
+Allowing your visitors to see anything else would potentially
+allow them to access sensitive data, execute scripts, etc.
+
+If you're not allowed to do that, you can try using a .htaccess
+file to restrict access to those resources.
+
+CodeIgniter will have an index.html file in all of its
+directories in an attempt to hide some of this data, but have
+it in mind that this is not enough to prevent a serious
+attacker. \ No newline at end of file
diff --git a/user_guide_src/source/general/styleguide.rst b/user_guide_src/source/general/styleguide.rst
index 925954c03..7c0a59791 100644
--- a/user_guide_src/source/general/styleguide.rst
+++ b/user_guide_src/source/general/styleguide.rst
@@ -168,11 +168,11 @@ picked up by IDEs::
/**
* Encodes string for use in XML
*
- * @param string
+ * @param string $str Input string
* @return string
*/
function xml_encode($str)
-
+
::
/**
@@ -180,9 +180,7 @@ picked up by IDEs::
*
* @var array
*/
- public $data
-
-
+ public $data = array();
Use single line comments within code, leaving a blank line between large
comment blocks and code.
@@ -308,8 +306,8 @@ Use **===** and **!==** as necessary.
}
-See also information regarding
-`typecasting <http://us3.php.net/manual/en/language.types.type-juggling.php#language.types.typecasting>`_,
+See also information regarding `typecasting
+<http://php.net/manual/en/language.types.type-juggling.php#language.types.typecasting>`_,
which can be quite useful. Typecasting has a slightly different effect
which may be desirable. When casting a variable as a string, for
instance, NULL and boolean FALSE variables become empty strings, 0 (and
@@ -338,7 +336,6 @@ begin before CodeIgniter outputs its content, leading to errors and an
inability for CodeIgniter to send proper headers. In the examples below,
select the text with your mouse to reveal the incorrect whitespace.
-
Compatibility
=============
@@ -559,16 +556,16 @@ code abstraction, should be prefixed with an underscore.
::
- convert_text() // public method
- _convert_text() // private method
+ public function convert_text()
+ private function _convert_text()
PHP Errors
==========
Code must run error free and not rely on warnings and notices to be
hidden to meet this requirement. For instance, never access a variable
-that you did not set yourself (such as $_POST array keys) without first
-checking to see that it isset().
+that you did not set yourself (such as ``$_POST`` array keys) without first
+checking to see that it ``isset()``.
Make sure that while developing your add-on, error reporting is enabled
for ALL users, and that display_errors is enabled in the PHP
@@ -579,22 +576,22 @@ environment. You can check this setting with::
exit "Enabled";
}
-On some servers where display_errors is disabled, and you do not have
+On some servers where *display_errors* is disabled, and you do not have
the ability to change this in the php.ini, you can often enable it with::
ini_set('display_errors', 1);
-**NOTE:** Setting the
-`display_errors <http://us.php.net/manual/en/ref.errorfunc.php#ini.display-errors>`_
-setting with ini_set() at runtime is not identical to having it enabled
-in the PHP environment. Namely, it will not have any effect if the
-script has fatal errors
+.. note:: Setting the `display_errors
+ <http://php.net/manual/en/ref.errorfunc.php#ini.display-errors>`_
+ setting with ``ini_set()`` at runtime is not identical to having
+ it enabled in the PHP environment. Namely, it will not have any
+ effect if the script has fatal errors.
Short Open Tags
===============
Always use full PHP opening tags, in case a server does not have
-short_open_tag enabled.
+*short_open_tag* enabled.
**INCORRECT**::
@@ -606,6 +603,8 @@ short_open_tag enabled.
<?php echo $foo; ?>
+.. note:: PHP 5.4 will always have the **<?=** tag available.
+
One Statement Per Line
======================
@@ -645,7 +644,7 @@ characters.
SQL Queries
===========
-MySQL keywords are always capitalized: SELECT, INSERT, UPDATE, WHERE,
+SQL keywords are always capitalized: SELECT, INSERT, UPDATE, WHERE,
AS, JOIN, ON, IN, etc.
Break up long queries into multiple lines for legibility, preferably
@@ -674,5 +673,4 @@ Whenever appropriate, provide function argument defaults, which helps
prevent PHP errors with mistaken calls and provides common fallback
values which can save a few lines of code. Example::
- function foo($bar = '', $baz = FALSE)
-
+ function foo($bar = '', $baz = FALSE) \ No newline at end of file
diff --git a/user_guide_src/source/general/urls.rst b/user_guide_src/source/general/urls.rst
index 6b390b559..d678e4a0a 100644
--- a/user_guide_src/source/general/urls.rst
+++ b/user_guide_src/source/general/urls.rst
@@ -20,7 +20,6 @@ approach, usually represent::
example.com/class/function/ID
-
#. The first segment represents the controller **class** that should be
invoked.
#. The second segment represents the class **function**, or method, that
@@ -28,9 +27,28 @@ approach, usually represent::
#. The third, and any additional segments, represent the ID and any
variables that will be passed to the controller.
-The :doc:`URI Class <../libraries/uri>` and the :doc:`URL Helper <../helpers/url_helper>` contain functions that make it
-easy to work with your URI data. In addition, your URLs can be remapped
-using the :doc:`URI Routing <routing>` feature for more flexibility.
+The :doc:`URI Library <../libraries/uri>` and the :doc:`URL Helper
+<../helpers/url_helper>` contain functions that make it easy to work
+with your URI data. In addition, your URLs can be remapped using the
+:doc:`URI Routing <routing>` feature for more flexibility.
+
+Friendly URLs
+=============
+
+As you might guess, since there's a straight relationship between
+URI segments and the controller/method pair that's being called,
+those two determining segments must represent a valid class and
+method name.
+You may however also use dashes in the class/method-representing
+segments, and they will automatically be translated to underscores
+in order to be valid routed segments.
+
+For example::
+
+ example.com/my-settings/change-password/
+
+The above example will route to the ``My_settings`` controller and
+its method ``change_password()``.
Removing the index.php file
===========================
@@ -39,7 +57,7 @@ By default, the **index.php** file will be included in your URLs::
example.com/index.php/news/article/my_article
-If your Apache server has mod_rewrite enabled, you can easily remove this
+If your Apache server has *mod_rewrite* enabled, you can easily remove this
file by using a .htaccess file with some simple rules. Here is an example
of such a file, using the "negative" method in which everything is redirected
except the specified items:
@@ -54,7 +72,10 @@ except the specified items:
In the above example, any HTTP request other than those for existing
directories and existing files is treated as a request for your index.php file.
-.. note:: Note: These specific rules might not work for all server configurations.
+.. note:: These specific rules might not work for all server configurations.
+
+.. note:: Make sure to also exclude from the above rule any assets that you
+ might need to be accessible from the outside world.
Adding a URL Suffix
===================
@@ -91,7 +112,7 @@ active. Your controllers and functions will then be accessible using the
index.php?c=controller&m=method
-.. note:: If you are using query strings you will have to build
- your own URLs, rather than utilizing the URL helpers (and other helpers
- that generate URLs, like some of the form helpers) as these are designed
- to work with segment based URLs.
+.. note:: If you are using query strings you will have to build your own
+ URLs, rather than utilizing the URL helpers (and other helpers
+ that generate URLs, like some of the form helpers) as these are
+ designed to work with segment based URLs. \ No newline at end of file
diff --git a/user_guide_src/source/general/views.rst b/user_guide_src/source/general/views.rst
index 9b7c9daaa..4b1ab3c34 100644
--- a/user_guide_src/source/general/views.rst
+++ b/user_guide_src/source/general/views.rst
@@ -31,20 +31,22 @@ in it::
</body>
</html>
-Then save the file in your application/views/ folder.
+Then save the file in your *application/views/* directory.
Loading a View
==============
-To load a particular view file you will use the following function::
+To load a particular view file you will use the following method::
$this->load->view('name');
-Where name is the name of your view file. Note: The .php file extension
-does not need to be specified unless you use something other than .php.
+Where name is the name of your view file.
+
+.. note:: The .php file extension does not need to be specified
+ unless you use something other than .php.
Now, open the controller file you made earlier called blog.php, and
-replace the echo statement with the view loading function::
+replace the echo statement with the view loading method::
<?php
class Blog extends CI_Controller {
@@ -54,7 +56,6 @@ replace the echo statement with the view loading function::
$this->load->view('blogview');
}
}
- ?>
If you visit your site using the URL you did earlier you should see your
new view. The URL was similar to this::
@@ -65,7 +66,7 @@ Loading multiple views
======================
CodeIgniter will intelligently handle multiple calls to
-$this->load->view from within a controller. If more than one call
+``$this->load->view()`` from within a controller. If more than one call
happens they will be appended together. For example, you may wish to
have a header view, a menu view, a content view, and a footer view. That
might look something like this::
@@ -84,32 +85,31 @@ might look something like this::
}
}
- ?>
In the example above, we are using "dynamically added data", which you
will see below.
-Storing Views within Sub-folders
-================================
+Storing Views within Sub-directories
+====================================
-Your view files can also be stored within sub-folders if you prefer that
-type of organization. When doing so you will need to include the folder
-name loading the view. Example::
+Your view files can also be stored within sub-directories if you prefer
+that type of organization. When doing so you will need to include the
+directory name loading the view. Example::
- $this->load->view('folder_name/file_name');
+ $this->load->view('directory_name/file_name');
Adding Dynamic Data to the View
===============================
Data is passed from the controller to the view by way of an **array** or
-an **object** in the second parameter of the view loading function. Here
+an **object** in the second parameter of the view loading method. Here
is an example using an array::
$data = array(
- 'title' => 'My Title',
- 'heading' => 'My Heading',
- 'message' => 'My Message'
- );
+ 'title' => 'My Title',
+ 'heading' => 'My Heading',
+ 'message' => 'My Message'
+ );
$this->load->view('blogview', $data);
@@ -118,8 +118,8 @@ And here's an example using an object::
$data = new Someclass();
$this->load->view('blogview', $data);
-Note: If you use an object, the class variables will be turned into
-array elements.
+.. note:: If you use an object, the class variables will be turned
+ into array elements.
Let's try it with your controller file. Open it add this code::
@@ -134,7 +134,6 @@ Let's try it with your controller file. Open it add this code::
$this->load->view('blogview', $data);
}
}
- ?>
Now open your view file and change the text to variables that correspond
to the array keys in your data::
@@ -174,7 +173,6 @@ Here's a simple example. Add this to your controller::
$this->load->view('blogview', $data);
}
}
- ?>
Now open your view file and create a loop::
@@ -200,17 +198,16 @@ Now open your view file and create a loop::
.. note:: You'll notice that in the example above we are using PHP's
alternative syntax. If you are not familiar with it you can read about
- it :doc:`here </general/alternative_php>`.
+ it :doc:`here <alternative_php>`.
Returning views as data
=======================
There is a third **optional** parameter lets you change the behavior of
-the function so that it returns data as a string rather than sending it
+the method so that it returns data as a string rather than sending it
to your browser. This can be useful if you want to process the data in
-some way. If you set the parameter to true (boolean) it will return
+some way. If you set the parameter to TRUE (boolean) it will return
data. The default behavior is false, which sends it to your browser.
Remember to assign it to a variable if you want the data returned::
- $string = $this->load->view('myfile', '', true);
-
+ $string = $this->load->view('myfile', '', TRUE); \ No newline at end of file
diff --git a/user_guide_src/source/general/welcome.rst b/user_guide_src/source/general/welcome.rst
index b28c3bcc2..b6f473c2b 100644
--- a/user_guide_src/source/general/welcome.rst
+++ b/user_guide_src/source/general/welcome.rst
@@ -29,4 +29,4 @@ CodeIgniter is right for you if:
- You do not want to be forced to learn a templating language (although
a template parser is optionally available if you desire one).
- You eschew complexity, favoring simple solutions.
-- You need clear, thorough documentation.
+- You need clear, thorough documentation. \ No newline at end of file
diff --git a/user_guide_src/source/helpers/array_helper.rst b/user_guide_src/source/helpers/array_helper.rst
index 15b5e17c4..9435b3ac7 100644
--- a/user_guide_src/source/helpers/array_helper.rst
+++ b/user_guide_src/source/helpers/array_helper.rst
@@ -10,9 +10,7 @@ arrays.
Loading this Helper
===================
-This helper is loaded using the following code
-
-::
+This helper is loaded using the following code::
$this->load->helper('array');
@@ -21,20 +19,19 @@ The following functions are available:
element()
=========
-.. php:method:: element($item, $array, $default = NULL)
-
- :param string $item: Item to fetch from the array
- :param array $array: Input array
- :param boolean $default: What to return if the array isn't valid
- :returns: NULL on failure or the array item.
+.. php:function:: element($item, $array, $default = NULL)
+ :param string $item: Item to fetch from the array
+ :param array $array: Input array
+ :param bool $default: What to return if the array isn't valid
+ :returns: NULL on failure or the array item.
Lets you fetch an item from an array. The function tests whether the
array index is set and whether it has a value. If a value exists it is
returned. If a value does not exist it returns NULL, or whatever you've
-specified as the default value via the third parameter. Example
+specified as the default value via the third parameter.
-::
+Example::
$array = array(
'color' => 'red',
@@ -48,21 +45,19 @@ specified as the default value via the third parameter. Example
elements()
==========
+.. php:function:: elements($items, $array, $default = NULL)
+
+ :param string $item: Item to fetch from the array
+ :param array $array: Input array
+ :param bool $default: What to return if the array isn't valid
+ :returns: NULL on failure or the array item.
+
Lets you fetch a number of items from an array. The function tests
whether each of the array indices is set. If an index does not exist it
is set to NULL, or whatever you've specified as the default value via
the third parameter.
-.. php:method:: elements($items, $array, $default = NULL)
-
- :param string $item: Item to fetch from the array
- :param array $array: Input array
- :param boolean $default: What to return if the array isn't valid
- :returns: NULL on failure or the array item.
-
-Example
-
-::
+Example::
$array = array(
'color' => 'red',
@@ -73,9 +68,7 @@ Example
$my_shape = elements(array('color', 'shape', 'height'), $array);
-The above will return the following array
-
-::
+The above will return the following array::
array(
'color' => 'red',
@@ -83,15 +76,12 @@ The above will return the following array
'height' => NULL
);
-You can set the third parameter to any default value you like
-
+You can set the third parameter to any default value you like.
::
$my_shape = elements(array('color', 'shape', 'height'), $array, 'foobar');
-The above will return the following array
-
-::
+The above will return the following array::
array(     
'color' => 'red',
@@ -99,9 +89,9 @@ The above will return the following array
'height' => 'foobar'
);
-This is useful when sending the $_POST array to one of your Models.
+This is useful when sending the ``$_POST`` array to one of your Models.
This prevents users from sending additional POST data to be entered into
-your tables
+your tables.
::
@@ -116,15 +106,14 @@ updated.
random_element()
================
-Takes an array as input and returns a random element from it. Usage
-example
+.. php:function:: random_element($array)
-.. php:method:: random_element($array)
+ :param array $array: Input array
+ :returns: string (a random element from the array)
- :param array $array: Input array
- :returns: String - Random element from the array.
+Takes an array as input and returns a random element from it.
-::
+Usage example::
$quotes = array(
"I find that the harder I work, the more luck I seem to have. - Thomas Jefferson",
@@ -135,5 +124,4 @@ example
"Chance favors the prepared mind - Louis Pasteur"
);
- echo random_element($quotes);
-
+ echo random_element($quotes); \ No newline at end of file
diff --git a/user_guide_src/source/helpers/captcha_helper.rst b/user_guide_src/source/helpers/captcha_helper.rst
index 90244739b..17462a8de 100644
--- a/user_guide_src/source/helpers/captcha_helper.rst
+++ b/user_guide_src/source/helpers/captcha_helper.rst
@@ -11,78 +11,72 @@ Loading this Helper
===================
This helper is loaded using the following code
-
::
$this->load->helper('captcha');
The following functions are available:
-create_captcha($data)
-=====================
+create_captcha()
+================
+
+.. php:function:: function create_captcha($data = '', $img_path = '', $img_url = '', $font_path = '')
+
+ :param array $data: Array of data for the CAPTCHA
+ :param string $img_path: Path to create the image in
+ :param string $img_url: URL to the CAPTCHA image folder
+ :param string $font_path: Server path to font
+ :returns: array('word' => $word, 'time' => $now, 'image' => $img)
Takes an array of information to generate the CAPTCHA as input and
creates the image to your specifications, returning an array of
associative data about the image.
-.. php:method:: function create_captcha($data = '', $img_path = '', $img_url = '', $font_path = '')
-
- :param array $data: array of data for the CAPTCHA
- :param string $img_path: path to create the image in
- :param string $img_url: URL to the CAPTCHA image folder
- :param string $font_path: server path to font
- :returns: array('word' => $word, 'time' => $now, 'image' => $img)
-
-
::
- [array] (
- 'image' => IMAGE TAG   
- 'time' => TIMESTAMP (in microtime)   
- 'word' => CAPTCHA WORD )
+ array(
+ 'image' => IMAGE TAG
+ 'time' => TIMESTAMP (in microtime)
+ 'word' => CAPTCHA WORD
+ )
-The "image" is the actual image tag:
-
-::
+The **image** is the actual image tag::
<img src="http://example.com/captcha/12345.jpg" width="140" height="50" />
-
-The "time" is the micro timestamp used as the image name without the
+The **time** is the micro timestamp used as the image name without the
file extension. It will be a number like this: 1139612155.3422
-The "word" is the word that appears in the captcha image, which if not
+The **word** is the word that appears in the captcha image, which if not
supplied to the function, will be a random string.
Using the CAPTCHA helper
------------------------
-Once loaded you can generate a captcha like this
-
-::
+Once loaded you can generate a captcha like this::
- $vals = array(     
- 'word' => 'Random word',     
- 'img_path' => './captcha/',     
- 'img_url' => 'http://example.com/captcha/',     
- 'font_path' => './path/to/fonts/texb.ttf',     
- 'img_width' => '150',     
- 'img_height' => 30,     
- 'expiration' => 7200     
+ $vals = array(
+ 'word' => 'Random word',
+ 'img_path' => './captcha/',
+ 'img_url' => 'http://example.com/captcha/',
+ 'font_path' => './path/to/fonts/texb.ttf',
+ 'img_width' => '150',
+ 'img_height' => 30,
+ 'expiration' => 7200
);
- $cap = create_captcha($vals); echo $cap['image'];
-
+ $cap = create_captcha($vals);
+ echo $cap['image'];
- The captcha function requires the GD image library.
-- Only the img_path and img_url are required.
-- If a "word" is not supplied, the function will generate a random
+- Only the **img_path** and **img_url** are required.
+- If a **word** is not supplied, the function will generate a random
ASCII string. You might put together your own word library that you
can draw randomly from.
- If you do not specify a path to a TRUE TYPE font, the native ugly GD
font will be used.
- The "captcha" folder must be writable (666, or 777)
-- The "expiration" (in seconds) signifies how long an image will remain
+- The **expiration** (in seconds) signifies how long an image will remain
in the captcha folder before it will be deleted. The default is two
hours.
@@ -90,14 +84,12 @@ Adding a Database
-----------------
In order for the captcha function to prevent someone from submitting,
-you will need to add the information returned from create_captcha()
-function to your database. Then, when the data from the form is
-submitted by the user you will need to verify that the data exists in
-the database and has not expired.
+you will need to add the information returned from ``create_captcha()``
+to your database. Then, when the data from the form is submitted by
+the user you will need to verify that the data exists in the database
+and has not expired.
-Here is a table prototype
-
-::
+Here is a table prototype::
CREATE TABLE captcha (  
captcha_id bigint(13) unsigned NOT NULL auto_increment,  
@@ -109,9 +101,7 @@ Here is a table prototype
);
Here is an example of usage with a database. On the page where the
-CAPTCHA will be shown you'll have something like this
-
-::
+CAPTCHA will be shown you'll have something like this::
$this->load->helper('captcha');
$vals = array(     
@@ -134,23 +124,20 @@ CAPTCHA will be shown you'll have something like this
echo '<input type="text" name="captcha" value="" />';
Then, on the page that accepts the submission you'll have something like
-this
-
-::
+this::
// First, delete old captchas
$expiration = time() - 7200; // Two hour limit
$this->db->where('captcha_time < ', $expiration)
- ->delete('captcha');
+ ->delete('captcha');
// Then see if a captcha exists:
- $sql = "SELECT COUNT(*) AS count FROM captcha WHERE word = ? AND ip_address = ? AND captcha_time > ?";
+ $sql = 'SELECT COUNT(*) AS count FROM captcha WHERE word = ? AND ip_address = ? AND captcha_time > ?';
$binds = array($_POST['captcha'], $this->input->ip_address(), $expiration);
$query = $this->db->query($sql, $binds);
$row = $query->row();
if ($row->count == 0)
{     
- echo "You must submit the word that appears in the image";
- }
-
+ echo 'You must submit the word that appears in the image.';
+ } \ No newline at end of file
diff --git a/user_guide_src/source/helpers/cookie_helper.rst b/user_guide_src/source/helpers/cookie_helper.rst
index 30e601c32..c41193c3c 100644
--- a/user_guide_src/source/helpers/cookie_helper.rst
+++ b/user_guide_src/source/helpers/cookie_helper.rst
@@ -10,9 +10,7 @@ cookies.
Loading this Helper
===================
-This helper is loaded using the following code
-
-::
+This helper is loaded using the following code::
$this->load->helper('cookie');
@@ -21,52 +19,53 @@ The following functions are available:
set_cookie()
============
+.. php:function:: set_cookie($name = '', $value = '', $expire = '', $domain = '', $path = '/', $prefix = '', $secure = FALSE, $httponly = FALSE)
+
+ :param string $name: Cookie name
+ :param string $value: Cookie value
+ :param int $expire: Number of seconds until expiration
+ :param string $domain: Cookie domain (usually: .yourdomain.com)
+ :param string $path: Cookie path
+ :param string $prefix: Cookie name prefix
+ :param bool $secure: Whether to only send the cookie through HTTPS
+ :param bool $httponly: Whether to hide the cookie from JavaScript
+ :returns: void
+
This helper function gives you view file friendly syntax to set browser
-cookies. Refer to the :doc:`Input class <../libraries/input>` for a
-description of use, as this function is an alias to
-`$this->input->set_cookie()`.
-
-.. php:method:: set_cookie($name = '', $value = '', $expire = '', $domain = '', $path = '/', $prefix = '', $secure = FALSE)
-
- :param string $name: the name of the cookie
- :param string $value: the value of the cookie
- :param string $expire: the number of seconds until expiration
- :param string $domain: the cookie domain. Usually: .yourdomain.com
- :param string $path: the cookie path
- :param string $prefix: the cookie prefix
- :param boolean $secure: secure cookie or not.
- :returns: void
+cookies. Refer to the :doc:`Input Library <../libraries/input>` for a
+description of its use, as this function is an alias for
+``CI_Input::set_cookie()``.
get_cookie()
============
-This helper function gives you view file friendly syntax to get browser
-cookies. Refer to the :doc:`Input class <../libraries/input>` for a
-description of use, as this function is an alias to `$this->input->cookie()`.
+.. php:function:: get_cookie($index = '', $xss_clean = FALSE)
-.. php:method:: get_cookie($index = '', $xss_clean = FALSE)
+ :param string $index: Cookie name
+ :param bool $xss_clean: Whether to apply XSS filtering to the returned value
+ :returns: mixed
- :param string $index: the name of the cookie
- :param boolean $xss_clean: If the resulting value should be xss_cleaned or not
- :returns: mixed
+This helper function gives you view file friendly syntax to get browser
+cookies. Refer to the :doc:`Input Library <../libraries/input>` for a
+description of itsuse, as this function is an alias for ``CI_Input::cookie()``.
delete_cookie()
===============
-Lets you delete a cookie. Unless you've set a custom path or other
-values, only the name of the cookie is needed
-
-.. php:method:: delete_cookie($name = '', $domain = '', $path = '/', $prefix = '')
+.. php:function:: delete_cookie($name = '', $domain = '', $path = '/', $prefix = '')
- :param string $name: the name of the cookie
- :param string $domain: cookie domain (ususally .example.com)
- :param string $path: cookie path
- :param string $prefix: cookie prefix
+ :param string $name: Cookie name
+ :param string $domain: Cookie domain (usually: .yourdomain.com)
+ :param string $path: Cookie path
+ :param string $prefix: Cookie name prefix
:returns: void
+Lets you delete a cookie. Unless you've set a custom path or other
+values, only the name of the cookie is needed.
+
::
- delete_cookie("name");
+ delete_cookie('name');
This function is otherwise identical to ``set_cookie()``, except that it
does not have the value and expiration parameters. You can submit an
diff --git a/user_guide_src/source/helpers/date_helper.rst b/user_guide_src/source/helpers/date_helper.rst
index 9de925ba7..3a3454edc 100644
--- a/user_guide_src/source/helpers/date_helper.rst
+++ b/user_guide_src/source/helpers/date_helper.rst
@@ -9,9 +9,7 @@ The Date Helper file contains functions that help you work with dates.
Loading this Helper
===================
-This helper is loaded using the following code
-
-::
+This helper is loaded using the following code::
$this->load->helper('date');
@@ -20,44 +18,45 @@ The following functions are available:
now()
=====
-Returns the current time as a Unix timestamp, referenced either to your
-server's local time or any PHP suported timezone, based on the "time reference"
-setting in your config file. If you do not intend to set your master time reference
-to any other PHP suported timezone (which you'll typically do if you run a site that
-lets each user set their own timezone settings) there is no benefit to using this
-function over PHP's time() function.
+.. php:function:: now($timezone = NULL)
-.. php:method:: now($timezone = NULL)
+ :param string $timezone: Timezone
+ :returns: int
- :param string $timezone: The timezone you want to be returned
- :returns: integer
+Returns the current time as a UNIX timestamp, referenced either to your server's
+local time or any PHP suported timezone, based on the "time reference" setting
+in your config file. If you do not intend to set your master time reference to
+any other PHP supported timezone (which you'll typically do if you run a site
+that lets each user set their own timezone settings) there is no benefit to using
+this function over PHP's ``time()`` function.
::
- echo now("Australia/Victoria");
-If a timezone is not provided, it will return time() based on "time_reference" setting.
+ echo now('Australia/Victoria');
+
+If a timezone is not provided, it will return ``time()`` based on the
+**time_reference** setting.
mdate()
=======
+.. php:function:: mdate($datestr = '', $time = '')
+
+ :param string $datestr: Date string
+ :param int $time: UNIX timestamp
+ :returns: int
+
This function is identical to PHP's `date() <http://www.php.net/date>`_
function, except that it lets you use MySQL style date codes, where each
-code letter is preceded with a percent sign: %Y %m %d etc.
+code letter is preceded with a percent sign, e.g. `%Y %m %d`
The benefit of doing dates this way is that you don't have to worry
about escaping any characters that are not date codes, as you would
-normally have to do with the date() function. Example
-
-.. php:method:: mdate($datestr = '', $time = '')
+normally have to do with the ``date()`` function.
- :param string $datestr: Date String
- :param integer $time: time
- :returns: integer
+Example::
-
-::
-
- $datestring = "Year: %Y Month: %m Day: %d - %h:%i %a";
+ $datestring = 'Year: %Y Month: %m Day: %d - %h:%i %a';
$time = time();
echo mdate($datestring, $time);
@@ -67,32 +66,30 @@ will be used.
standard_date()
===============
-Lets you generate a date string in one of several standardized formats.
-Example
+.. php:function:: standard_date($fmt = 'DATE_RFC822', $time = NULL)
-.. php:method:: standard_date($fmt = 'DATE_RFC822', $time = '')
+ :param string $fmt: Date format
+ :param int $time: UNIX timestamp
+ :returns: string
- :param string $fmt: the chosen format
- :param string $time: Unix timestamp
- :returns: string
+Lets you generate a date string in one of several standardized formats.
-::
+Example::
$format = 'DATE_RFC822';
$time = time();
echo standard_date($format, $time);
-The first parameter must contain the format, the second parameter must
-contain the date as a Unix timestamp.
-
-.. note:: This function is DEPRECATED. Use the native ``date()`` combined
- with `DateTime's format constants <http://www.php.net/manual/en/class.datetime.php#datetime.constants.types>`_
+.. note:: This function is DEPRECATED.Use the native ``date()`` combined with
+ `DateTime's format constants
+ <http://www.php.net/manual/en/class.datetime.php#datetime.constants.types>`_
instead:
|
| echo date(DATE_RFC822, time());
-Supported formats:
+Supported formats
+-----------------
=============== ======================= ======================================
Constant Description Example
@@ -112,39 +109,34 @@ DATE_W3C W3C 2005-08-14T16:13:03+0000
local_to_gmt()
==============
-Takes a Unix timestamp as input and returns it as GMT.
+.. php:function:: local_to_gmt($time = '')
-.. php:method:: local_to_gmt($time = '')
+ :param int $time: UNIX timestamp
+ :returns: string
- :param integer $time: Unix timestamp
- :returns: string
+Takes a UNIX timestamp as input and returns it as GMT.
-Example:
+Example::
-::
-
- $now = time();
- $gmt = local_to_gmt($now);
+ $gmt = local_to_gmt(time());
gmt_to_local()
==============
-Takes a Unix timestamp (referenced to GMT) as input, and converts it to
-a localized timestamp based on the timezone and Daylight Saving time
-submitted.
-
-.. php:method:: gmt_to_local($time = '', $timezone = 'UTC', $dst = FALSE)
+.. php:function:: gmt_to_local($time = '', $timezone = 'UTC', $dst = FALSE)
- :param integer $time: Unix timestamp
- :param string $timezone: timezone
- :param boolean $dst: whether DST is active
- :returns: integer
+ :param int $time: UNIX timestamp
+ :param string $timezone: Timezone
+ :param bool $dst: Whether DST is active
+ :returns: int
-Example
+Takes a UNIX timestamp (referenced to GMT) as input, and converts it to
+a localized timestamp based on the timezone and Daylight Saving Time
+submitted.
-::
+Example::
- $timestamp = '1140153693';
+ $timestamp = 1140153693;
$timezone = 'UM8';
$daylight_saving = TRUE;
echo gmt_to_local($timestamp, $timezone, $daylight_saving);
@@ -152,40 +144,32 @@ Example
.. note:: For a list of timezones see the reference at the bottom of this page.
-
mysql_to_unix()
===============
-Takes a MySQL Timestamp as input and returns it as Unix.
+.. php:function:: mysql_to_unix($time = '')
-.. php:method:: mysql_to_unix($time = '')
+ :param int $time: UNIX timestamp
+ :returns: int
- :param integer $time: Unix timestamp
- :returns: integer
-
-Example
+Takes a MySQL Timestamp as input and returns it as a UNIX timestamp.
-::
+Example::
- $mysql = '20061124092345';
- $unix = mysql_to_unix($mysql);
+ $unix = mysql_to_unix('20061124092345');
unix_to_human()
===============
-Takes a Unix timestamp as input and returns it in a human readable
-format with this prototype
+.. php:function:: unix_to_human($time = '', $seconds = FALSE, $fmt = 'us')
-.. php:method:: unix_to_human($time = '', $seconds = FALSE, $fmt = 'us')
-
- :param integer $time: Unix timestamp
- :param boolean $seconds: whether to show seconds
- :param string $fmt: format: us or euro
+ :param int $time: UNIX timestamp
+ :param bool $seconds: Whether to show seconds
+ :param string $fmt: format (us or euro)
:returns: integer
-Example
-
-::
+Takes a UNIX timestamp as input and returns it in a human readable
+format with this prototype::
YYYY-MM-DD HH:MM:SS AM/PM
@@ -194,9 +178,9 @@ submission.
The time can be formatted with or without seconds, and it can be set to
European or US format. If only the timestamp is submitted it will return
-the time without seconds formatted for the U.S. Examples
+the time without seconds formatted for the U.S.
-::
+Examples::
$now = time();
echo unix_to_human($now); // U.S. time, no seconds
@@ -206,19 +190,17 @@ the time without seconds formatted for the U.S. Examples
human_to_unix()
===============
-The opposite of the above function. Takes a "human" time as input and
-returns it as Unix. This function is useful if you accept "human"
-formatted dates submitted via a form. Returns FALSE (boolean) if the
-date string passed to it is not formatted as indicated above.
+.. php:function:: human_to_unix($datestr = '')
-.. php:method:: human_to_unix($datestr = '')
-
- :param integer $datestr: Date String
- :returns: integer
+ :param int $datestr: Date string
+ :returns: int UNIX timestamp or FALSE on failure
-Example:
+The opposite of the :php:func:`unix_to_time()` function. Takes a "human"
+time as input and returns it as a UNIX timestamp. This is useful if you
+accept "human" formatted dates submitted via a form. Returns boolean FALSE
+date string passed to it is not formatted as indicated above.
-::
+Example::
$now = time();
$human = unix_to_human($now);
@@ -227,22 +209,20 @@ Example:
nice_date()
===========
-This function can take a number poorly-formed date formats and convert
-them into something useful. It also accepts well-formed dates.
-
-The function will return a Unix timestamp by default. You can,
-optionally, pass a format string (the same type as the PHP date function
-accepts) as the second parameter.
+.. php:function:: nice_date($bad_date = '', $format = FALSE)
-.. php:method:: nice_date($bad_date = '', $format = FALSE)
+ :param int $bad_date: The terribly formatted date-like string
+ :param string $format: Date format to return (same as PHP's ``date()`` function)
+ :returns: string
- :param integer $bad_date: The terribly formatted date-like string
- :param string $format: Date format to return (same as php date function)
- :returns: string
+This function can take a number poorly-formed date formats and convert
+them into something useful. It also accepts well-formed dates.
-Example
+The function will return a UNIX timestamp by default. You can, optionally,
+pass a format string (the same type as the PHP ``date()`` function accepts)
+as the second parameter.
-::
+Example::
$bad_date = '199605';
// Should Produce: 1996-05-01
@@ -255,28 +235,28 @@ Example
timespan()
==========
-Formats a unix timestamp so that is appears similar to this
-::
+.. php:function:: timespan($seconds = 1, $time = '', $units = '')
- 1 Year, 10 Months, 2 Weeks, 5 Days, 10 Hours, 16 Minutes
+ :param int $seconds: Number of seconds
+ :param string $time: UNIX timestamp
+ :param int $units: Number of time units to display
+ :returns: string
-The first parameter must contain a Unix timestamp. The second parameter
-must contain a timestamp that is greater that the first timestamp. If
-the second parameter empty, the current time will be used. The third
-parameter is optional and limits the number of time units to display.
-The most common purpose for this function is to show how much time has
-elapsed from some point in time in the past to now.
+Formats a UNIX timestamp so that is appears similar to this::
-.. php:method:: timespan($seconds = 1, $time = '', $units = '')
+ 1 Year, 10 Months, 2 Weeks, 5 Days, 10 Hours, 16 Minutes
- :param integer $seconds: a number of seconds
- :param string $time: Unix timestamp
- :param integer $units: a number of time units to display
- :returns: string
+The first parameter must contain a UNIX timestamp.
+The second parameter must contain a timestamp that is greater that the
+first timestamp.
+The thirdparameter is optional and limits the number of time units to display.
-Example
+If the second parameter empty, the current time will be used.
-::
+The most common purpose for this function is to show how much time has
+elapsed from some point in time in the past to now.
+
+Example::
$post_date = '1079621429';
$now = time();
@@ -284,23 +264,21 @@ Example
echo timespan($post_date, $now, $units);
.. note:: The text generated by this function is found in the following language
- file: language/<your_lang>/date_lang.php
+ file: `language/<your_lang>/date_lang.php`
days_in_month()
===============
-Returns the number of days in a given month/year. Takes leap years into
-account.
+.. php:function:: days_in_month($month = 0, $year = '')
-.. php:method:: days_in_month($month = 0, $year = '')
+ :param int $month: a numeric month
+ :param int $year: a numeric year
+ :returns: int
- :param integer $month: a numeric month
- :param integer $year: a numeric year
- :returns: integer
-
-Example
+Returns the number of days in a given month/year. Takes leap years into
+account.
-::
+Example::
echo days_in_month(06, 2005);
@@ -309,19 +287,17 @@ If the second parameter is empty, the current year will be used.
date_range()
============
-Returns a list of dates within a specified period.
-
-.. php:method:: date_range($unix_start = '', $mixed = '', $is_unix = TRUE, $format = 'Y-m-d')
+.. php:function:: date_range($unix_start = '', $mixed = '', $is_unix = TRUE, $format = 'Y-m-d')
- :param integer $unix_start: UNIX timestamp of the range start date
- :param integer $mixed: UNIX timestamp of the range end date or interval in days
- :param boolean $is_unix: set to FALSE if $mixed is not a timestamp
- :param string $format: output date format, same as in date()
- :returns: array
+ :param int $unix_start: UNIX timestamp of the range start date
+ :param int $mixed: UNIX timestamp of the range end date or interval in days
+ :param bool $is_unix: set to FALSE if $mixed is not a timestamp
+ :param string $format: Output date format, same as in ``date()``
+ :returns: array
-Example
+Returns a list of dates within a specified period.
-::
+Example::
$range = date_range('2012-01-01', '2012-01-15');
echo "First 15 days of 2012:";
@@ -333,29 +309,34 @@ Example
timezones()
===========
+.. php:function:: timezones($tz = '')
+
+ :param string $tz: a numeric timezone
+ :returns: string
+
Takes a timezone reference (for a list of valid timezones, see the
"Timezone Reference" below) and returns the number of hours offset from
UTC.
-.. php:method:: timezones($tz = '')
-
- :param string $tz: a numeric timezone
- :returns: string
-
-Example
-
-::
+Example::
echo timezones('UM5');
-This function is useful when used with `timezone_menu()`.
+This function is useful when used with :php:func:`timezone_menu()`.
timezone_menu()
===============
-Generates a pull-down menu of timezones, like this one:
+.. php:function:: timezone_menu($default = 'UTC', $class = '', $name = 'timezones', $attributes = '')
+ :param string $default: Timezone
+ :param string $class: Class name
+ :param string $name: Menu name
+ :param mixed $attributes: HTML attributes
+ :returns: string
+
+Generates a pull-down menu of timezones, like this one:
.. raw:: html
@@ -409,19 +390,7 @@ This menu is useful if you run a membership site in which your users are
allowed to set their local timezone value.
The first parameter lets you set the "selected" state of the menu. For
-example, to set Pacific time as the default you will do this
-
-.. php:method:: timezone_menu($default = 'UTC', $class = '', $name = 'timezones', $attributes = '')
-
- :param string $default: timezone
- :param string $class: classname
- :param string $name: menu name
- :param mixed $attributes: attributes
- :returns: string
-
-Example:
-
-::
+example, to set Pacific time as the default you will do this::
echo timezone_menu('UM8');
@@ -445,37 +414,37 @@ Note some of the location lists have been abridged for clarity and formatting.
=========== =====================================================================
Time Zone Location
=========== =====================================================================
-UM2 (UTC - 12:00) Baker/Howland Island
-UM1 (UTC - 11:00) Samoa Time Zone, Niue
-UM0 (UTC - 10:00) Hawaii-Aleutian Standard Time, Cook Islands
+UM2 (UTC - 12:00) Baker/Howland Island
+UM1 (UTC - 11:00) Samoa Time Zone, Niue
+UM0 (UTC - 10:00) Hawaii-Aleutian Standard Time, Cook Islands
UM95 (UTC - 09:30) Marquesas Islands
-UM9 (UTC - 09:00) Alaska Standard Time, Gambier Islands
-UM8 (UTC - 08:00) Pacific Standard Time, Clipperton Island
-UM7 (UTC - 11:00) Mountain Standard Time
-UM6 (UTC - 06:00) Central Standard Time
-UM5 (UTC - 05:00) Eastern Standard Time, Western Caribbean
+UM9 (UTC - 09:00) Alaska Standard Time, Gambier Islands
+UM8 (UTC - 08:00) Pacific Standard Time, Clipperton Island
+UM7 (UTC - 11:00) Mountain Standard Time
+UM6 (UTC - 06:00) Central Standard Time
+UM5 (UTC - 05:00) Eastern Standard Time, Western Caribbean
UM45 (UTC - 04:30) Venezuelan Standard Time
-UM4 (UTC - 04:00) Atlantic Standard Time, Eastern Caribbean
+UM4 (UTC - 04:00) Atlantic Standard Time, Eastern Caribbean
UM35 (UTC - 03:30) Newfoundland Standard Time
-UM3 (UTC - 03:00) Argentina, Brazil, French Guiana, Uruguay
-UM2 (UTC - 02:00) South Georgia/South Sandwich Islands
-UM (UTC -1:00) Azores, Cape Verde Islands
-UTC (UTC) Greenwich Mean Time, Western European Time
-UP1 (UTC +1:00) Central European Time, West Africa Time
-UP2 (UTC +2:00) Central Africa Time, Eastern European Time
-UP3 (UTC +3:00) Moscow Time, East Africa Time
+UM3 (UTC - 03:00) Argentina, Brazil, French Guiana, Uruguay
+UM2 (UTC - 02:00) South Georgia/South Sandwich Islands
+UM (UTC -1:00) Azores, Cape Verde Islands
+UTC (UTC) Greenwich Mean Time, Western European Time
+UP1 (UTC +1:00) Central European Time, West Africa Time
+UP2 (UTC +2:00) Central Africa Time, Eastern European Time
+UP3 (UTC +3:00) Moscow Time, East Africa Time
UP35 (UTC +3:30) Iran Standard Time
-UP4 (UTC +4:00) Azerbaijan Standard Time, Samara Time
+UP4 (UTC +4:00) Azerbaijan Standard Time, Samara Time
UP45 (UTC +4:30) Afghanistan
-UP5 (UTC +5:00) Pakistan Standard Time, Yekaterinburg Time
+UP5 (UTC +5:00) Pakistan Standard Time, Yekaterinburg Time
UP55 (UTC +5:30) Indian Standard Time, Sri Lanka Time
UP575 (UTC +5:45) Nepal Time
-UP6 (UTC +6:00) Bangladesh Standard Time, Bhutan Time, Omsk Time
+UP6 (UTC +6:00) Bangladesh Standard Time, Bhutan Time, Omsk Time
UP65 (UTC +6:30) Cocos Islands, Myanmar
-UP7 (UTC +7:00) Krasnoyarsk Time, Cambodia, Laos, Thailand, Vietnam
-UP8 (UTC +8:00) Australian Western Standard Time, Beijing Time
+UP7 (UTC +7:00) Krasnoyarsk Time, Cambodia, Laos, Thailand, Vietnam
+UP8 (UTC +8:00) Australian Western Standard Time, Beijing Time
UP875 (UTC +8:45) Australian Central Western Standard Time
-UP9 (UTC +9:00) Japan Standard Time, Korea Standard Time, Yakutsk
+UP9 (UTC +9:00) Japan Standard Time, Korea Standard Time, Yakutsk
UP95 (UTC +9:30) Australian Central Standard Time
UP10 (UTC +10:00) Australian Eastern Standard Time, Vladivostok Time
UP105 (UTC +10:30) Lord Howe Island
@@ -483,6 +452,6 @@ UP11 (UTC +11:00) Magadan Time, Solomon Islands, Vanuatu
UP115 (UTC +11:30) Norfolk Island
UP12 (UTC +12:00) Fiji, Gilbert Islands, Kamchatka, New Zealand
UP1275 (UTC +12:45) Chatham Islands Standard Time
-UP1 (UTC +13:00) Phoenix Islands Time, Tonga
+UP1 (UTC +13:00) Phoenix Islands Time, Tonga
UP14 (UTC +14:00) Line Islands
=========== ===================================================================== \ No newline at end of file
diff --git a/user_guide_src/source/helpers/directory_helper.rst b/user_guide_src/source/helpers/directory_helper.rst
index cf88732d3..a785ebc8c 100644
--- a/user_guide_src/source/helpers/directory_helper.rst
+++ b/user_guide_src/source/helpers/directory_helper.rst
@@ -57,7 +57,7 @@ be numerically indexed. Here is an example of a typical array::
(        
[0] => benchmark.html        
[1] => config.html        
- [database] => Array
+ ["database/"] => Array
(              
[0] => query_builder.html              
[1] => binds.html              
@@ -76,5 +76,4 @@ be numerically indexed. Here is an example of a typical array::
[7] => loader.html        
[8] => pagination.html        
[9] => uri.html
- )
-
+ ) \ No newline at end of file
diff --git a/user_guide_src/source/helpers/download_helper.rst b/user_guide_src/source/helpers/download_helper.rst
index e6094dc6b..1e9ec21ea 100644
--- a/user_guide_src/source/helpers/download_helper.rst
+++ b/user_guide_src/source/helpers/download_helper.rst
@@ -9,34 +9,40 @@ The Download Helper lets you download data to your desktop.
Loading this Helper
===================
-This helper is loaded using the following code
-
-::
+This helper is loaded using the following code::
$this->load->helper('download');
The following functions are available:
-force_download('filename', 'data')
-==================================
+force_download()
+================
+
+.. php:function:: force_download($filename = '', $data = '', $set_mime = FALSE)
+
+ :param string $filename: Filename
+ :param string $data: File contents
+ :param bool $set_mime: Whether to try to send the actual MIME type
+ :returns: void
Generates server headers which force data to be downloaded to your
desktop. Useful with file downloads. The first parameter is the **name
you want the downloaded file to be named**, the second parameter is the
-file data. Example
+file data.
+
+If you set the third parameter to boolean TRUE, then the actual file MIME type
+(based on the filename extension) will be sent, so that if your browser has a
+handler for that type - it can use it.
-::
+Example::
$data = 'Here is some text!';
$name = 'mytext.txt';
force_download($name, $data);
If you want to download an existing file from your server you'll need to
-read the file into a string
+read the file into a string::
-::
-
- $data = file_get_contents("/path/to/photo.jpg"); // Read the file's contents
+ $data = file_get_contents('/path/to/photo.jpg'); // Read the file's contents
$name = 'myphoto.jpg';
- force_download($name, $data);
-
+ force_download($name, $data); \ No newline at end of file
diff --git a/user_guide_src/source/helpers/email_helper.rst b/user_guide_src/source/helpers/email_helper.rst
index d4e94b1ed..10adf1d0e 100644
--- a/user_guide_src/source/helpers/email_helper.rst
+++ b/user_guide_src/source/helpers/email_helper.rst
@@ -8,6 +8,8 @@ Class <../libraries/email>`.
.. contents:: Page Contents
+.. important:: The Email helper is DEPRECATED.
+
Loading this Helper
===================
@@ -15,21 +17,21 @@ This helper is loaded using the following code::
$this->load->helper('email');
-
The following functions are available:
-valid_email('email')
-====================
+valid_email()
+=============
-Checks if an email is a correctly formatted email. Note that is doesn't
-actually prove the email will recieve mail, simply that it is a validly
-formed address.
+.. php:function:: valid_email($email)
-It returns TRUE/FALSE
+ :param string $email: Email address
+ :returns: bool
-::
+Checks if the input is a correctly formatted e-mail address. Note that is
+doesn't actually prove that the address will be able recieve mail, but
+simply that it is a validly formed address.
- $this->load->helper('email');
+Example::
if (valid_email('email@somesite.com'))
{
@@ -40,10 +42,26 @@ It returns TRUE/FALSE
echo 'email is not valid';
}
-send_email('recipient', 'subject', 'message')
-=============================================
+.. note:: All that this function does is to use PHP's native ``filter_var()``:
+ |
+ | (bool) filter_var($email, FILTER_VALIDATE_EMAIL);
-Sends an email using PHP's native
-`mail() <http://www.php.net/function.mail>`_ function. For a more robust
-email solution, see CodeIgniter's :doc:`Email
-Class <../libraries/email>`.
+send_email()
+============
+
+.. php:function:: send_email($recipient, $subject, $message)
+
+ :param string $recipient: E-mail address
+ :param string $subject: Mail subject
+ :param string $message: Message body
+ :returns: bool
+
+Sends an email using PHP's native `mail() <http://www.php.net/function.mail>`_
+function.
+
+.. note:: All that this function does is to use PHP's native ``mail``:
+ |
+ | mail($recipient, $subject, $message);
+
+For a more robust email solution, see CodeIgniter's :doc:`Email Library
+<../libraries/email>`.
diff --git a/user_guide_src/source/helpers/file_helper.rst b/user_guide_src/source/helpers/file_helper.rst
index 60c5aa98c..194d4348f 100644
--- a/user_guide_src/source/helpers/file_helper.rst
+++ b/user_guide_src/source/helpers/file_helper.rst
@@ -9,20 +9,23 @@ The File Helper file contains functions that assist in working with files.
Loading this Helper
===================
-This helper is loaded using the following code
-
-::
+This helper is loaded using the following code::
$this->load->helper('file');
The following functions are available:
-read_file('path')
-=================
+read_file()
+===========
-Returns the data contained in the file specified in the path. Example
+.. php:function:: read_file($file)
-::
+ :param string $file: File path
+ :returns: string or FALSE on failure
+
+Returns the data contained in the file specified in the path.
+
+Example::
$string = read_file('./path/to/file.php');
@@ -35,14 +38,24 @@ The path can be a relative or full server path. Returns FALSE (boolean) on failu
.. note:: This function is DEPRECATED. Use the native ``file_get_contents()``
instead.
-If your server is running an `open_basedir` restriction this function might not work if you are trying to access a file above the calling script.
+.. important:: If your server is running an **open_basedir** restriction this
+ function might not work if you are trying to access a file above the
+ calling script.
-write_file('path', $data)
-=========================
+write_file()
+============
-Writes data to the file specified in the path. If the file does not exist the function will create it. Example
+.. php:function:: write_file($path, $data, $mode = 'wb')
-::
+ :param string $path: File path
+ :param string $data: Data to write to file
+ :param string $mode: ``fopen()`` mode
+ :returns: bool
+
+Writes data to the file specified in the path. If the file does not exist then the
+function will create it.
+
+Example::
$data = 'Some file data';
if ( ! write_file('./path/to/file.php', $data))
@@ -54,85 +67,150 @@ Writes data to the file specified in the path. If the file does not exist the fu
echo 'File written!';
}
-You can optionally set the write mode via the third parameter
-
-::
+You can optionally set the write mode via the third parameter::
write_file('./path/to/file.php', $data, 'r+');
-The default mode is wb. Please see the `PHP user guide <http://php.net/fopen>`_ for mode options.
+The default mode is 'wb'. Please see the `PHP user guide <http://php.net/fopen>`_
+for mode options.
-Note: In order for this function to write data to a file its file permissions must be set such that it is writable (666, 777, etc.). If the file does not already exist, the directory containing it must be writable.
+.. note: In order for this function to write data to a file, its permissions must
+ be set such that it is writable (666, 777, etc.). If the file does not
+ already exist, the directory containing it must be writable.
.. note:: The path is relative to your main site index.php file, NOT your
controller or view files. CodeIgniter uses a front controller so paths
are always relative to the main site index.
-delete_files('path')
-====================
+.. note:: This function acquires an exclusive lock on the file while writing to it.
-Deletes ALL files contained in the supplied path. Example
+delete_files()
+==============
-::
+.. php:function:: delete_files($path, $del_dir = FALSE, $htdocs = FALSE)
+
+ :param string $path: Directory path
+ :param bool $del_dir: Whether to also delete directories
+ :param bool $htdocs: Whether to skip deleting .htaccess and index page files
+ :returns: bool
+
+Deletes ALL files contained in the supplied path.
+
+Example::
delete_files('./path/to/directory/');
-If the second parameter is set to true, any directories contained within the supplied root path will be deleted as well. Example
+If the second parameter is set to TRUE, any directories contained within the supplied
+root path will be deleted as well.
-::
+Example::
delete_files('./path/to/directory/', TRUE);
.. note:: The files must be writable or owned by the system in order to be deleted.
-get_filenames('path/to/directory/')
-===================================
+get_filenames()
+===============
+
+.. php:function:: get_filenames($source_dir, $include_path = FALSE)
+
+ :param string $source_dir: Directory path
+ :param bool $include_path: Whether to include the path as part of the filenames
+ :returns: array
-Takes a server path as input and returns an array containing the names of all files contained within it. The file path can optionally be added to the file names by setting the second parameter to TRUE.
+Takes a server path as input and returns an array containing the names of all files
+contained within it. The file path can optionally be added to the file names by setting
+the second parameter to TRUE.
-get_dir_file_info('path/to/directory/', $top_level_only = TRUE)
-===============================================================
+Example::
-Reads the specified directory and builds an array containing the filenames, filesize, dates, and permissions. Sub-folders contained within the specified path are only read if forced by sending the second parameter, $top_level_only to FALSE, as this can be an intensive operation.
+ $controllers = get_filenames(APPPATH.'controllers/');
-get_file_info('path/to/file', $file_information)
-================================================
+get_dir_file_info()
+===================
+
+.. php:function:: get_dir_file_info($source_dir, $top_level_only)
+
+ :param string $source_dir: Directory path
+ :param bool $top_level_only: Whether to look only at the specified directory
+ (excluding sub-directories)
+ :returns: array
+
+Reads the specified directory and builds an array containing the filenames, filesize,
+dates, and permissions. Sub-folders contained within the specified path are only read
+if forced by sending the second parameter to FALSE, as this can be an intensive
+operation.
+
+Example::
+
+ $models_info = get_dir_file_info(APPPATH.'models/');
+
+get_file_info()
+===============
+
+.. php:function: get_file_info($file, $returned_values = array('name', 'server_path', 'size', 'date'))
+
+ :param string $file: File path
+ :param array $returned_values: What type of info to return
+ :returns: array or FALSE on failure
-Given a file and path, returns the name, path, size, date modified. Second parameter allows you to explicitly declare what information you want returned; options are: `name`, `server_path`, `size`, `date`, `readable`, `writable`, `executable`, `fileperms`. Returns FALSE if the file cannot be found.
+Given a file and path, returns (optionally) the *name*, *path*, *size* and *date modified*
+information attributes for a file. Second parameter allows you to explicitly declare what
+information you want returned.
-.. note:: The "writable" uses the PHP function is_writable() which is known
- to have issues on the IIS webserver. Consider using fileperms instead,
- which returns information from PHP's fileperms() function.
+Valid ``$returned_values`` options are: `name`, `size`, `date`, `readable`, `writeable`,
+`executable` and `fileperms`.
-get_mime_by_extension('file')
-=============================
+.. note:: The *writable* attribute is checked via PHP's ``is_writeable()`` function, which
+ known to have issues on the IIS webserver. Consider using *fileperms* instead,
+ which returns information from PHP's ``fileperms()`` function.
-Translates a file extension into a mime type based on config/mimes.php. Returns FALSE if it can't determine the type, or open the mime config file.
+get_mime_by_extension()
+=======================
+
+.. php:function:: get_mime_by_extension($filename)
+
+ :param string $filename: File name
+ :returns: string or FALSE on failure
+
+Translates a filename extension into a MIME type based on *config/mimes.php*.
+Returns FALSE if it can't determine the type, or read the MIME config file.
::
- $file = "somefile.png";
- echo $file . ' is has a mime type of ' . get_mime_by_extension($file);
+ $file = 'somefile.png';
+ echo $file.' is has a mime type of '.get_mime_by_extension($file);
+
+.. note:: This is not an accurate way of determining file MIME types, and
+ is here strictly for convenience. It should not be used for security
+ purposes.
+symbolic_permissions()
+======================
-.. note:: This is not an accurate way of determining file mime types, and
- is here strictly as a convenience. It should not be used for security.
+.. php:function:: symbolic_permissions($perms)
-symbolic_permissions($perms)
-============================
+ :param int $perms: Permissions
+ :returns: string
-Takes numeric permissions (such as is returned by `fileperms()` and returns standard symbolic notation of file permissions.
+Takes numeric permissions (such as is returned by ``fileperms()``) and returns
+standard symbolic notation of file permissions.
::
echo symbolic_permissions(fileperms('./index.php')); // -rw-r--r--
-octal_permissions($perms)
-=========================
+octal_permissions()
+===================
-Takes numeric permissions (such as is returned by fileperms() and returns a three character octal notation of file permissions.
+.. php:function:: octal_permissions($perms)
-::
+ :param int $perms: Permissions
+ :returns: string
- echo octal_permissions(fileperms('./index.php')); // 644
+Takes numeric permissions (such as is returned by ``fileperms()``) and returns
+a three character octal notation of file permissions.
+
+::
+ echo octal_permissions(fileperms('./index.php')); // 644 \ No newline at end of file
diff --git a/user_guide_src/source/helpers/form_helper.rst b/user_guide_src/source/helpers/form_helper.rst
index 015bf1162..b2a9b6f0f 100644
--- a/user_guide_src/source/helpers/form_helper.rst
+++ b/user_guide_src/source/helpers/form_helper.rst
@@ -10,9 +10,7 @@ forms.
Loading this Helper
===================
-This helper is loaded using the following code
-
-::
+This helper is loaded using the following code::
$this->load->helper('form');
@@ -21,19 +19,27 @@ The following functions are available:
form_open()
===========
-Creates an opening form tag with a base URL **built from your config preferences**. It will optionally let you add form attributes and hidden input fields, and will always add the attribute accept-charset based on the charset value in your config file.
+.. php:function:: form_open($action = '', $attributes = '', $hidden = array())
-The main benefit of using this tag rather than hard coding your own HTML is that it permits your site to be more portable in the event your URLs ever change.
+ :param string $action: Form action/target URI string
+ :param string $attributes: HTML attributes
+ :param array $hidden: An array of hidden fields' definitions
+ :returns: string
-Here's a simple example
+Creates an opening form tag with a base URL **built from your config preferences**.
+It will optionally let you add form attributes and hidden input fields, and
+will always add the `accept-charset` attribute based on the charset value in your
+config file.
-::
+The main benefit of using this tag rather than hard coding your own HTML is that
+it permits your site to be more portable in the event your URLs ever change.
- echo form_open('email/send');
+Here's a simple example::
-The above example would create a form that points to your base URL plus the "email/send" URI segments, like this
+ echo form_open('email/send');
-::
+The above example would create a form that points to your base URL plus the
+"email/send" URI segments, like this::
<form method="post" accept-charset="utf-8" action="http://example.com/index.php/email/send" />
@@ -41,32 +47,25 @@ Adding Attributes
^^^^^^^^^^^^^^^^^
Attributes can be added by passing an associative array to the second
-parameter, like this
-
-::
+parameter, like this::
$attributes = array('class' => 'email', 'id' => 'myform');
echo form_open('email/send', $attributes);
-The above example would create a form similar to this
-
-::
+The above example would create a form similar to this::
<form method="post" accept-charset="utf-8" action="http://example.com/index.php/email/send" class="email" id="myform" />
Adding Hidden Input Fields
^^^^^^^^^^^^^^^^^^^^^^^^^^
-Hidden fields can be added by passing an associative array to the third parameter, like this
+Hidden fields can be added by passing an associative array to the
+third parameter, like this::
-::
-
- $hidden = array('username' => 'Joe', 'member_id' => '234');
+ $hidden = array('username' => 'Joe', 'member_id' => '234');
echo form_open('email/send', '', $hidden);
-The above example would create a form similar to this
-
-::
+The above example would create a form similar to this::
<form method="post" accept-charset="utf-8" action="http://example.com/index.php/email/send">
<input type="hidden" name="username" value="Joe" />
@@ -75,29 +74,38 @@ The above example would create a form similar to this
form_open_multipart()
=====================
-This function is absolutely identical to the `form_open()` tag above
-except that it adds a multipart attribute, which is necessary if you
+.. php:function:: form_open_multipart($action = '', $attributes = array(), $hidden = array())
+
+ :param string $action: Form action/target URI string
+ :param string $attributes: HTML attributes
+ :param array $hidden: An array of hidden fields' definitions
+ :returns: string
+
+This function is absolutely identical to :php:func:`form_open()` above,
+except that it adds a *multipart* attribute, which is necessary if you
would like to use the form to upload files with.
form_hidden()
=============
-Lets you generate hidden input fields. You can either submit a
-name/value string to create one field
+.. php:function:: form_hidden($name, $value = '')
-::
+ :param string $name: Field name
+ :param string $value: Field value
+ :returns: string
+
+Lets you generate hidden input fields. You can either submit a
+name/value string to create one field::
form_hidden('username', 'johndoe');
// Would produce: <input type="hidden" name="username" value="johndoe" />
-Or you can submit an associative array to create multiple fields
-
-::
+... or you can submit an associative array to create multiple fields::
$data = array(
- 'name'  => 'John Doe',
- 'email' => 'john@example.com',
- 'url'   => 'http://example.com'
+ 'name' => 'John Doe',
+ 'email' => 'john@example.com',
+ 'url' => 'http://example.com'
);
echo form_hidden($data);
@@ -109,35 +117,32 @@ Or you can submit an associative array to create multiple fields
<input type="hidden" name="url" value="http://example.com" />
*/
-Or pass an associative array to the value field.
-
-::
+You can also pass an associative array to the value field::
$data = array(
- 'name'  => 'John Doe',
- 'email' => 'john@example.com',
- 'url'   => 'http://example.com'
+ 'name' => 'John Doe',
+ 'email' => 'john@example.com',
+ 'url' => 'http://example.com'
);
echo form_hidden('my_array', $data);
/*
Would produce:
+
<input type="hidden" name="my_array[name]" value="John Doe" />
<input type="hidden" name="my_array[email]" value="john@example.com" />
<input type="hidden" name="my_array[url]" value="http://example.com" />
*/
-If you want to create hidden input fields with extra attributes
-
-::
+If you want to create hidden input fields with extra attributes::
$data = array(
- 'type'        => 'hidden',
- 'name'        => 'email',
- 'id'          => 'hiddenemail',
- 'value'       => 'john@example.com',
- 'class'       => 'hiddenemail'
+ 'type' => 'hidden',
+ 'name' => 'email',
+ 'id' => 'hiddenemail',
+ 'value' => 'john@example.com',
+ 'class' => 'hiddenemail'
);
echo form_input($data);
@@ -151,25 +156,28 @@ If you want to create hidden input fields with extra attributes
form_input()
============
-Lets you generate a standard text input field. You can minimally pass
-the field name and value in the first and second parameter
+.. php:function:: form_input($data = '', $value = '', $extra = '')
-::
+ :param array $data: Field attributes data
+ :param string $value: Field value
+ :param string $extra: Extra attributes to be added to the tag *as is*
+ :returns: string
+
+Lets you generate a standard text input field. You can minimally pass
+the field name and value in the first and second parameter::
echo form_input('username', 'johndoe');
Or you can pass an associative array containing any data you wish your
-form to contain
-
-::
+form to contain::
$data = array(
- 'name'        => 'username',
- 'id'          => 'username',
- 'value'       => 'johndoe',
- 'maxlength'   => '100',
- 'size'        => '50',
- 'style'       => 'width:50%'
+ 'name' => 'username',
+ 'id' => 'username',
+ 'value' => 'johndoe',
+ 'maxlength' => '100',
+ 'size' => '50',
+ 'style' => 'width:50%'
);
echo form_input($data);
@@ -181,9 +189,7 @@ form to contain
*/
If you would like your form to contain some additional data, like
-Javascript, you can pass it as a string in the third parameter
-
-::
+JavaScript, you can pass it as a string in the third parameter::
$js = 'onClick="some_function()"';
echo form_input('username', 'johndoe', $js);
@@ -191,34 +197,70 @@ Javascript, you can pass it as a string in the third parameter
form_password()
===============
-This function is identical in all respects to the `form_input()` function above except that it uses the "password" input type.
+.. php:function:: form_password($data = '', $value = '', $extra = '')
+
+ :param array $data: Field attributes data
+ :param string $value: Field value
+ :param string $extra: Extra attributes to be added to the tag *as is*
+ :returns: string
+
+This function is identical in all respects to the :php:func:`form_input()`
+function above except that it uses the "password" input type.
form_upload()
=============
-This function is identical in all respects to the `form_input()` function above except that it uses the "file" input type, allowing it to be used to upload files.
+.. php:function:: form_upload($data = '', $value = '', $extra = '')
+
+ :param array $data: Field attributes data
+ :param string $value: Field value
+ :param string $extra: Extra attributes to be added to the tag *as is*
+ :returns: string
+
+This function is identical in all respects to the :php:func:`form_input()`
+function above except that it uses the "file" input type, allowing it to
+be used to upload files.
form_textarea()
===============
-This function is identical in all respects to the `form_input()` function above except that it generates a "textarea" type. Note: Instead of the "maxlength" and "size" attributes in the above example, you will instead specify "rows" and "cols".
+.. php:function:: form_textarea($data = '', $value = '', $extra = '')
+
+ :param array $data: Field attributes data
+ :param string $value: Field value
+ :param string $extra: Extra attributes to be added to the tag *as is*
+ :returns: string
+
+This function is identical in all respects to the :php:func:`form_input()`
+function above except that it generates a "textarea" type.
+
+.. note: Instead of the *maxlength* and *size* attributes in the above example,
+ you will instead specify *rows* and *cols*.
form_dropdown()
===============
+.. php:function:: form_dropdown($name = '', $options = array(), $selected = array(), $extra = '')
+
+ :param string $name: Field name
+ :param array $options: An associative array of options to be listed
+ :param array $selected: List of fields to mark with the *selected* attribute
+ :param string $extra: Extra attributes to be added to the tag *as is*
+ :returns: string
+
Lets you create a standard drop-down field. The first parameter will
contain the name of the field, the second parameter will contain an
associative array of options, and the third parameter will contain the
value you wish to be selected. You can also pass an array of multiple
items through the third parameter, and CodeIgniter will create a
-multiple select for you. Example
+multiple select for you.
-::
+Example::
$options = array(
- 'small'  => 'Small Shirt',
- 'med'    => 'Medium Shirt',
- 'large'   => 'Large Shirt',
+ 'small' => 'Small Shirt',
+ 'med' => 'Medium Shirt',
+ 'large' => 'Large Shirt',
'xlarge' => 'Extra Large Shirt',
);
@@ -251,33 +293,47 @@ multiple select for you. Example
If you would like the opening <select> to contain additional data, like
an id attribute or JavaScript, you can pass it as a string in the fourth
-parameter
-
-::
+parameter::
$js = 'id="shirts" onChange="some_function();"';
echo form_dropdown('shirts', $options, 'large', $js);
-If the array passed as $options is a multidimensional array,
-`form_dropdown()` will produce an <optgroup> with the array key as the
+If the array passed as ``$options`` is a multidimensional array, then
+``form_dropdown()`` will produce an <optgroup> with the array key as the
label.
form_multiselect()
==================
+.. php:function:: form_multiselect($name = '', $options = array(), $selected = array(), $extra = '')
+
+ :param string $name: Field name
+ :param array $options: An associative array of options to be listed
+ :param array $selected: List of fields to mark with the *selected* attribute
+ :param string $extra: Extra attributes to be added to the tag *as is*
+ :returns: string
+
Lets you create a standard multiselect field. The first parameter will
contain the name of the field, the second parameter will contain an
associative array of options, and the third parameter will contain the
-value or values you wish to be selected. The parameter usage is
-identical to using form_dropdown() above, except of course that the
-name of the field will need to use POST array syntax, e.g. foo[].
+value or values you wish to be selected.
+
+The parameter usage is identical to using :php:func:`form_dropdown()` above,
+except of course that the name of the field will need to use POST array
+syntax, e.g. foo[].
form_fieldset()
-================
+===============
+
+.. php:function:: form_fieldset($legend_text = '', $attributes = array())
+
+ :param string $legend_text: Text to put in the <legend> tag
+ :param array $attributes: Attributes to be set on the <fieldset> tag
+ :returns: string
Lets you generate fieldset/legend fields.
-::
+Example::
echo form_fieldset('Address Information');
echo "<p>fieldset content here</p>\n";
@@ -285,6 +341,7 @@ Lets you generate fieldset/legend fields.
/*
Produces:
+
<fieldset>
<legend>Address Information</legend>
<p>form content here</p>
@@ -292,13 +349,11 @@ Lets you generate fieldset/legend fields.
*/
Similar to other functions, you can submit an associative array in the
-second parameter if you prefer to set additional attributes.
-
-::
+second parameter if you prefer to set additional attributes::
$attributes = array(
- 'id' => 'address_info',
- 'class' => 'address_info'
+ 'id' => 'address_info',
+ 'class' => 'address_info'
);
echo form_fieldset('Address Information', $attributes);
@@ -317,22 +372,33 @@ second parameter if you prefer to set additional attributes.
form_fieldset_close()
=====================
+.. php:function:: form_fieldset_close($extra = '')
+
+ :param string $extra: Anything to append after the closing tag, *as is*
+ :returns: string
+
Produces a closing </fieldset> tag. The only advantage to using this
function is it permits you to pass data to it which will be added below
the tag. For example
::
- $string = "</div></div>";
+ $string = '</div></div>';
echo form_fieldset_close($string);
// Would produce: </fieldset></div></div>
form_checkbox()
===============
-Lets you generate a checkbox field. Simple example
+.. php:function:: form_checkbox($data = '', $value = '', $checked = FALSE, $extra = '')
-::
+ :param array $data: Field attributes data
+ :param string $value: Field value
+ :param bool $checked: Whether to mark the checkbox as being *checked*
+ :param string $extra: Extra attributes to be added to the tag *as is*
+ :returns: string
+
+Lets you generate a checkbox field. Simple example::
echo form_checkbox('newsletter', 'accept', TRUE);
// Would produce: <input type="checkbox" name="newsletter" value="accept" checked="checked" />
@@ -346,21 +412,19 @@ array of attributes to the function
::
$data = array(
- 'name'        => 'newsletter',
- 'id'          => 'newsletter',
- 'value'       => 'accept',
- 'checked'     => TRUE,
- 'style'       => 'margin:10px',
+ 'name' => 'newsletter',
+ 'id'      => 'newsletter',
+ 'value'   => 'accept',
+ 'checked' => TRUE,
+ 'style'   => 'margin:10px'
);
echo form_checkbox($data);
// Would produce: <input type="checkbox" name="newsletter" id="newsletter" value="accept" checked="checked" style="margin:10px" />
-As with other functions, if you would like the tag to contain additional
-data, like JavaScript, you can pass it as a string in the fourth
-parameter
-
-::
+Also as with other functions, if you would like the tag to contain
+additional data like JavaScript, you can pass it as a string in the
+fourth parameter::
$js = 'onClick="some_function()"';
echo form_checkbox('newsletter', 'accept', TRUE, $js)
@@ -368,29 +432,28 @@ parameter
form_radio()
============
-This function is identical in all respects to the `form_checkbox()`
-function above except that it uses the "radio" input type.
-
-form_submit()
-=============
+.. php:function:: form_radio($data = '', $value = '', $checked = FALSE, $extra = '')
-Lets you generate a standard submit button. Simple example
+ :param array $data: Field attributes data
+ :param string $value: Field value
+ :param bool $checked: Whether to mark the radio button as being *checked*
+ :param string $extra: Extra attributes to be added to the tag *as is*
+ :returns: string
-::
-
- echo form_submit('mysubmit', 'Submit Post!');
- // Would produce: <input type="submit" name="mysubmit" value="Submit Post!" />
-
-Similar to other functions, you can submit an associative array in the
-first parameter if you prefer to set your own attributes. The third
-parameter lets you add extra data to your form, like JavaScript.
+This function is identical in all respects to the :php:func:`form_checkbox()`
+function above except that it uses the "radio" input type.
form_label()
============
-Lets you generate a <label>. Simple example
+.. php:function:: form_label($label_text = '', $id = '', $attributes = array())
-::
+ :param string $label_text: Text to put in the <label> tag
+ :param string $id: ID of the form element that we're making a label for
+ :param string $attributes: HTML attributes
+ :returns: string
+
+Lets you generate a <label>. Simple example::
echo form_label('What is your Name', 'username');
// Would produce: <label for="username">What is your Name</label>
@@ -398,7 +461,7 @@ Lets you generate a <label>. Simple example
Similar to other functions, you can submit an associative array in the
third parameter if you prefer to set additional attributes.
-::
+Example::
$attributes = array(
'class' => 'mycustomclass',
@@ -408,87 +471,156 @@ third parameter if you prefer to set additional attributes.
echo form_label('What is your Name', 'username', $attributes);
// Would produce: <label for="username" class="mycustomclass" style="color: #000;">What is your Name</label>
+form_submit()
+=============
+
+.. php:function:: form_submit($data = '', $value = '', $extra = '')
+
+ :param string $data: Button name
+ :param string $value: Button value
+ :param string $extra: Extra attributes to be added to the tag *as is*
+ :returns: string
+
+Lets you generate a standard submit button. Simple example::
+
+ echo form_submit('mysubmit', 'Submit Post!');
+ // Would produce: <input type="submit" name="mysubmit" value="Submit Post!" />
+
+Similar to other functions, you can submit an associative array in the
+first parameter if you prefer to set your own attributes. The third
+parameter lets you add extra data to your form, like JavaScript.
form_reset()
============
+.. php:function:: form_reset($data = '', $value = '', $extra = '')
+
+ :param string $data: Button name
+ :param string $value: Button value
+ :param string $extra: Extra attributes to be added to the tag *as is*
+ :returns: string
+
Lets you generate a standard reset button. Use is identical to
-`form_submit()`.
+:php:func:`form_submit()`.
form_button()
=============
-Lets you generate a standard button element. You can minimally pass the
-button name and content in the first and second parameter
+.. php:function:: form_button($data = '', $content = '', $extra = '')
-::
+ :param string $data: Button name
+ :param string $content: Button label
+ :param string $extra: Extra attributes to be added to the tag *as is*
+ :returns: string
- echo form_button('name','content');
- // Would produce <button name="name" type="button">Content</button>
+Lets you generate a standard button element. You can minimally pass the
+button name and content in the first and second parameter::
-Or you can pass an associative array containing any data you wish your
-form to contain:
+ echo form_button('name','content');
+ // Would produce: <button name="name" type="button">Content</button>
-::
+Or you can pass an associative array containing any data you wish your
+form to contain::
$data = array(
- 'name' => 'button',
- 'id' => 'button',
- 'value' => 'true',
- 'type' => 'reset',
- 'content' => 'Reset'
+ 'name' => 'button',
+ 'id' => 'button',
+ 'value' => 'true',
+ 'type' => 'reset',
+ 'content' => 'Reset'
);
echo form_button($data);
// Would produce: <button name="button" id="button" value="true" type="reset">Reset</button>
If you would like your form to contain some additional data, like
-JavaScript, you can pass it as a string in the third parameter:
-
-::
+JavaScript, you can pass it as a string in the third parameter::
- $js = 'onClick="some_function()"';
+ $js = 'onClick="some_function()"';
echo form_button('mybutton', 'Click Me', $js);
form_close()
============
+.. php:function:: form_close($extra = '')
+
+ :param string $extra: Anything to append after the closing tag, *as is*
+ :returns: string
+
Produces a closing </form> tag. The only advantage to using this
function is it permits you to pass data to it which will be added below
-the tag. For example
+the tag. For example::
-::
-
- $string = "</div></div>";
+ $string = '</div></div>';
echo form_close($string);
// Would produce: </form> </div></div>
+form_prep()
+===========
+
+.. php:function:: form_prep($str = '', $is_textarea = FALSE)
+
+ :param string $str: Value to escape
+ :param bool $is_textarea: Whether we're preparing for <textarea> or a regular input tag
+ :returns: string
+
+Allows you to safely use HTML and characters such as quotes within form
+elements without breaking out of the form.
+
+Consider this example::
+
+ $string = 'Here is a string containing "quoted" text.';
+ <input type="text" name="myform" value="$string" />
+
+Since the above string contains a set of quotes it will cause the form
+to break. The ``form_prep()`` function converts HTML so that it can be used
+safely::
+
+ <input type="text" name="myform" value="<?php echo form_prep($string); ?>" />
+
+.. note:: If you use any of the form helper functions listed in this page the form
+ values will be prepped automatically, so there is no need to call this
+ function. Use it only if you are creating your own form elements.
+
set_value()
===========
+.. php:function:: set_value($field = '', $default = '', $is_textarea = FALSE)
+
+ :param string $field: Field name
+ :param string $default: Default value
+ :param bool $is_textarea: Whether we're setting <textarea> content
+ :returns: string
+
Permits you to set the value of an input form or textarea. You must
supply the field name via the first parameter of the function. The
second (optional) parameter allows you to set a default value for the
-form. Example
+form.
-::
+Example::
- <input type="text" name="quantity" value="<?php echo set_value('quantity', '0'); ?>" size="50" />
+ <input type="text" name="quantity" value="<?=set_value('quantity', '0');?>" size="50" />
The above form will show "0" when loaded for the first time.
set_select()
============
+.. php:function:: set_select($field = '', $value = '', $default = FALSE)
+
+ :param string $field: Field name
+ :param string $value: Value to check for
+ :param string $default: Whether the value is also a default one
+ :returns: string
+
If you use a <select> menu, this function permits you to display the
-menu item that was selected. The first parameter must contain the name
-of the select menu, the second parameter must contain the value of each
-item, and the third (optional) parameter lets you set an item as the
-default (use boolean TRUE/FALSE).
+menu item that was selected.
-Example
+The first parameter must contain the name of the select menu, the second
+parameter must contain the value of each item, and the third (optional)
+parameter lets you set an item as the default (use boolean TRUE/FALSE).
-::
+Example::
<select name="myselect">
<option value="one" <?php echo set_select('myselect', 'one', TRUE); ?> >One</option>
@@ -499,12 +631,20 @@ Example
set_checkbox()
==============
-Permits you to display a checkbox in the state it was submitted. The
-first parameter must contain the name of the checkbox, the second
+.. php:function:: set_checkbox($field = '', $value = '', $default = FALSE)
+
+ :param string $field: Field name
+ :param string $value: Value to check for
+ :param string $default: Whether the value is also a default one
+ :returns: string
+
+Permits you to display a checkbox in the state it was submitted.
+
+The first parameter must contain the name of the checkbox, the second
parameter must contain its value, and the third (optional) parameter
-lets you set an item as the default (use boolean TRUE/FALSE). Example
+lets you set an item as the default (use boolean TRUE/FALSE).
-::
+Example::
<input type="checkbox" name="mycheck" value="1" <?php echo set_checkbox('mycheck', '1'); ?> />
<input type="checkbox" name="mycheck" value="2" <?php echo set_checkbox('mycheck', '2'); ?> />
@@ -512,37 +652,71 @@ lets you set an item as the default (use boolean TRUE/FALSE). Example
set_radio()
===========
+.. php:function:: set_radio($field = '', $value = '', $default = FALSE)
+
+ :param string $field: Field name
+ :param string $value: Value to check for
+ :param string $default: Whether the value is also a default one
+ :returns: string
+
Permits you to display radio buttons in the state they were submitted.
-This function is identical to the **set_checkbox()** function above.
+This function is identical to the :php:func:`set_checkbox()` function above.
-::
+Example::
<input type="radio" name="myradio" value="1" <?php echo set_radio('myradio', '1', TRUE); ?> />
<input type="radio" name="myradio" value="2" <?php echo set_radio('myradio', '2'); ?> />
-.. note:: If you are using the Form Validation class, you must always specify a rule for your field,
- even if empty, in order for the set_*() functions to work. This is because if a Form Validation object
- is defined, the control for set_*() is handed over to a method of the class instead of the generic helper
- function.
+.. note:: If you are using the Form Validation class, you must always specify
+ a rule for your field, even if empty, in order for the ``set_*()``
+ functions to work. This is because if a Form Validation object is
+ defined, the control for ``set_*()`` is handed over to a method of the
+ class instead of the generic helper function.
-Escaping field values
-=====================
+form_error()
+============
-You may need to use HTML and characters such as quotes within form
-elements. In order to do that safely, you'll need to use
-:doc:`common function <../general/common_functions>` ``html_escape()``.
+.. php:function:: form_error($field = '', $prefix = '', $suffix = '')
-Consider the following example::
+ :param string $field: Field name
+ :param string $prefix: Error opening tag
+ :param string $suffix: Error closing tag
+ :returns: string
- $string = 'Here is a string containing "quoted" text.';
- <input type="text" name="myform" value="$string" />
+Returns a validation error message from the :doc:`Form Validation Library
+<../libraries/form_validation>`, associated with the specified field name.
+You can optionally specify opening and closing tag(s) to put around the error
+message.
-Since the above string contains a set of quotes it will cause the form
-to break. The ``html_escape()`` function converts HTML so that it can be
-used safely::
+Example::
- <input type="text" name="myform" value="<?php echo html_escape($string); ?>" />
+ // Assuming that the 'username' field value was incorrect:
+ echo form_error('myfield', '<div class="error">', '</div>');
-.. note:: If you use any of the form helper functions listed in this page, the form
- values will be prepped automatically, so there is no need to call this
- function. Use it only if you are creating your own form elements. \ No newline at end of file
+ // Would produce: <div class="error">Error message associated with the "username" field.</div>
+
+validation_errors()
+===================
+
+.. php:function:: validation_errors($prefix = '', $suffix = '')
+
+ :param string $prefix: Error opening tag
+ :param string $suffix: Error closing tag
+ :returns: string
+
+Similarly to the :php:func:`form_error()` function, returns all validation
+error messages produced by the :doc:`Form Validation Library
+<../libraries/form_validation>`, with optional opening and closing tags
+around each of the messages.
+
+Example::
+
+ echo validation_errors('<span class="error">', '</span>');
+
+ /*
+ Would produce, e.g.:
+
+ <span class="error">The "email" field doesn't contain a valid e-mail address!</span>
+ <span class="error">The "password" field doesn't match the "repeat_password" field!</span>
+
+ */ \ No newline at end of file
diff --git a/user_guide_src/source/helpers/html_helper.rst b/user_guide_src/source/helpers/html_helper.rst
index 17c28cd2a..df53ebd2f 100644
--- a/user_guide_src/source/helpers/html_helper.rst
+++ b/user_guide_src/source/helpers/html_helper.rst
@@ -19,6 +19,11 @@ The following functions are available:
br()
====
+.. php:function:: br($count = 1)
+
+ :param int $count: Number of times to repeat the tag
+ :returns: string
+
Generates line break tags (<br />) based on the number you submit.
Example::
@@ -29,7 +34,14 @@ The above would produce: <br /><br /><br />
heading()
=========
-Lets you create HTML <h1> tags. The first parameter will contain the
+.. php:function:: heading($data = '', $h = '1', $attributes = '')
+
+ :param string $data: Content
+ :param string $h: Heading level
+ :param array $attributes: HTML attributes
+ :returns: string
+
+Lets you create HTML heading tags. The first parameter will contain the
data, the second the size of the heading. Example::
echo heading('Welcome!', 3);
@@ -37,9 +49,7 @@ data, the second the size of the heading. Example::
The above would produce: <h3>Welcome!</h3>
Additionally, in order to add attributes to the heading tag such as HTML
-classes, ids or inline styles, a third parameter is available.
-
-::
+classes, ids or inline styles, a third parameter is available::
echo heading('Welcome!', 3, 'class="pink"')
@@ -48,28 +58,31 @@ The above code produces: <h3 class="pink">Welcome!<<h3>
img()
=====
-Lets you create HTML <img /> tags. The first parameter contains the
-image source. Example
+.. php:function:: img($src = '', $index_page = FALSE, $attributes = '')
-::
+ :param string $src: Image source data
+ :param bool $index_page: Whether to treat $src as a routed URI string
+ :param array $attributes: HTML attributes
+ :returns: string
+
+Lets you create HTML <img /> tags. The first parameter contains the
+image source. Example::
echo img('images/picture.jpg'); // gives <img src="http://site.com/images/picture.jpg" />
There is an optional second parameter that is a TRUE/FALSE value that
-specifics if the src should have the page specified by
-$config['index_page'] added to the address it creates. Presumably, this
-would be if you were using a media controller.
-
-::
+specifics if the *src* should have the page specified by
+``$config['index_page']`` added to the address it creates.
+Presumably, this would be if you were using a media controller::
echo img('images/picture.jpg', TRUE); // gives <img src="http://site.com/index.php/images/picture.jpg" alt="" />
-Additionally, an associative array can be passed to the img() function
-for complete control over all attributes and values. If an alt attribute
+Additionally, an associative array can be passed to the ``img()`` function
+for complete control over all attributes and values. If an *alt* attribute
is not provided, CodeIgniter will generate an empty string.
-::
+Example::
$image_properties = array(           
'src' => 'images/picture.jpg',           
@@ -81,128 +94,136 @@ is not provided, CodeIgniter will generate an empty string.
'rel' => 'lightbox'
);
- img($image_properties); // <img src="http://site.com/index.php/images/picture.jpg" alt="Me, demonstrating how to eat 4 slices of pizza at one time" class="post_images" width="200" height="200" title="That was quite a night" rel="lightbox" />
+ img($image_properties);
+ // <img src="http://site.com/index.php/images/picture.jpg" alt="Me, demonstrating how to eat 4 slices of pizza at one time" class="post_images" width="200" height="200" title="That was quite a night" rel="lightbox" />
link_tag()
-===========
+==========
-Lets you create HTML <link /> tags. This is useful for stylesheet links,
-as well as other links. The parameters are href, with optional rel,
-type, title, media and index_page. index_page is a TRUE/FALSE value
-that specifics if the href should have the page specified by
-$config['index_page'] added to the address it creates.
+.. php:function:: ling_tag($href = '', $rel = 'stylesheet', $type = 'text/css', $title = '', $media = '', $index_page = FALSE)
-::
+ :param string $href: What are we linking to
+ :param string $rel: Relation type
+ :param string $type: Type of the related document
+ :param string $title: Link title
+ :param string $media: Media type
+ :param bool $index_page: Whether to treat $src as a routed URI string
+ :returns: string
- echo link_tag('css/mystyles.css'); // gives <link href="http://site.com/css/mystyles.css" rel="stylesheet" type="text/css" />
+Lets you create HTML <link /> tags. This is useful for stylesheet links,
+as well as other links. The parameters are *href*, with optional *rel*,
+*type*, *title*, *media* and *index_page*.
+
+*index_page* is a boolean value that specifies if the *href* should have
+the page specified by ``$config['index_page']`` added to the address it creates.
+Example::
-Further examples
+ echo link_tag('css/mystyles.css');
+ // gives <link href="http://site.com/css/mystyles.css" rel="stylesheet" type="text/css" />
-::
- echo link_tag('favicon.ico', 'shortcut icon', 'image/ico'); // <link href="http://site.com/favicon.ico" rel="shortcut icon" type="image/ico" />
+Further examples::
- echo link_tag('feed', 'alternate', 'application/rss+xml', 'My RSS Feed'); // <link href="http://site.com/feed" rel="alternate" type="application/rss+xml" title="My RSS Feed" />
+ echo link_tag('favicon.ico', 'shortcut icon', 'image/ico');
+ // <link href="http://site.com/favicon.ico" rel="shortcut icon" type="image/ico" />
-Additionally, an associative array can be passed to the link() function
-for complete control over all attributes and values.
+ echo link_tag('feed', 'alternate', 'application/rss+xml', 'My RSS Feed');
+ // <link href="http://site.com/feed" rel="alternate" type="application/rss+xml" title="My RSS Feed" />
-::
+Additionally, an associative array can be passed to the ``link()`` function
+for complete control over all attributes and values::
$link = array(           
- 'href' => 'css/printer.css',           
- 'rel' => 'stylesheet',           
- 'type' => 'text/css',           
- 'media' => 'print'
+ 'href' => 'css/printer.css',
+ 'rel' => 'stylesheet',
+ 'type' => 'text/css',
+ 'media' => 'print'
);
- echo link_tag($link); // <link href="http://site.com/css/printer.css" rel="stylesheet" type="text/css" media="print" />
-
+ echo link_tag($link);
+ // <link href="http://site.com/css/printer.css" rel="stylesheet" type="text/css" media="print" />
nbs()
=====
-Generates non-breaking spaces (&nbsp;) based on the number you submit.
-Example
+.. php:function:: nbs($num = 1)
-::
+ :param int $num: Number of space entities to produce
+ :returns: string
- echo nbs(3);
+Generates non-breaking spaces (&nbsp;) based on the number you submit.
+Example::
-The above would produce
+ echo nbs(3);
-::
+The above would produce::
&nbsp;&nbsp;&nbsp;
-ol() and ul()
+ul() and ol()
=============
-Permits you to generate ordered or unordered HTML lists from simple or
-multi-dimensional arrays. Example
+.. php:function:: ul($list, $attributes = '')
-::
+ :param array $list: List entries
+ :param array $attributes: HTML attributes
+ :returns: string
- $this->load->helper('html');
+Permits you to generate ordered or unordered HTML lists from simple or
+multi-dimensional arrays. Example::
- $list = array(             
- 'red',             
- 'blue',             
- 'green',             
- 'yellow'             
+ $list = array(
+ 'red',
+ 'blue',
+ 'green',
+ 'yellow'
);
- $attributes = array(                     
- 'class' => 'boldlist',                     
- 'id'    => 'mylist'                    
+ $attributes = array(
+ 'class' => 'boldlist',
+ 'id' => 'mylist'
);
echo ul($list, $attributes);
-The above code will produce this
-
-::
+The above code will produce this::
- <ul class="boldlist" id="mylist">   
- <li>red</li>   
- <li>blue</li>   
- <li>green</li>   
+ <ul class="boldlist" id="mylist">
+ <li>red</li>
+ <li>blue</li>
+ <li>green</li>
<li>yellow</li>
</ul>
-Here is a more complex example, using a multi-dimensional array
-
-::
-
- $this->load->helper('html');
+Here is a more complex example, using a multi-dimensional array::
- $attributes = array(                     
- 'class' => 'boldlist',                     
- 'id'    => 'mylist'                     
+ $attributes = array(
+ 'class' => 'boldlist',
+ 'id' => 'mylist'
);
- $list = array(             
- 'colors' => array(                                 
- 'red',                                 
- 'blue',                                 
- 'green'                             
+ $list = array(
+ 'colors' => array(
+ 'red',
+ 'blue',
+ 'green'
),
- 'shapes' => array(                                 
- 'round',                                 
- 'square',                                 
- 'circles' => array(                                             
+ 'shapes' => array(
+ 'round',
+ 'square',
+ 'circles' => array(
'ellipse',
'oval',
'sphere'
- )                             
- ),             
- 'moods' => array(                                 
- 'happy',                                 
- 'upset' => array(                                         
+ )
+ ),
+ 'moods' => array(
+ 'happy',
+ 'upset' => array(
'defeated' => array(
- 'dejected',                
+ 'dejected',
'disheartened',
'depressed'
),
@@ -215,59 +236,74 @@ Here is a more complex example, using a multi-dimensional array
echo ul($list, $attributes);
-The above code will produce this
-
-::
-
- <ul class="boldlist" id="mylist">   
- <li>colors     
- <ul>       
- <li>red</li>       
- <li>blue</li>       
- <li>green</li>     
- </ul>   
- </li>   
- <li>shapes     
- <ul>       
- <li>round</li>       
- <li>suare</li>       
- <li>circles         
- <ul>           
- <li>elipse</li>           
- <li>oval</li>           
- <li>sphere</li>         
- </ul>       
- </li>     
- </ul>   
- </li>   
- <li>moods     
- <ul>       
- <li>happy</li>       
- <li>upset         
- <ul>           
- <li>defeated             
- <ul>               
+The above code will produce this::
+
+ <ul class="boldlist" id="mylist">
+ <li>colors
+ <ul>
+ <li>red</li>
+ <li>blue</li>
+ <li>green</li>
+ </ul>
+ </li>
+ <li>shapes
+ <ul>
+ <li>round</li>
+ <li>suare</li>
+ <li>circles
+ <ul>
+ <li>elipse</li>
+ <li>oval</li>
+ <li>sphere</li>
+ </ul>
+ </li>
+ </ul>
+ </li>
+ <li>moods
+ <ul>
+ <li>happy</li>
+ <li>upset
+ <ul>
+ <li>defeated
+ <ul>
<li>dejected</li>
<li>disheartened</li>
<li>depressed</li>
</ul>
</li>
<li>annoyed</li>
- <li>cross</li>           
- <li>angry</li>         
- </ul>       
- </li>     
- </ul>   
+ <li>cross</li>
+ <li>angry</li>
+ </ul>
+ </li>
+ </ul>
</li>
</ul>
+.. php:function:: ol($list, $attributes = '')
+
+ :param array $list: List entries
+ :param array $attributes: HTML attributes
+ :returns: string
+
+Identical to :php:func:`ul()`, only it produces the <ol> tag for
+ordered lists instead of <ul>.
+
meta()
======
+.. php:function:: meta($name = '', $content = '', $type = 'name', $newline = "\n")
+
+ :param string $name: Meta name
+ :param string $content: Meta content
+ :param string $type: Meta type
+ :param string $newline: Newline character
+ :returns: string
+
Helps you generate meta tags. You can pass strings to the function, or
-simple arrays, or multidimensional ones. Examples
+simple arrays, or multidimensional ones.
-::
+Examples::
echo meta('description', 'My Great site');
// Generates: <meta name="description" content="My Great Site" />
@@ -279,7 +315,7 @@ simple arrays, or multidimensional ones. Examples
echo meta(array('name' => 'robots', 'content' => 'no-cache'));
// Generates: <meta name="robots" content="no-cache" />
- $meta = array(         
+ $meta = array(
array(
'name' => 'robots',
'content' => 'no-cache'
@@ -291,7 +327,7 @@ simple arrays, or multidimensional ones. Examples
array(
'name' => 'keywords',
'content' => 'love, passion, intrigue, deception'
- ),         
+ ),
array(
'name' => 'robots',
'content' => 'no-cache'
@@ -313,10 +349,14 @@ simple arrays, or multidimensional ones. Examples
doctype()
=========
+.. php:function:: doctype($type = 'xhtml1-strict')
+
+ :param string $type: Doctype name
+
Helps you generate document type declarations, or DTD's. XHTML 1.0
Strict is used by default, but many doctypes are available.
-::
+Example::
echo doctype(); // <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
diff --git a/user_guide_src/source/helpers/inflector_helper.rst b/user_guide_src/source/helpers/inflector_helper.rst
index cc46a1851..1f54b76c0 100644
--- a/user_guide_src/source/helpers/inflector_helper.rst
+++ b/user_guide_src/source/helpers/inflector_helper.rst
@@ -10,9 +10,7 @@ words to plural, singular, camel case, etc.
Loading this Helper
===================
-This helper is loaded using the following code
-
-::
+This helper is loaded using the following code::
$this->load->helper('inflector');
@@ -21,65 +19,81 @@ The following functions are available:
singular()
==========
-Changes a plural word to singular. Example
+.. php:function:: singular($str)
+
+ :param string $str: Input string
+ :returns: string
-::
+Changes a plural word to singular. Example::
- $word = "dogs";
- echo singular($word); // Returns "dog"
+ echo singular('dogs'); // Prints 'dog'
plural()
========
-Changes a singular word to plural. Example
-
-::
-
- $word = "dog";
- echo plural($word); // Returns "dogs"
+.. php:function:: plural($str)
-To force a word to end with "es" use a second "true" argument.
+ :param string $str: Input string
+ :returns: string
-::
+Changes a singular word to plural. Example::
- $word = "pass";
- echo plural($word, TRUE); // Returns "passes"
+ echo plural('dog'); // Prints 'dogs'
camelize()
==========
-Changes a string of words separated by spaces or underscores to camel
-case. Example
+.. php:function:: camelize($str)
+
+ :param string $str: Input string
+ :returns: string
-::
+Changes a string of words separated by spaces or underscores to camel
+case. Example::
- $word = "my_dog_spot";
- echo camelize($word); // Returns "myDogSpot"
+ echo camelize('my_dog_spot'); // Prints 'myDogSpot'
underscore()
============
-Takes multiple words separated by spaces and underscores them. Example
+.. php:function:: camelize($str)
-::
+ :param string $str: Input string
+ :returns: string
- $word = "my dog spot";
- echo underscore($word); // Returns "my_dog_spot"
+Takes multiple words separated by spaces and underscores them.
+Example::
+
+ echo underscore('my dog spot'); // Prints 'my_dog_spot'
humanize()
==========
+.. php:function:: camelize($str)
+
+ :param string $str: Input string
+ :param string $separator: Input separator
+ :returns: string
+
Takes multiple words separated by underscores and adds spaces between
-them. Each word is capitalized. Example
+them. Each word is capitalized.
+
+Example::
+
+ echo humanize('my_dog_spot'); // Prints 'My Dog Spot'
+
+To use dashes instead of underscores::
+
+ echo humanize('my-dog-spot', '-'); // Prints 'My Dog Spot'
-::
+is_countable()
+==============
- $word = "my_dog_spot";
- echo humanize($word); // Returns "My Dog Spot"
+.. php:function:: is_countable($word)
-To use dashes instead of underscores
+ :param string $word: Input string
+ :returns: bool
-::
+Checks if the given word has a plural version. Example::
- $word = "my-dog-spot";
- echo humanize($word, '-'); // Returns "My Dog Spot" \ No newline at end of file
+ is_countable('equipment'); // Returns FALSE \ No newline at end of file
diff --git a/user_guide_src/source/helpers/language_helper.rst b/user_guide_src/source/helpers/language_helper.rst
index b7b23d149..8b039374d 100644
--- a/user_guide_src/source/helpers/language_helper.rst
+++ b/user_guide_src/source/helpers/language_helper.rst
@@ -10,24 +10,27 @@ language files.
Loading this Helper
===================
-This helper is loaded using the following code
-
-::
+This helper is loaded using the following code::
$this->load->helper('language');
The following functions are available:
-lang('language line', 'element id')
-===================================
+lang()
+======
+
+.. php:function:: lang($line, $id = '')
+
+ :param string $line: Language line key
+ :param string $id: ID of the element we're creating a label for
+ :returns: string
This function returns a line of text from a loaded language file with
-simplified syntax that may be more desirable for view files than calling
-`$this->lang->line()`. The optional second parameter will also output a
-form label for you. Example
+simplified syntax that may be more desirable for view files than
+``CI_Lang::line()``.
+The optional second parameter will also output a form label for you.
-::
+Example::
echo lang('language_key', 'form_item_id');
- // becomes <label for="form_item_id">language_key</label>
-
+ // becomes <label for="form_item_id">language_key</label> \ No newline at end of file
diff --git a/user_guide_src/source/helpers/number_helper.rst b/user_guide_src/source/helpers/number_helper.rst
index af6cdad57..8e0ebda5e 100644
--- a/user_guide_src/source/helpers/number_helper.rst
+++ b/user_guide_src/source/helpers/number_helper.rst
@@ -10,9 +10,7 @@ numeric data.
Loading this Helper
===================
-This helper is loaded using the following code
-
-::
+This helper is loaded using the following code::
$this->load->helper('number');
@@ -21,25 +19,27 @@ The following functions are available:
byte_format()
=============
-Formats a numbers as bytes, based on size, and adds the appropriate
-suffix. Examples
+.. php:function:: byte_format($num, $precision = 1)
+
+ :param mixed $num: Number of bytes
+ :param int $precision: Floating point precision
+ :returns: string
-::
+Formats numbers as bytes, based on size, and adds the appropriate
+suffix. Examples::
- echo byte_format(456); // Returns 456 Bytes
- echo byte_format(4567); // Returns 4.5 KB
- echo byte_format(45678); // Returns 44.6 KB
- echo byte_format(456789); // Returns 447.8 KB
- echo byte_format(3456789); // Returns 3.3 MB
- echo byte_format(12345678912345); // Returns 1.8 GB
+ echo byte_format(456); // Returns 456 Bytes
+ echo byte_format(4567); // Returns 4.5 KB
+ echo byte_format(45678); // Returns 44.6 KB
+ echo byte_format(456789); // Returns 447.8 KB
+ echo byte_format(3456789); // Returns 3.3 MB
+ echo byte_format(12345678912345); // Returns 1.8 GB
echo byte_format(123456789123456789); // Returns 11,228.3 TB
An optional second parameter allows you to set the precision of the
-result.
-
-::
+result::
echo byte_format(45678, 2); // Returns 44.61 KB
.. note:: The text generated by this function is found in the following
- language file: language/<your_lang>/number_lang.php
+ language file: `language/<your_lang>/number_lang.php` \ No newline at end of file
diff --git a/user_guide_src/source/helpers/path_helper.rst b/user_guide_src/source/helpers/path_helper.rst
index 847f5a08b..3a271b28f 100644
--- a/user_guide_src/source/helpers/path_helper.rst
+++ b/user_guide_src/source/helpers/path_helper.rst
@@ -10,9 +10,7 @@ file paths on the server.
Loading this Helper
===================
-This helper is loaded using the following code
-
-::
+This helper is loaded using the following code::
$this->load->helper('path');
@@ -21,23 +19,28 @@ The following functions are available:
set_realpath()
==============
-Checks to see if the path exists. This function will return a server
-path without symbolic links or relative directory structures. An
-optional second argument will cause an error to be triggered if the path
-cannot be resolved.
+.. php:function:: set_realpath($path, $check_existance = FALSE)
+
+ :param string $path: Path
+ :param bool $check_existance: Whether to check if the path actually exists
+ :returns: string
+
+This function will return a server path without symbolic links or
+relative directory structures. An optional second argument will
+cause an error to be triggered if the path cannot be resolved.
-::
+Examples::
$file = '/etc/php5/apache2/php.ini';
- echo set_realpath($file); // returns "/etc/php5/apache2/php.ini"
+ echo set_realpath($file); // Prints '/etc/php5/apache2/php.ini'
$non_existent_file = '/path/to/non-exist-file.txt';
- echo set_realpath($non_existent_file, TRUE); // shows an error, as the path cannot be resolved
- echo set_realpath($non_existent_file, FALSE); // returns "/path/to/non-exist-file.txt"
+ echo set_realpath($non_existent_file, TRUE); // Shows an error, as the path cannot be resolved
+ echo set_realpath($non_existent_file, FALSE); // Prints '/path/to/non-exist-file.txt'
$directory = '/etc/php5';
- echo set_realpath($directory); // returns "/etc/php5/"
+ echo set_realpath($directory); // Prints '/etc/php5/'
$non_existent_directory = '/path/to/nowhere';
- echo set_realpath($non_existent_directory, TRUE); // shows an error, as the path cannot be resolved
- echo set_realpath($non_existent_directory, FALSE); // returns "/path/to/nowhere"
+ echo set_realpath($non_existent_directory, TRUE); // Shows an error, as the path cannot be resolved
+ echo set_realpath($non_existent_directory, FALSE); // Prints '/path/to/nowhere' \ No newline at end of file
diff --git a/user_guide_src/source/helpers/security_helper.rst b/user_guide_src/source/helpers/security_helper.rst
index ec0be28b3..21bf53490 100644
--- a/user_guide_src/source/helpers/security_helper.rst
+++ b/user_guide_src/source/helpers/security_helper.rst
@@ -9,9 +9,7 @@ The Security Helper file contains security related functions.
Loading this Helper
===================
-This helper is loaded using the following code
-
-::
+This helper is loaded using the following code::
$this->load->helper('security');
@@ -20,25 +18,47 @@ The following functions are available:
xss_clean()
===========
-Provides Cross Site Script Hack filtering. This function is an alias to
-the one in the :doc:`Input class <../libraries/input>`. More info can
-be found there.
+.. php:function:: xss_clean($str, $is_image = FALSE)
+
+ :param string $str: Input data
+ :param bool $is_image: Whether we're dealing with an image
+ :returns: string
+
+Provides Cross Site Script Hack filtering.
+
+This function is an alias for ``CI_Input::xss_clean()``. For more info,
+please see the :doc:`Input Library <../libraries/input>` documentation.
sanitize_filename()
===================
-Provides protection against directory traversal. This function is an
-alias to the one in the :doc:`Security class <../libraries/security>`.
-More info can be found there.
+.. php:function:: sanitize_filename($filename)
+
+ :param string $filename: Filename
+ :returns: string
+
+Provides protection against directory traversal.
+
+This function is an alias for ``CI_Security::sanitize_filename()``.
+For more info, please see the :doc:`Security Library <../libraries/security>`
+documentation.
do_hash()
=========
+.. php:function:: do_hash($str, $type = 'sha1')
+
+ :param string $str: Input
+ :param string $type: Algorithm
+ :returns: string
+
Permits you to create one way hashes suitable for encrypting
-passwords. Will create SHA1 by default. See `hash_algos() <http://php.net/function.hash_algos>`_
+passwords. Will use SHA1 by default.
+
+See `hash_algos() <http://php.net/function.hash_algos>`_
for a full list of supported algorithms.
-::
+Examples::
$str = do_hash($str); // SHA1
$str = do_hash($str, 'md5'); // MD5
@@ -51,20 +71,34 @@ for a full list of supported algorithms.
strip_image_tags()
==================
-This is a security function that will strip image tags from a string. It
-leaves the image URL as plain text.
+.. php:function:: strip_image_tags($str)
+
+ :param string $str: Input
+ :returns: string
+
+This is a security function that will strip image tags from a string.
+It leaves the image URL as plain text.
-::
+Example::
$string = strip_image_tags($string);
+This function is an alias for ``CI_Security::strip_image_tags()``. For
+more info, please see the :doc:`Security Library <../libraries/security>`
+documentation.
+
encode_php_tags()
=================
-This is a security function that converts PHP tags to entities. Note: If
-you use the XSS filtering function it does this automatically.
+.. php:function:: encode_php_tags($str)
+
+ :param string $str: Input
+ :returns: string
+
+This is a security function that converts PHP tags to entities.
-::
+.. note: :php:func:`xss_clean()` does this automatically, if you use it.
- $string = encode_php_tags($string);
+Example::
+ $string = encode_php_tags($string); \ No newline at end of file
diff --git a/user_guide_src/source/helpers/smiley_helper.rst b/user_guide_src/source/helpers/smiley_helper.rst
index 941ba11e3..13841e8bd 100644
--- a/user_guide_src/source/helpers/smiley_helper.rst
+++ b/user_guide_src/source/helpers/smiley_helper.rst
@@ -10,9 +10,7 @@ The Smiley Helper file contains functions that let you manage smileys
Loading this Helper
===================
-This helper is loaded using the following code
-
-::
+This helper is loaded using the following code::
$this->load->helper('smiley');
@@ -36,10 +34,11 @@ smileys next to a form field. This example requires that you first
download and install the smiley images, then create a controller and the
View as described.
-.. important:: Before you begin, please `download the smiley images <http://codeigniter.com/download_files/smileys.zip>`_
- and put them in a publicly accessible place on your server. This helper
- also assumes you have the smiley replacement array located at
- `application/config/smileys.php`
+.. important:: Before you begin, please `download the smiley images
+ <http://codeigniter.com/download_files/smileys.zip>`_
+ and put them in a publicly accessible place on your server.
+ This helper also assumes you have the smiley replacement array
+ located at `application/config/smileys.php`
The Controller
--------------
@@ -47,18 +46,17 @@ The Controller
In your `application/controllers/` folder, create a file called
smileys.php and place the code below in it.
-.. important:: Change the URL in the `get_clickable_smileys()`
+.. important:: Change the URL in the :php:func:`get_clickable_smileys()`
function below so that it points to your smiley folder.
-You'll notice that in addition to the smiley helper we are using the :doc:`Table Class <../libraries/table>`.
-
-::
+You'll notice that in addition to the smiley helper, we are also using
+the :doc:`Table Class <../libraries/table>`::
<?php
class Smileys extends CI_Controller {
- function index()
+ public function index()
{
$this->load->helper('smiley');
$this->load->library('table');
@@ -69,12 +67,11 @@ You'll notice that in addition to the smiley helper we are using the :doc:`Table
$data['smiley_table'] = $this->table->generate($col_array);
$this->load->view('smiley_view', $data);
}
+
}
In your `application/views/` folder, create a file called `smiley_view.php`
-and place this code in it:
-
-::
+and place this code in it::
<html>
<head>
@@ -102,59 +99,66 @@ links a generic name that will be tied to a specific id in your view.
$image_array = get_smiley_links("http://example.com/images/smileys/", "comment_textarea_alias");
-To map the alias to the field id, pass them both into the `smiley_js`
-function
-
-::
+To map the alias to the field id, pass them both into the
+:php:func:`smiley_js()` function::
$image_array = smiley_js("comment_textarea_alias", "comments");
-******************
-Function Reference
-******************
-
get_clickable_smileys()
=======================
+.. php:function:: get_clickable_smileys($image_url, $alias = '', $smileys = NULL)
+
+ :param string $image_url: URL path to the smileys directory
+ :param string $alias: Field alias
+ :returns: array
+
Returns an array containing your smiley images wrapped in a clickable
link. You must supply the URL to your smiley folder and a field id or
field alias.
-::
+Example::
$image_array = get_smiley_links("http://example.com/images/smileys/", "comment");
-Note: Usage of this function without the second parameter, in
-combination with `js_insert_smiley` has been deprecated.
-
smiley_js()
===========
+.. php:function:: smiley_js($alias = '', $field_id = '', $inline = TRUE)
+
+ :param string $alias: Field alias
+ :param string $field_id: Field ID
+ :param bool $inline: Whether we're inserting an inline smiley
+
Generates the JavaScript that allows the images to be clicked and
inserted into a form field. If you supplied an alias instead of an id
when generating your smiley links, you need to pass the alias and
corresponding form id into the function. This function is designed to be
placed into the <head> area of your web page.
-::
+Example::
<?php echo smiley_js(); ?>
-Note: This function replaces `js_insert_smiley`, which has been
-deprecated.
-
parse_smileys()
===============
+.. php:function:: parse_smileys($str = '', $image_url = '', $smileys = NULL)
+
+ :param string $str: Text containing smiley codes
+ :param string $image_url: URL path to the smileys directory
+ :param array $smileys: An array of smileys
+ :returns: string
+
Takes a string of text as input and replaces any contained plain text
smileys into the image equivalent. The first parameter must contain your
string, the second must contain the URL to your smiley folder
-::
+Example::
$str = 'Here are some simileys: :-) ;-)';
$str = parse_smileys($str, "http://example.com/images/smileys/");
echo $str;
-.. |smile!| image:: ../images/smile.gif
+.. |smile!| image:: ../images/smile.gif \ No newline at end of file
diff --git a/user_guide_src/source/helpers/string_helper.rst b/user_guide_src/source/helpers/string_helper.rst
index 530af2f89..d0d302476 100644
--- a/user_guide_src/source/helpers/string_helper.rst
+++ b/user_guide_src/source/helpers/string_helper.rst
@@ -10,9 +10,7 @@ strings.
Loading this Helper
===================
-This helper is loaded using the following code
-
-::
+This helper is loaded using the following code::
$this->load->helper('string');
@@ -21,39 +19,48 @@ The following functions are available:
random_string()
===============
+.. php:function:: random_string($type = 'alnum', $len = 8)
+
+ :param string $type: Randomization type
+ :param int $len: Output string length
+ :returns: string
+
Generates a random string based on the type and length you specify.
Useful for creating passwords or generating random hashes.
The first parameter specifies the type of string, the second parameter
specifies the length. The following choices are available:
-alpha, alunum, numeric, nozero, unique, md5, encrypt and sha1
-
- **alpha**: A string with lower and uppercase letters only.
- **alnum**: Alpha-numeric string with lower and uppercase characters.
+- **basic**: A random number based on ``mt_rand()``.
- **numeric**: Numeric string.
- **nozero**: Numeric string with no zeros.
-- **unique**: Encrypted with MD5 and uniqid(). Note: The length
- parameter is not available for this type. Returns a fixed length 32
- character string.
-- **sha1**: An encrypted random number based on ``sha1()``.
-
-Usage example
+- **md5**: An encrypted random number based on ``md5()`` (fixed length of 32).
+- **sha1**: An encrypted random number based on ``sha1()`` (fixed length of 40).
-::
+Usage example::
echo random_string('alnum', 16);
+.. note:: Usage of the *unique* and *encrypt* types is DEPRECATED. They
+ are just aliases for *md5* and *sha1* respectively.
+
increment_string()
==================
+.. php:function:: increment_string($str, $separator = '_', $first = 1)
+
+ :param string $str: Input string
+ :param string $separator: Separator to append a duplicate number with
+ :param int $first: Starting number
+ :returns: string
+
Increments a string by appending a number to it or increasing the
number. Useful for creating "copies" or a file or duplicating database
content which has unique titles or slugs.
-Usage example
-
-::
+Usage example::
echo increment_string('file', '_'); // "file_1"
echo increment_string('file', '-', 2); // "file-2"
@@ -62,10 +69,13 @@ Usage example
alternator()
============
-Allows two or more items to be alternated between, when cycling through
-a loop. Example
+.. php:function:: alternator($args)
-::
+ :param mixed $args: A variable number of arguments
+ :returns: mixed
+
+Allows two or more items to be alternated between, when cycling through
+a loop. Example::
for ($i = 0; $i < 10; $i++)
{     
@@ -88,11 +98,16 @@ your loop the next item will be returned.
repeater()
==========
-Generates repeating copies of the data you submit. Example
+.. php:function:: repeater($data, $num = 1)
-::
+ :param string $data: Input
+ :param int $num: Number of times to repeat
+ :returns: string
+
+Generates repeating copies of the data you submit. Example::
- $string = "\n"; echo repeater($string, 30);
+ $string = "\n";
+ echo repeater($string, 30);
The above would generate 30 newlines.
@@ -102,10 +117,15 @@ The above would generate 30 newlines.
reduce_double_slashes()
=======================
+.. php:function:: reduce_double_slashes($str)
+
+ :param string $str: Input string
+ :returns: string
+
Converts double slashes in a string to a single slash, except those
-found in http://. Example
+found in URL protocol prefixes (e.g. http://).
-::
+Example::
$string = "http://example.com//index.php";
echo reduce_double_slashes($string); // results in "http://example.com/index.php"
@@ -113,16 +133,14 @@ found in http://. Example
strip_slashes()
===============
-Removes any slashes from a string. Example
-
-::
+.. php:function:: strip_slashes($data)
- $str = "Is your name O\'reilly?";
- echo strip_slashes($str); // results in Is your name O'reilly?
+ :param array $data: Input
+ :returns: array
-You can also use an array. Example
+Removes any slashes from an array of strings.
-::
+Example::
$str = array(
'question'  => 'Is your name O\'reilly?',
@@ -131,60 +149,66 @@ You can also use an array. Example
$str = strip_slashes($str);
-The above will return the following array:
-
-::
+The above will return the following array::
array(
'question'  => "Is your name O'reilly?",
'answer' => "No, my name is O'connor."
);
+.. note:: For historical reasons, this function will also accept
+ and handle string inputs. This however makes it just an
+ alias for ``stripslashes()``.
+
trim_slashes()
==============
-Removes any leading/trailing slashes from a string. Example
+.. php:function:: trim_slashes($str)
-::
+ :param string $str: Input string
+ :returns: string
+
+Removes any leading/trailing slashes from a string. Example::
$string = "/this/that/theother/";
echo trim_slashes($string); // results in this/that/theother
+.. note:: This function is DEPRECATED. Use the native ``trim()`` instead:
+ |
+ | trim($str, '/');
reduce_multiples()
==================
+.. php:function:: reduce_multiples($str, $character = '', $trim = FALSE)
+
+ :param string $str: Text to search in
+ :param string $character: Character to reduce
+ :param bool $trim: Whether to also trim the specified character
+ :returns: string
+
Reduces multiple instances of a particular character occuring directly
after each other. Example::
$string = "Fred, Bill,, Joe, Jimmy";
$string = reduce_multiples($string,","); //results in "Fred, Bill, Joe, Jimmy"
-The function accepts the following parameters:
-
-::
-
- reduce_multiples(string: text to search in, string: character to reduce, boolean: whether to remove the character from the front and end of the string)
-
-The first parameter contains the string in which you want to reduce the
-multiplies. The second parameter contains the character you want to have
-reduced. The third parameter is FALSE by default; if set to TRUE it will
-remove occurences of the character at the beginning and the end of the
-string. Example:
-
-::
+If the third parameter is set to TRUE it will remove occurences of the
+character at the beginning and the end of the string. Example::
$string = ",Fred, Bill,, Joe, Jimmy,";
$string = reduce_multiples($string, ", ", TRUE); //results in "Fred, Bill, Joe, Jimmy"
-
quotes_to_entities()
====================
-Converts single and double quotes in a string to the corresponding HTML
-entities. Example
+.. php:function:: quotes_to_entities($str)
-::
+ :param string $str: Input string
+ :returns: string
+
+Converts single and double quotes in a string to the corresponding HTML
+entities. Example::
$string = "Joe's \"dinner\"";
$string = quotes_to_entities($string); //results in "Joe&#39;s &quot;dinner&quot;"
@@ -192,8 +216,12 @@ entities. Example
strip_quotes()
==============
+.. php:function:: strip_quotes($str)
+
+ :param string $str: Input string
+ :returns: string
+
Removes single and double quotes from a string. Example::
$string = "Joe's \"dinner\"";
- $string = strip_quotes($string); //results in "Joes dinner"
-
+ $string = strip_quotes($string); //results in "Joes dinner" \ No newline at end of file
diff --git a/user_guide_src/source/helpers/text_helper.rst b/user_guide_src/source/helpers/text_helper.rst
index 8cb2d6f96..aec36c9a7 100644
--- a/user_guide_src/source/helpers/text_helper.rst
+++ b/user_guide_src/source/helpers/text_helper.rst
@@ -10,9 +10,7 @@ text.
Loading this Helper
===================
-This helper is loaded using the following code
-
-::
+This helper is loaded using the following code::
$this->load->helper('text');
@@ -21,7 +19,14 @@ The following functions are available:
word_limiter()
==============
-Truncates a string to the number of **words** specified. Example::
+.. php:function:: word_limiter($str, $limit = 100, $end_char = '&#8230;')
+
+ :param string $str: Input string
+ :param int $limit: Limit
+ :param string $end_char: End character (usually an ellipsis)
+ :returns: string
+
+Truncates a string to the number of *words* specified. Example::
$string = "Here is a nice text string consisting of eleven words.";
$string = word_limiter($string, 4);
@@ -33,11 +38,18 @@ default it adds an ellipsis.
character_limiter()
===================
-Truncates a string to the number of **characters** specified. It
+.. php:function:: character_limiter($str, $n = 500, $end_char = '&#8230;')
+
+ :param string $str: Input string
+ :param int $n: Number of characters
+ :param string $end_char: End character (usually an ellipsis)
+ :returns: string
+
+Truncates a string to the number of *characters* specified. It
maintains the integrity of words so the character count may be slightly
-more or less then what you specify. Example
+more or less then what you specify.
-::
+Example::
$string = "Here is a nice text string consisting of eleven words.";
$string = character_limiter($string, 20);
@@ -46,55 +58,78 @@ more or less then what you specify. Example
The third parameter is an optional suffix added to the string, if
undeclared this helper uses an ellipsis.
-**Note:** If you need to truncate to an exact number of characters please see
-the :ref:`ellipsize` function below.
+.. note:: If you need to truncate to an exact number of characters please
+ see the :ref:`ellipsize()` function below.
ascii_to_entities()
===================
+.. php:function:: ascii_to_entities($str)
+
+ :param string $str: Input string
+ :returns: string
+
Converts ASCII values to character entities, including high ASCII and MS
Word characters that can cause problems when used in a web page, so that
they can be shown consistently regardless of browser settings or stored
reliably in a database. There is some dependence on your server's
supported character sets, so it may not be 100% reliable in all cases,
but for the most part it should correctly identify characters outside
-the normal range (like accented characters). Example
+the normal range (like accented characters).
-::
+Example::
$string = ascii_to_entities($string);
entities_to_ascii()
===================
-This function does the opposite of the previous one; it turns character
-entities back into ASCII.
+.. php:function::entities_to_ascii($str, $all = TRUE)
+
+ :param string $str: Input string
+ :param bool $all: Whether to convert unsafe entities as well
+ :returns: string
+
+This function does the opposite of :php:func:`ascii_to_entities()`.
+It turns character entities back into ASCII.
convert_accented_characters()
=============================
-Transliterates high ASCII characters to low ASCII equivalents, useful
+.. php:function:: convert_accented_characters($str)
+
+ :param string $str: Input string
+ :returns: string
+
+Transliterates high ASCII characters to low ASCII equivalents. Useful
when non-English characters need to be used where only standard ASCII
characters are safely used, for instance, in URLs.
-::
+Example::
$string = convert_accented_characters($string);
-This function uses a companion config file
-`application/config/foreign_chars.php` to define the to and from array
-for transliteration.
+.. note:: This function uses a companion config file
+ `application/config/foreign_chars.php` to define the to and
+ from array for transliteration.
word_censor()
=============
+.. php:function:: word_censor($str, $censored, $replacement = '')
+
+ :param string $str: Input string
+ :param array $censored: List of bad words to censor
+ :param string $replacement: What to replace bad words with
+ :returns: string
+
Enables you to censor words within a text string. The first parameter
will contain the original string. The second will contain an array of
-words which you disallow. The third (optional) parameter can contain a
-replacement value for the words. If not specified they are replaced with
-pound signs: ####. Example
+words which you disallow. The third (optional) parameter can contain
+a replacement value for the words. If not specified they are replaced
+with pound signs: ####.
-::
+Example::
$disallowed = array('darn', 'shucks', 'golly', 'phooey');
$string = word_censor($string, $disallowed, 'Beep!');
@@ -102,48 +137,76 @@ pound signs: ####. Example
highlight_code()
================
+.. php:function:: highlight_code($str)
+
+ :param string $str: Input string
+ :returns: string
+
Colorizes a string of code (PHP, HTML, etc.). Example::
$string = highlight_code($string);
-The function uses PHP's highlight_string() function, so the colors used
-are the ones specified in your php.ini file.
+The function uses PHP's ``highlight_string()`` function, so the
+colors used are the ones specified in your php.ini file.
highlight_phrase()
==================
+.. php:function:: highlight_phrase($str, $phrase, $tag_open = '<strong>', $tag_close = '</strong>')
+
+ :param string $str: Input string
+ :param string $phrase: Phrase to highlight
+ :param string $tag_open: Opening tag used for the highlight
+ :param string $tag_close: Closing tag for the highlight
+ :returns: string
+
Will highlight a phrase within a text string. The first parameter will
contain the original string, the second will contain the phrase you wish
to highlight. The third and fourth parameters will contain the
-opening/closing HTML tags you would like the phrase wrapped in. Example
+opening/closing HTML tags you would like the phrase wrapped in.
-::
+Example::
$string = "Here is a nice text string about nothing in particular.";
- $string = highlight_phrase($string, "nice text", '<span style="color:#990000">', '</span>');
+ echo highlight_phrase($string, "nice text", '<span style="color:#990000;">', '</span>');
-The above text returns:
+The above code prints::
-Here is a nice text string about nothing in particular.
+ Here is a <span style="color:#990000;">nice text</span> string about nothing in particular.
word_wrap()
===========
-Wraps text at the specified **character** count while maintaining
-complete words. Example
+.. php:function:: word_wrap($str, $charlim = 76)
+
+ :param string $str: Input string
+ :param int $charlim: Character limit
+ :returns: string
-::
+Wraps text at the specified *character* count while maintaining
+complete words.
+
+Example::
$string = "Here is a simple string of text that will help us demonstrate this function.";
echo word_wrap($string, 25);
// Would produce: Here is a simple string of text that will help us demonstrate this function
-.. _ellipsize:
+.. _ellipsize():
ellipsize()
===========
+.. php:function:: ellipsize($str, $max_length, $position = 1, $ellipsis = '&hellip;')
+
+ :param string $str: Input string
+ :param int $max_length: String length limit
+ :param mixed $position: Position to split at
+ (int or float)
+ :param string $ellipsis: What to use as the ellipsis character
+ :returns: string
+
This function will strip tags from a string, split it at a defined
maximum length, and insert an ellipsis.
@@ -156,14 +219,11 @@ string, .5 in the middle, and 0 at the left.
An optional forth parameter is the kind of ellipsis. By default,
&hellip; will be inserted.
-::
+Example::
$str = 'this_string_is_entirely_too_long_and_might_break_my_design.jpg';
echo ellipsize($str, 32, .5);
-Produces:
-
-::
-
- this_string_is_e&hellip;ak_my_design.jpg
+Produces::
+ this_string_is_e&hellip;ak_my_design.jpg \ No newline at end of file
diff --git a/user_guide_src/source/helpers/typography_helper.rst b/user_guide_src/source/helpers/typography_helper.rst
index f3202603a..3c81687ac 100644
--- a/user_guide_src/source/helpers/typography_helper.rst
+++ b/user_guide_src/source/helpers/typography_helper.rst
@@ -10,9 +10,7 @@ in semantically relevant ways.
Loading this Helper
===================
-This helper is loaded using the following code
-
-::
+This helper is loaded using the following code::
$this->load->helper('typography');
@@ -21,9 +19,18 @@ The following functions are available:
auto_typography()
=================
+.. php:function:: auto_typography($str, $reduce_linebreaks = FALSE)
+
+ :param string $str: Input string
+ :param bool $reduce_linebreaks: Whether to reduce multiple instances of double newlines to two
+ :returns: string
+
Formats text so that it is semantically and typographically correct
-HTML. Please see the :doc:`Typography Class <../libraries/typography>`
-for more info.
+HTML.
+
+This function is an alias for ``CI_Typography::auto_typography``.
+For more info, please see the :doc:`Typography Library
+<../libraries/typography>` documentation.
Usage example::
@@ -31,18 +38,34 @@ Usage example::
.. note:: Typographic formatting can be processor intensive, particularly if
you have a lot of content being formatted. If you choose to use this
- function you may want to consider `caching </general/caching>` your pages.
+ function you may want to consider `caching <../general/caching>` your
+ pages.
nl2br_except_pre()
==================
-Converts newlines to <br /> tags unless they appear within <pre> tags.
-This function is identical to the native PHP nl2br() function, except
-that it ignores <pre> tags.
+.. php:function:: nl2br_except_pre($str)
-Usage example
+ :param string $str: Input string
+ :returns: string
-::
+Converts newlines to <br /> tags unless they appear within <pre> tags.
+This function is identical to the native PHP ``nl2br()`` function,
+except that it ignores <pre> tags.
+
+Usage example::
$string = nl2br_except_pre($string);
+entity_decode()
+===============
+
+.. php:function:: entity_decode($str, $charset = NULL)
+
+ :param string $str: Input string
+ :param string $charset: Character set
+ :returns: string
+
+This function is an alias for ``CI_Security::entity_decode()``.
+Fore more info, please see the :doc:`Security Library
+<../libraries/security>` documentation. \ No newline at end of file
diff --git a/user_guide_src/source/helpers/url_helper.rst b/user_guide_src/source/helpers/url_helper.rst
index 1987dfb72..5b8fa5f44 100644
--- a/user_guide_src/source/helpers/url_helper.rst
+++ b/user_guide_src/source/helpers/url_helper.rst
@@ -9,9 +9,7 @@ The URL Helper file contains functions that assist in working with URLs.
Loading this Helper
===================
-This helper is loaded using the following code
-
-::
+This helper is loaded using the following code::
$this->load->helper('url');
@@ -20,119 +18,135 @@ The following functions are available:
site_url()
==========
+.. php:function:: site_url($uri = '')
+
+ :param string $uri: URI string
+ :returns: string
+
Returns your site URL, as specified in your config file. The index.php
-file (or whatever you have set as your site index_page in your config
+file (or whatever you have set as your site **index_page** in your config
file) will be added to the URL, as will any URI segments you pass to the
-function, and the url_suffix as set in your config file.
+function, plus the **url_suffix** as set in your config file.
You are encouraged to use this function any time you need to generate a
local URL so that your pages become more portable in the event your URL
changes.
Segments can be optionally passed to the function as a string or an
-array. Here is a string example
+array. Here is a string example::
-::
-
- echo site_url("news/local/123");
+ echo site_url('news/local/123');
The above example would return something like:
-http://example.com/index.php/news/local/123
-
-Here is an example of segments passed as an array
+*http://example.com/index.php/news/local/123*
-::
+Here is an example of segments passed as an array::
$segments = array('news', 'local', '123');
echo site_url($segments);
+This function is an alias for ``CI_Config::site_url()``. For more info,
+please see the :doc:`Config Library <../libraries/config>` documentation.
+
base_url()
===========
-Returns your site base URL, as specified in your config file. Example
+.. php:function:: base_url($uri = '')
-::
+ :param string $uri: URI string
+ :returns: string
- echo base_url();
+Returns your site base URL, as specified in your config file. Example::
-This function returns the same thing as `site_url`, without the
-index_page or url_suffix being appended.
+ echo base_url();
-Also like site_url, you can supply segments as a string or an array.
-Here is a string example
+This function returns the same thing as :php:func:`site_url()`, without
+the *index_page* or *url_suffix* being appended.
-::
+Also like :php:func:`site_url()`, you can supply segments as a string or
+an array. Here is a string example::
echo base_url("blog/post/123");
The above example would return something like:
-http://example.com/blog/post/123
-
-This is useful because unlike `site_url()`, you can supply a string to a
-file, such as an image or stylesheet. For example
+*http://example.com/blog/post/123*
-::
+This is useful because unlike :php:func:`site_url()`, you can supply a
+string to a file, such as an image or stylesheet. For example::
echo base_url("images/icons/edit.png");
This would give you something like:
-http://example.com/images/icons/edit.png
+*http://example.com/images/icons/edit.png*
+
+This function is an alias for ``CI_Config::base_url()``. For more info,
+please see the :doc:`Config Library <../libraries/config>` documentation.
current_url()
=============
+.. php:function:: current_url()
+
+ :returns: string
+
Returns the full URL (including segments) of the page being currently
viewed.
+.. note:: Calling this function is the same as doing this:
+ |
+ | site_url(uri_string());
+
uri_string()
============
-Returns the URI segments of any page that contains this function. For
-example, if your URL was this
+.. php:function:: uri_string()
-::
+ :returns: string
- http://some-site.com/blog/comments/123
+Returns the URI segments of any page that contains this function.
+For example, if your URL was this::
-The function would return
+ http://some-site.com/blog/comments/123
-::
+The function would return::
/blog/comments/123
+This function is an alias for ``CI_Config::uri_string()``. For more info,
+please see the :doc:`Config Library <../libraries/config>` documentation.
+
index_page()
============
-Returns your site "index" page, as specified in your config file.
-Example
+.. php:function:: index_page()
+
+ :returns: string
-::
+Returns your site **index_page**, as specified in your config file.
+Example::
echo index_page();
anchor()
========
-Creates a standard HTML anchor link based on your local site URL
-
-::
+.. php:function:: anchor($uri = '', $title = '', $attributes = '')
- <a href="http://example.com">Click Here</a>
+ :param string $uri: URI string
+ :param string $title: Anchor title
+ :param mixed $attributes: HTML attributes
+ :returns: string
-The tag has three optional parameters
-
-::
-
- anchor(uri segments, text, attributes)
+Creates a standard HTML anchor link based on your local site URL.
The first parameter can contain any segments you wish appended to the
-URL. As with the site_url() function above, segments can be a string or
-an array.
+URL. As with the :php:func:`site_url()` function above, segments can
+be a string or an array.
.. note:: If you are building links that are internal to your application
- do not include the base URL (http://...). This will be added automatically
- from the information specified in your config file. Include only the
- URI segments you wish appended to the URL.
+ do not include the base URL (http://...). This will be added
+ automatically from the information specified in your config file.
+ Include only the URI segments you wish appended to the URL.
The second segment is the text you would like the link to say. If you
leave it blank, the URL will be used.
@@ -141,41 +155,43 @@ The third parameter can contain a list of attributes you would like
added to the link. The attributes can be a simple string or an
associative array.
-Here are some examples
-
-::
+Here are some examples::
echo anchor('news/local/123', 'My News', 'title="News title"');
-
-Would produce: <a href="http://example.com/index.php/news/local/123"
-title="News title">My News</a>
-
-::
+ // Prints: <a href="http://example.com/index.php/news/local/123" title="News title">My News</a>
echo anchor('news/local/123', 'My News', array('title' => 'The best news!'));
+ // Prints: <a href="http://example.com/index.php/news/local/123" title="The best news!">My News</a>
-Would produce: <a href="http://example.com/index.php/news/local/123"
-title="The best news!">My News</a>
+ echo anchor('', 'Click here');
+ // Prints: <a href="http://example.com">Click Here</a>
anchor_popup()
==============
-Nearly identical to the anchor() function except that it opens the URL
-in a new window. You can specify JavaScript window attributes in the
-third parameter to control how the window is opened. If the third
-parameter is not set it will simply open a new window with your own
-browser settings. Here is an example with attributes
+.. php:function:: anchor_popup($uri = '', $title = '', $attributes = FALSE)
-::
+ :param string $uri: URI string
+ :param string $title: Anchor title
+ :param mixed $attributes: HTML attributes
+ :returns: string
+
+Nearly identical to the :php:func:``anchor()`` function except that it
+opens the URL in a new window. You can specify JavaScript window
+attributes in the third parameter to control how the window is opened.
+If the third parameter is not set it will simply open a new window with
+your own browser settings.
+
+Here is an example with attributes::
$atts = array(
- 'width' => '800',
- 'height' => '600',
+ 'width' => 800,
+ 'height' => 600,
'scrollbars' => 'yes',
'status'      => 'yes',
'resizable'   => 'yes',
- 'screenx'     => '0',
- 'screeny'     => '0',
+ 'screenx' => 0,
+ 'screeny' => 0,
'window_name' => '_blank'
);
@@ -184,13 +200,11 @@ browser settings. Here is an example with attributes
.. note:: The above attributes are the function defaults so you only need to
set the ones that are different from what you need. If you want the
function to use all of its defaults simply pass an empty array in the
- third parameter
-
-::
+ third parameter:
+ |
+ | echo anchor_popup('news/local/123', 'Click Me!', array());
- echo anchor_popup('news/local/123', 'Click Me!', array());
-
-.. note:: The 'window_name' is not really an attribute, but an argument to
+.. note:: The **window_name** is not really an attribute, but an argument to
the JavaScript `window.open() <http://www.w3schools.com/jsref/met_win_open.asp>`
method, which accepts either a window name or a window target.
@@ -200,117 +214,149 @@ browser settings. Here is an example with attributes
mailto()
========
-Creates a standard HTML email link. Usage example
+.. php:function:: mailto($email, $title = '', $attributes = '')
-::
+ :param string $email: E-mail address
+ :param string $title: Anchor title
+ :param mixed $attributes: HTML attributes
+ :returns: string
- echo mailto('me@my-site.com', 'Click Here to Contact Me');
+Creates a standard HTML e-mail link. Usage example::
-As with the anchor() tab above, you can set attributes using the third
-parameter:
+ echo mailto('me@my-site.com', 'Click Here to Contact Me');
-::
+As with the :php:func:`anchor()` tab above, you can set attributes using the
+third parameter::
- $attributes = array('title' => 'Mail me');
- echo mailto('me@my-site.com', 'Contact Me', $attributes);
+ $attributes = array('title' => 'Mail me');
+ echo mailto('me@my-site.com', 'Contact Me', $attributes);
safe_mailto()
=============
-Identical to the above function except it writes an obfuscated version
-of the mailto tag using ordinal numbers written with JavaScript to help
-prevent the email address from being harvested by spam bots.
+.. php:function:: safe_mailto($email, $title = '', $attributes = '')
+
+ :param string $email: E-mail address
+ :param string $title: Anchor title
+ :param mixed $attributes: HTML attributes
+ :returns: string
+
+Identical to the :php:func:`mailto()` function except it writes an obfuscated
+version of the *mailto* tag using ordinal numbers written with JavaScript to
+help prevent the e-mail address from being harvested by spam bots.
auto_link()
===========
-Automatically turns URLs and email addresses contained in a string into
-links. Example
+.. php:function:: auto_link($str, $type = 'both', $popup = FALSE)
+
+ :param string $str: Input string
+ :param string $type: Link type ('email', 'url' or 'both')
+ :param bool $popup: Whether to create popup links
+ :returns: string
-::
+Automatically turns URLs and e-mail addresses contained in a string into
+links. Example::
$string = auto_link($string);
-The second parameter determines whether URLs and emails are converted or
+The second parameter determines whether URLs and e-mails are converted or
just one or the other. Default behavior is both if the parameter is not
-specified. Email links are encoded as safe_mailto() as shown above.
+specified. E-mail links are encoded as :php:func:`safe_mailto()` as shown
+above.
-Converts only URLs
-
-::
+Converts only URLs::
$string = auto_link($string, 'url');
-Converts only Email addresses
-
-::
+Converts only e-mail addresses::
$string = auto_link($string, 'email');
The third parameter determines whether links are shown in a new window.
-The value can be TRUE or FALSE (boolean)
-
-::
+The value can be TRUE or FALSE (boolean)::
$string = auto_link($string, 'both', TRUE);
url_title()
===========
+.. php:function:: url_title($str, $separator = '-', $lowercase = FALSE)
+
+ :param string $str: Input string
+ :param string $separator: Word separator
+ :param string $lowercase: Whether to transform the output string to lower-case
+ :returns: string
+
Takes a string as input and creates a human-friendly URL string. This is
useful if, for example, you have a blog in which you'd like to use the
-title of your entries in the URL. Example
-
-::
+title of your entries in the URL. Example::
$title = "What's wrong with CSS?";
- $url_title = url_title($title); // Produces: Whats-wrong-with-CSS
+ $url_title = url_title($title);
+ // Produces: Whats-wrong-with-CSS
The second parameter determines the word delimiter. By default dashes
-are used. Options are: dash, or underscore
+are used. Preferred options are: **-** (dash) or **_** (underscore)
-::
+Example::
$title = "What's wrong with CSS?";
- $url_title = url_title($title, 'underscore'); // Produces: Whats_wrong_with_CSS
+ $url_title = url_title($title, 'underscore');
+ // Produces: Whats_wrong_with_CSS
+
+.. note:: Old usage of 'dash' and 'underscore' as the second parameter
+ is DEPRECATED.
The third parameter determines whether or not lowercase characters are
-forced. By default they are not. Options are boolean TRUE/FALSE
+forced. By default they are not. Options are boolean TRUE/FALSE.
-::
+Example::
$title = "What's wrong with CSS?";
- $url_title = url_title($title, 'underscore', TRUE); // Produces: whats_wrong_with_css
+ $url_title = url_title($title, 'underscore', TRUE);
+ // Produces: whats_wrong_with_css
prep_url()
----------
-This function will add http:// in the event that a scheme is missing
-from a URL. Pass the URL string to the function like this
+.. php:function:: prep_url($str = '')
+
+ :param string $str: URL string
+ :returns: string
-::
+This function will add http:// in the event that a protocol prefix
+is missing from a URL.
- $url = "example.com";
- $url = prep_url($url);
+Pass the URL string to the function like this::
+
+ $url = prep_url('example.com');
redirect()
==========
+.. php:function:: redirect($uri = '', $method = 'auto', $code = NULL)
+
+ :param string $uri: URI string
+ :param string $method: Redirect method ('auto', 'location' or 'refresh')
+ :param string $code: HTTP Response code (usually 302 or 303)
+ :returns: void
+
Does a "header redirect" to the URI specified. If you specify the full
site URL that link will be built, but for local links simply providing
the URI segments to the controller you want to direct to will create the
link. The function will build the URL based on your config file values.
The optional second parameter allows you to force a particular redirection
-method. The available methods are "location" or "refresh", with location
-being faster but less reliable on IIS servers. The default is "auto",
-which will attempt to intelligently choose the method based on the server
-environment.
+method. The available methods are **auto**, **location** and **refresh**,
+with location being faster but less reliable on IIS servers.
+The default is **auto**, which will attempt to intelligently choose the
+method based on the server environment.
The optional third parameter allows you to send a specific HTTP Response
Code - this could be used for example to create 301 redirects for search
engine purposes. The default Response Code is 302. The third parameter is
-*only* available with 'location' redirects, and not 'refresh'. Examples::
+*only* available with **location** redirects, and not *refresh*. Examples::
if ($logged_in == FALSE)
{      
@@ -324,8 +370,14 @@ engine purposes. The default Response Code is 302. The third parameter is
is outputted to the browser since it utilizes server headers.
.. note:: For very fine grained control over headers, you should use the
- `Output Library </libraries/output>` set_header() function.
+ `Output Library </libraries/output>` ``set_header()`` method.
-.. note:: To IIS users: if you hide the `Server` HTTP header, the "auto"
+.. note:: To IIS users: if you hide the `Server` HTTP header, the *auto*
method won't detect IIS, in that case it is advised you explicitly
- use the "refresh" method.
+ use the **refresh** method.
+
+.. note:: When the **location** method is used, an HTTP status code of 303
+ will *automatically* be selected when the page is currently accessed
+ via POST and HTTP/1.1 is used.
+
+.. important:: This function will terminate script execution. \ No newline at end of file
diff --git a/user_guide_src/source/installation/upgrade_211.rst b/user_guide_src/source/installation/upgrade_211.rst
index 59faca8e6..f0e70f6dc 100644
--- a/user_guide_src/source/installation/upgrade_211.rst
+++ b/user_guide_src/source/installation/upgrade_211.rst
@@ -8,9 +8,7 @@ replacing the index.php file with a static one.
Step 1: Update your CodeIgniter files
=====================================
-Replace all files and directories in your "system" folder and replace
-your index.php file. If any modifications were made to your index.php
-they will need to be made fresh in this new one.
+Replace all files and directories in your "system" folder.
.. note:: If you have any custom developed files in these folders please
make copies of them first.
diff --git a/user_guide_src/source/installation/upgrade_212.rst b/user_guide_src/source/installation/upgrade_212.rst
index 205ad8622..4b76482e3 100644
--- a/user_guide_src/source/installation/upgrade_212.rst
+++ b/user_guide_src/source/installation/upgrade_212.rst
@@ -8,9 +8,7 @@ replacing the index.php file with a static one.
Step 1: Update your CodeIgniter files
=====================================
-Replace all files and directories in your "system" folder and replace
-your index.php file. If any modifications were made to your index.php
-they will need to be made fresh in this new one.
+Replace all files and directories in your "system" folder.
.. note:: If you have any custom developed files in these folders please
make copies of them first.
diff --git a/user_guide_src/source/installation/upgrade_213.rst b/user_guide_src/source/installation/upgrade_213.rst
new file mode 100644
index 000000000..3a3497ccb
--- /dev/null
+++ b/user_guide_src/source/installation/upgrade_213.rst
@@ -0,0 +1,20 @@
+#############################
+Upgrading from 2.1.2 to 2.1.3
+#############################
+
+Before performing an update you should take your site offline by
+replacing the index.php file with a static one.
+
+Step 1: Update your CodeIgniter files
+=====================================
+
+Replace all files and directories in your "system" folder.
+
+.. note:: If you have any custom developed files in these folders please
+ make copies of them first.
+
+Step 2: Update your user guide
+==============================
+
+Please also replace your local copy of the user guide with the new
+version. \ No newline at end of file
diff --git a/user_guide_src/source/installation/upgrade_300.rst b/user_guide_src/source/installation/upgrade_300.rst
index 6d99f4655..0af21b11e 100644
--- a/user_guide_src/source/installation/upgrade_300.rst
+++ b/user_guide_src/source/installation/upgrade_300.rst
@@ -31,8 +31,19 @@ Step 3: Remove $autoload['core'] from your config/autoload.php
Use of the ``$autoload['core']`` config array has been deprecated as of CodeIgniter 1.4.1 and is now removed.
Move any entries that you might have listed there to ``$autoload['libraries']`` instead.
+***************************************************
+Step 4: Move your Log class overrides or extensions
+***************************************************
+
+The Log Class is considered as a "core" class and is now located in the
+**system/core/** directory. Therefore, in order for your Log class overrides
+or extensions to work, you need to move them to **application/core/**::
+
+ application/libraries/Log.php -> application/core/Log.php
+ application/libraries/MY_Log.php -> application/core/MY_log.php
+
**************************************************************
-Step 4: Add new session driver items to your config/config.php
+Step 5: Add new session driver items to your config/config.php
**************************************************************
With the change from a single Session Library to the new Session Driver, two new config items have been added:
@@ -48,7 +59,7 @@ available as valid drivers, neither of these configuration items are required. H
add them for clarity and ease of configuration in the future.
***************************************
-Step 5: Update your config/database.php
+Step 6: Update your config/database.php
***************************************
Due to 3.0.0's renaming of Active Record to Query Builder, inside your `config/database.php`, you will
@@ -60,13 +71,13 @@ need to rename the `$active_record` variable to `$query_builder`
$query_builder = TRUE;
*******************************
-Step 6: Move your errors folder
+Step 7: Move your errors folder
*******************************
In version 3.0.0, the errors folder has been moved from _application/errors* to _application/views/errors*.
*******************************************************
-Step 7: Update your config/routes.php containing (:any)
+Step 8: Update your config/routes.php containing (:any)
*******************************************************
Historically, CodeIgniter has always provided the **:any** wildcard in routing,
@@ -87,15 +98,37 @@ regular expression::
****************************************************************************
-Step 8: Check the calls to Array Helper's element() and elements() functions
+Step 9: Check the calls to Array Helper's element() and elements() functions
****************************************************************************
The default return value of these functions, when the required elements
don't exist, has been changed from FALSE to NULL.
-**********************************************************
-Step 9: Change usage of Email library with multiple emails
-**********************************************************
+*************************************************************
+Step 10: Update usage of Database Forge's drop_table() method
+*************************************************************
+
+Up until now, ``drop_table()`` added an IF EXISTS clause by default or it didn't work
+at all with some drivers. In CodeIgniter 3.0, the IF EXISTS condition is no longer added
+by default and has an optional second parameter that allows that instead and is set to
+FALSE by default.
+
+If your application relies on IF EXISTS, you'll have to change its usage.
+
+::
+
+ // Now produces just DROP TABLE `table_name`
+ $this->dbforge->drop_table('table_name');
+
+ // Produces DROP TABLE IF EXISTS `table_name`
+ $this->dbforge->drop_table('table_name', TRUE);
+
+.. note:: The given example users MySQL-specific syntax, but it should work across
+ all drivers with the exception of ODBC.
+
+***********************************************************
+Step 11: Change usage of Email library with multiple emails
+***********************************************************
The :doc:`Email library <../libraries/email>` will automatically clear the
set parameters after successfully sending emails. To override this behaviour,
@@ -110,7 +143,7 @@ pass FALSE as the first parameter in the ``send()`` method:
****************************************************************
-Step 10: Remove usage of (previously) deprecated functionalities
+Step 12: Remove usage of (previously) deprecated functionalities
****************************************************************
In addition to the ``$autoload['core']`` configuration setting, there's a number of other functionalities
@@ -159,23 +192,37 @@ CodeIgniter 3.1+.
String helper repeater()
========================
-:doc:`String Helper <../helpers/string_helper>` function ``repeater()`` is now just an alias for
-PHP's native ``str_repeat()`` function. It is deprecated and scheduled for removal in
-CodeIgniter 3.1+.
+:doc:`String Helper <../helpers/string_helper>` function :php:func:`repeater()` is now just an alias for
+PHP's native ``str_repeat()`` function. It is deprecated and scheduled for removal in CodeIgniter 3.1+.
.. note:: This function is still available, but you're strongly encouraged to remove it's usage sooner
rather than later.
-Form helper form_prep()
-=======================
+String helper trim_slashes()
+============================
-:doc:`Form Helper <../helpers/form_helper>` function ``form_prep()`` is now just an alias for
-:doc:`common function <../general/common_functions>` ``html_escape()`` and it's second argument
-is ignored. It is deprecated and scheduled for removal in CodeIgniter 3.1+.
+:doc:`String Helper <../helpers/string_helper>` function :php:func:`trim_slashes()` is now just an alias
+for PHP's native ``trim()`` function (with a slash passed as its second argument). It is deprecated and
+scheduled for removal in CodeIgniter 3.1+.
.. note:: This function is still available, but you're strongly encouraged to remove it's usage sooner
rather than later.
+Email helper functions
+======================
+
+:doc:`Email Helper <../helpers/email_helper>` only has two functions
+
+ - :php:func:`valid_email()`
+ - :php:func:`send_email()`
+
+Both of them are now aliases for PHP's native ``filter_var()`` and ``mail()`` functions, respectively.
+Therefore the :doc:`Email Helper <../helpers/email_helper>` altogether is being deprecated and
+is scheduled for removal in CodeIgniter 3.1+.
+
+.. note:: These functions are still available, but you're strongly encouraged to remove their usage
+ sooner rather than later.
+
Date helper standard_date()
===========================
@@ -212,4 +259,59 @@ As a result of that, the 'anchor_class' setting is now deprecated and scheduled
CodeIgniter 3.1+.
.. note:: This setting is still available, but you're strongly encouraged to remove its' usage sooner
- rather than later. \ No newline at end of file
+ rather than later.
+
+String helper random_string() types 'unique' and 'encrypt'
+==========================================================
+
+When using the :doc:`String Helper <helpers/string_helper>` function :php:func:`random_string()`,
+you should no longer pass the **unique** and **encrypt** randomization types. They are only
+aliases for **md5** and **sha1** respectively and are now deprecated and scheduled for removal
+in CodeIgniter 3.1+.
+
+.. note:: These options are still available, but you're strongly encouraged to remove their usage
+ sooner rather than later.
+
+URL helper url_title() separators 'dash' and 'underscore'
+=========================================================
+
+When using the :doc:`URL Helper <helpers/url_helper>` function :php:func:`url_title()`, you
+should no longer pass **dash** or **underscore** as the word separator. This function will
+now accept any character and you should just pass the chosen character directly, so you
+should write '-' instead of 'dash' and '_' instead of 'underscore'.
+
+**dash** and **underscore** now act as aliases and are deprecated and scheduled for removal
+in CodeIgniter 3.1+.
+
+.. note:: These options are still available, but you're strongly encouraged to remove their usage
+ sooner rather than later.
+
+Database Forge method add_column() with an AFTER clause
+=======================================================
+
+If you have used the **third parameter** for :doc:`Database Forge <database/forge>` method
+``add_column()`` to add a field for an AFTER clause, then you should change its usage.
+
+That third parameter has been deprecated and scheduled for removal in CodeIgniter 3.1+.
+
+You should now put AFTER clause field names in the field definition array instead::
+
+ // Old usage:
+ $field = array(
+ 'new_field' => array('type' => 'TEXT')
+ );
+
+ $this->dbforge->add_column('table_name', $field, 'another_field');
+
+ // New usage:
+ $field = array(
+ 'new_field' => array('type' => 'TEXT', 'after' => 'another_field')
+ );
+
+ $this->dbforge->add_column('table_name', $field);
+
+.. note:: The parameter is still available, but you're strongly encouraged to remove its usage
+ sooner rather than later.
+
+.. note:: This is for MySQL and CUBRID databases only! Other drivers don't support this
+ clause and will silently ignore it.
diff --git a/user_guide_src/source/installation/upgrading.rst b/user_guide_src/source/installation/upgrading.rst
index 545f344ee..4f276207c 100644
--- a/user_guide_src/source/installation/upgrading.rst
+++ b/user_guide_src/source/installation/upgrading.rst
@@ -5,7 +5,8 @@ Upgrading From a Previous Version
Please read the upgrade notes corresponding to the version you are
upgrading from.
-- :doc:`Upgrading from 2.1.2 to 3.0.0 <upgrade_300>`
+- :doc:`Upgrading from 2.1.3 to 3.0.0 <upgrade_300>`
+- :doc:`Upgrading from 2.1.2 to 2.1.3 <upgrade_213>`
- :doc:`Upgrading from 2.1.1 to 2.1.2 <upgrade_212>`
- :doc:`Upgrading from 2.1.0 to 2.1.1 <upgrade_211>`
- :doc:`Upgrading from 2.0.3 to 2.1.0 <upgrade_210>`
diff --git a/user_guide_src/source/libraries/form_validation.rst b/user_guide_src/source/libraries/form_validation.rst
index 4d1940212..a3a35b499 100644
--- a/user_guide_src/source/libraries/form_validation.rst
+++ b/user_guide_src/source/libraries/form_validation.rst
@@ -288,8 +288,8 @@ CodeIgniter lets you pipe multiple rules together. Let's try it. Change
your rules in the third parameter of rule setting function, like this::
$this->form_validation->set_rules('username', 'Username', 'required|min_length[5]|max_length[12]|is_unique[users.username]');
- $this->form_validation->set_rules('password', 'Password', 'required|matches[passconf]');
- $this->form_validation->set_rules('passconf', 'Password Confirmation', 'required');
+ $this->form_validation->set_rules('password', 'Password', 'required');
+ $this->form_validation->set_rules('passconf', 'Password Confirmation', 'required|matches[password]');
$this->form_validation->set_rules('email', 'Email', 'required|valid_email|is_unique[users.email]');
The above code sets the following rules:
@@ -315,8 +315,8 @@ can also prep your data in various ways. For example, you can set up
rules like this::
$this->form_validation->set_rules('username', 'Username', 'trim|required|min_length[5]|max_length[12]|xss_clean');
- $this->form_validation->set_rules('password', 'Password', 'trim|required|matches[passconf]|md5');
- $this->form_validation->set_rules('passconf', 'Password Confirmation', 'trim|required');
+ $this->form_validation->set_rules('password', 'Password', 'trim|required|md5');
+ $this->form_validation->set_rules('passconf', 'Password Confirmation', 'trim|required|matches[password]');
$this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email');
In the above example, we are "trimming" the fields, converting the
@@ -910,9 +910,6 @@ Rule Parameter Description
to two parameters, where at least one is required (to pass
the field data).
-.. note:: When using the **matches** rule, the form item specified
- to compare against must already be defined.
-
******************
Prepping Reference
******************
diff --git a/user_guide_src/source/libraries/input.rst b/user_guide_src/source/libraries/input.rst
index c0b9c6589..177f5cb64 100644
--- a/user_guide_src/source/libraries/input.rst
+++ b/user_guide_src/source/libraries/input.rst
@@ -5,8 +5,7 @@ Input Class
The Input Class serves two purposes:
#. It pre-processes global input data for security.
-#. It provides some helper functions for fetching input data and
- pre-processing it.
+#. It provides some helper methods for fetching input data and pre-processing it.
.. note:: This class is initialized automatically by the system so there
is no need to do it manually.
@@ -14,7 +13,7 @@ The Input Class serves two purposes:
Security Filtering
==================
-The security filtering function is called automatically when a new
+The security filtering method is called automatically when a new
:doc:`controller <../general/controllers>` is invoked. It does the
following:
@@ -47,7 +46,7 @@ Using POST, GET, COOKIE, or SERVER Data
CodeIgniter comes with four helper methods that let you fetch POST, GET,
COOKIE or SERVER items. The main advantage of using the provided
-functions rather than fetching an item directly ($_POST['something'])
+methods rather than fetching an item directly (``$_POST['something']``)
is that the methods will check to see if the item is set and return
NULL if not. This lets you conveniently use data without
having to test whether an item exists first. In other words, normally
@@ -55,7 +54,7 @@ you might do something like this::
$something = isset($_POST['something']) ? $_POST['something'] : NULL;
-With CodeIgniter's built in functions you can simply do this::
+With CodeIgniter's built in methods you can simply do this::
$something = $this->input->post('something');
@@ -74,7 +73,7 @@ looking for::
$this->input->post('some_data');
-The function returns NULL if the item you are attempting to retrieve
+The method returns NULL if the item you are attempting to retrieve
does not exist.
The second optional parameter lets you run the data through the XSS
@@ -89,7 +88,7 @@ To return an array of all POST items call without any parameters.
To return all POST items and pass them through the XSS filter set the
first parameter NULL while setting the second parameter to boolean;
-The function returns NULL if there are no items in the POST.
+The method returns NULL if there are no items in the POST.
::
@@ -99,8 +98,8 @@ The function returns NULL if there are no items in the POST.
$this->input->get()
===================
-This function is identical to the post function, only it fetches get
-data::
+This method is identical to the post method, only it fetches get data
+::
$this->input->get('some_data', TRUE);
@@ -109,7 +108,7 @@ To return an array of all GET items call without any parameters.
To return all GET items and pass them through the XSS filter set the
first parameter NULL while setting the second parameter to boolean;
-The function returns NULL if there are no items in the GET.
+The method returns NULL if there are no items in the GET.
::
@@ -118,9 +117,9 @@ The function returns NULL if there are no items in the GET.
$this->input->get_post()
-=========================
+========================
-This function will search through both the post and get streams for
+This method will search through both the post and get streams for
data, looking first in post, and then in get::
$this->input->get_post('some_data', TRUE);
@@ -128,8 +127,8 @@ data, looking first in post, and then in get::
$this->input->cookie()
======================
-This function is identical to the post function, only it fetches cookie
-data::
+This method is identical to the post method, only it fetches cookie data
+::
$this->input->cookie('some_cookie');
$this->input->cookie('some_cookie, TRUE); // with XSS filter
@@ -138,16 +137,43 @@ data::
$this->input->server()
======================
-This function is identical to the above functions, only it fetches
+This method is identical to the above methods, only it fetches server
server data::
$this->input->server('some_data');
+Using the php://input stream
+============================
+
+If you want to utilize the PUT, DELETE, PATCH or other exotic request
+methods, they can only be accessed via a special input stream, that
+can only be read once. This isn't as easy as just reading from e.g.
+the ``$_POST`` array, because it will always exist and you can try
+and access multiple variables without caring that you might only have
+one shot at all of the POST data.
+
+CodeIgniter will take care of that for you, and you can access data
+from the **php://input** stream at any time, just by calling the
+``input_stream()`` method::
+
+ $this->input->input_stream('key');
+
+Similar to the methods above, if the requested data is not found, it
+will return NULL and you can also decide whether to run the data
+through ``xss_clean()`` by passing a boolean value as the second
+parameter::
+
+ $this->input->input_stream('key', TRUE); // XSS Clean
+ $this->input->input_stream('key', FALSE); // No XSS filter
+
+.. note:: You can utilize method() in order to know if you're reading
+ PUT, DELETE or PATCH data.
+
$this->input->set_cookie()
-===========================
+==========================
Sets a cookie containing the values you specify. There are two ways to
-pass information to this function so that a cookie can be set: Array
+pass information to this method so that a cookie can be set: Array
Method, and Discrete Parameters:
Array Method
@@ -182,7 +208,7 @@ For site-wide cookies regardless of how your site is requested, add your
URL to the **domain** starting with a period, like this:
.your-domain.com
-The path is usually not needed since the function sets a root path.
+The path is usually not needed since the method sets a root path.
The prefix is only needed if you need to avoid name collisions with
other identically named cookies for your server.
@@ -198,22 +224,25 @@ parameters::
$this->input->set_cookie($name, $value, $expire, $domain, $path, $prefix, $secure);
+
$this->input->ip_address()
-===========================
+==========================
Returns the IP address for the current user. If the IP address is not
-valid, the function will return an IP of: 0.0.0.0
+valid, the method will return an IP of: 0.0.0.0
::
echo $this->input->ip_address();
$this->input->valid_ip($ip)
-============================
+===========================
Takes an IP address as input and returns TRUE or FALSE (boolean) if it
-is valid or not. Note: The $this->input->ip_address() function above
-validates the IP automatically.
+is valid or not.
+
+.. note:: The $this->input->ip_address() method above automatically
+ validates the IP address.
::
@@ -230,7 +259,7 @@ Accepts an optional second string parameter of 'ipv4' or 'ipv6' to specify
an IP format. The default checks for both formats.
$this->input->user_agent()
-===========================
+==========================
Returns the user agent (web browser) being used by the current user.
Returns FALSE if it's not available.
@@ -243,7 +272,7 @@ See the :doc:`User Agent Class <user_agent>` for methods which extract
information from the user agent string.
$this->input->request_headers()
-================================
+===============================
Useful if running in a non-Apache environment where
`apache_request_headers() <http://php.net/apache_request_headers>`_
@@ -253,8 +282,8 @@ will not be supported. Returns an array of headers.
$headers = $this->input->request_headers();
-$this->input->get_request_header();
-=====================================
+$this->input->get_request_header()
+==================================
Returns a single member of the request headers array.
@@ -263,13 +292,13 @@ Returns a single member of the request headers array.
$this->input->get_request_header('some-header', TRUE);
$this->input->is_ajax_request()
-=================================
+===============================
Checks to see if the HTTP_X_REQUESTED_WITH server header has been
set, and returns a boolean response.
$this->input->is_cli_request()
-================================
+==============================
Checks to see if the STDIN constant is set, which is a failsafe way to
see if PHP is being run on the command line.
@@ -278,8 +307,8 @@ see if PHP is being run on the command line.
$this->input->is_cli_request()
-$this->input->method();
-=====================================
+$this->input->method()
+======================
Returns the $_SERVER['REQUEST_METHOD'], optional set uppercase or lowercase (default lowercase).
@@ -287,4 +316,4 @@ Returns the $_SERVER['REQUEST_METHOD'], optional set uppercase or lowercase (def
echo $this->input->method(TRUE); // Outputs: POST
echo $this->input->method(FALSE); // Outputs: post
- echo $this->input->method(); // Outputs: post
+ echo $this->input->method(); // Outputs: post \ No newline at end of file
diff --git a/user_guide_src/source/libraries/sessions.rst b/user_guide_src/source/libraries/sessions.rst
index dd9e8cbb4..ee7fb0b1c 100644
--- a/user_guide_src/source/libraries/sessions.rst
+++ b/user_guide_src/source/libraries/sessions.rst
@@ -388,7 +388,7 @@ session class::
user_agent varchar(120) NOT NULL,
last_activity int(10) unsigned DEFAULT 0 NOT NULL,
user_data text NOT NULL,
- PRIMARY KEY (session_id),
+ PRIMARY KEY (session_id, ip_address, user_agent),
KEY `last_activity_idx` (`last_activity`)
);
diff --git a/user_guide_src/source/libraries/unit_testing.rst b/user_guide_src/source/libraries/unit_testing.rst
index 03819b27c..6bd91bf88 100644
--- a/user_guide_src/source/libraries/unit_testing.rst
+++ b/user_guide_src/source/libraries/unit_testing.rst
@@ -131,7 +131,7 @@ default:
- Any notes you entered for the test (notes)
You can customize which of these items get displayed by using
-$this->unit->set_items(). For example, if you only wanted the test name
+$this->unit->set_test_items(). For example, if you only wanted the test name
and the result displayed:
Customizing displayed tests