Type | Line | Description |
---|---|---|
4 | www.phpsmartdb.com/ | |
8 | www.phpsmartdb.com/license | |
24 | note: PRI=Primary Key, UNI=Unique index, MUL=multiple... seems to mean the same as UNI though | |
27 | other collations can easily be added if needed | |
28 | UNIQUE when Key=PRI,UNI, or MUL. FULLTEXT for fulltext index | |
69 | i.e. fulltext index on this column | |
80 | Hold an instance of the class | |
83 | only allow the singleton to access this class | |
87 | The singleton method | |
101 | call function from the singleton | |
103 | the returned array will contain at least this information | |
110 | note: PRI=Primary Key, UNI=Unique index, MUL=multiple... seems to mean the same as UNI though | |
113 | other collations can easily be added if needed | |
135 | get columns information from information_schema | |
152 | for PMA bc: | |
153 | `[SCHEMA_FIELD_NAME]` AS `[SHOW_FULL_COLUMNS_FIELD_NAME]` | |
180 | lookup indexes on all tables | |
190 | i.e. $row['Index_type']=="BTREE" | |
191 | non-unique index | |
194 | unique index | |
195 | if key is not yet set, we need it |
Type | Line | Description |
---|---|---|
4 | www.phpsmartdb.com/ | |
8 | www.phpsmartdb.com/license | |
24 | note: PRI=Primary Key, UNI=Unique index, MUL=multiple... seems to mean the same as UNI though | |
27 | other collations can easily be added if needed | |
28 | UNIQUE when Key=PRI,UNI, or MUL. MUL could also mean NONUNIQUE. FULLTEXT for fulltext index | |
69 | i.e. fulltext index on this column | |
113 | options... all booleans | |
120 | Hold an instance of the class | |
123 | only allow the singleton to access this class | |
127 | The singleton method | |
147 | for each table | |
149 | table does not exist | |
153 | table exists | |
156 | lookup indexes on this table ("SHOW FULL FIELDS" doesnt provide all of this) | |
160 | get indexes by columnname | |
163 | get column for this index | |
165 | force index type to FULLTEXT or UNIQUE. if not fulltext, assume it's a unique | |
167 | Index_type == BTREE | |
176 | if an index exists for this column already, remove it | |
179 | an index exists already | |
180 | ie PRIMARY, 'id', whatever. references the index | |
181 | ie PRIMARY, 'id', whatever. references the index | |
184 | this index is not our PRIMARY index, so let's remove it | |
186 | dont use this index | |
189 | this index man be our PRIMARY index, so let's remove the OLD index | |
195 | ie PRIMARY, 'id', whatever. references the index | |
196 | ie FULLTEXT, UNIQUE, or NONUNIQUE | |
200 | get regular column properties of the table | |
204 | first- delete fields and 'track' updates, removal of keys, and removal of indexes | |
206 | for each field in this table | |
209 | set indexes. "IndexType" is not provided in the $currentField assoc ("SHOW FULL FIELDS FROM `$tableName`" doesn't provide this) | |
211 | see if indexType is set | |
215 | if key is not yet set, we need it for non-fulltext indexes. | |
217 | unique | |
218 | nonunique | |
222 | need this field for sync | |
223 | $currentField['IndexName'] = ""; //dont need this for sync | |
228 | delete rows in current db table that are not in new db structure | |
231 | Message(" ---- Field '<b>".$fieldName."</b>' exists. Comparing properties..."); | |
233 | mark field as found in current db table | |
238 | drop keys and indexes | |
241 | update fields that already exist to remove auto_increment so we can drop keys and indexes | |
244 | only update auto_increment fields | |
250 | drop indexes | |
257 | drop keys | |
263 | then add indexes on fields that already exist | |
266 | indexType can be UNIQUE or NONUNIQUE | |
271 | then add fulltext indexes on fields that already exist | |
278 | add new keys on fields that already exist | |
285 | update fields that already exist to their final structure (includes auto-increment) | |
294 | insert new fields (including keys and indexes on those fields) | |
315 | inserts any fields in $newDbStructure that do not have the ['verified'] flag set | |
317 | table was created by us now. no need to check it | |
321 | skip this entry | |
322 | if verified flag is not set, field doesnt exist in db | |
331 | compares the two fields, adding the fields to $this->_fieldsToUpdate[], $this->_indexesToDrop[], and/or $this->_keysToDrop[] if necessary | |
333 | print_r($currentField); | |
334 | print_r($newField); | |
345 | go through all properties to see what (if anything) needs updated | |
348 | properties to ignore | |
354 | Collation is a special case. Ignore it always unless it's set in the new structure | |
359 | Collation only applies to string types: "CHAR, VARCHAR, the TEXT types, ENUM, and SET data types" | |
361 | data type does not suppport collations | |
365 | valid collation | |
371 | check for index type changes (ie fulltext) | |
396 | special case where MUL==UNI | |
401 | check for primary/unique key changes | |
402 | remove primary key | |
418 | end switch | |
419 | end foreach | |
421 | regular update | |
424 | remove unique or fulltext index | |
427 | remove primary key | |
430 | add unique index | |
433 | add fulltext index | |
436 | add primary key | |
450 | copy structure with keys and indexes | |
451 | copy data | |
476 | non-unique index | |
539 | compile default value for CURRENT_TIMESTAMP | |
544 | blob/text types cant have default values in mysql. make sure it's not an enum/set though that may contain the text 'text' or 'blob' | |
549 | no quotes around default value | |
553 | quote default value | |
575 | does not update indexes/primary keys. use AddPrimaryKey and AddIndex for that... | |
587 | compile default value | |
592 | blob/text types cant have default values in mysql | |
597 | no quotes around default value for CURRENT_TIMESTAMP | |
601 | quote default value | |
613 | Collation only applies to string types: "CHAR, VARCHAR, the TEXT types, ENUM, and SET data types" | |
614 | returns TRUE if collation is valid for the given data type, false if not | |
615 | reference: http://dev.mysql.com/doc/refman/5.0/en/string-type-overview.html | |
618 | char and varchar | |
619 | tinytext, text, mediumtext, and longtext | |
620 | enum | |
621 | set | |
622 | valid | |
624 | not valid | |
629 | Collation only applies to string types: "CHAR, VARCHAR, the TEXT types, ENUM, and SET data types" | |
631 | forced character set | |
632 | reference: http://dev.mysql.com/doc/refman/5.0/en/charset-charsets.html | |
643 | no need for more yet. also may need to add a collation option | |
651 | table not yet backed up | |
661 | echo $str."<br>\n"; |
Type | Line | Description |
---|---|---|
4 | www.phpsmartdb.com/ | |
8 | www.phpsmartdb.com/license | |
15 | PHP 5.3.0 is required. removing this check for performance. PHP <5.3 is considered EOL now | |
16 | if (strnatcmp( ($version=phpversion()), '5.3.0') < 0){ //check php constraints. eventually we'll get rid of this when everyone is 5.3.0+ | |
17 | throw new Exception("This version of SmartDatabase only works with PHP versions 5.3.0 and newer. You are using PHP version $version"); | |
18 | } | |
28 | should update this for ANY change to structure at least. used for determining if a serialized SmartDatabase object is invalid/out of date | |
30 | ///////////////////////////// SERIALIZATION - At top so we don't forget to update these when we add new vars ////////////////////////// | |
45 | //////////////////////////////////////////////////////////////////////////////////// | |
50 | readonly. set in constructor | |
78 | php.net/manual/en/timezones.php | |
86 | DbManager - The DbManager instance that will be used to perform operations on the actual database. If null, no database operations can be performed (use for 'in-memory' instances) | |
87 | string - the database schema file to load. If left null, you will need to either build the database yourself useing ->AddTable() or load a schema from XML using ->LoadSchema() | |
88 | boolean - development mode toggle. When true, does extra verifications (ie data types, columns, etc) that are a must for development, but may slow things down a bit when running in production. | |
89 | boolean. if true and in $DEV_MODE, warnings will be shown for like missing classes and etc. | |
90 | string (i.e. "America/Indiana/Indianapolis"). if set, sets the DefaultTimezone to this value. using "date_default_timezone_get()" will use php's default date timezone that is currently set and can be changed with a call to "date_default_timezone_set(...);". empty will use default system time (not recommended). Ref: http://php.net/manual/en/timezones.php | |
99 | default options | |
100 | 'db-manager' => null, | |
101 | reverse compatibility | |
107 | reverse compatibility. constructor used to be (DbManager $dbManager=null, $xmlSchemaFilePath=null). now it's an array. need to support old versions though | |
110 | first parameter is DbManager | |
113 | merge in default options | |
116 | set local variables in this object | |
122 | load schema, if given | |
125 | use default timezone? | |
129 | ///////////////////////////// Table Management /////////////////////////////////// | |
161 | make $this Databsae the column's Database | |
162 | save this table with the table name as key | |
172 | $this database is no longer the table's database | |
194 | ///////////////////////////// LoadXmlSchema /////////////////////////////////// | |
208 | if set to true, all tables currently loaded within this instance will be removed (unmanaged. the actual table still exists in the real db). if false, the given $xmlSchemaFilePath is simply added to whatever is currently in this database instance (tables/properties with the same name are overwritten with the new schema) | |
216 | clear old tables... new database schema coming in. | |
221 | default schema path | |
224 | validate the xml with the schema | |
230 | store schema's last mod time. Useful for serializing objects, storing them somewhere ($_SESSION, memcached, etc), then retrieving without needing to completely rebuild the database from xml | |
247 | bs-"boolean string" | |
252 | www.w3.org/2001/XMLSchema">'."\n"; | |
283 | only print if we need to | |
287 | only set display name if it isnt the same as the column name | |
291 | enum and set data types | |
295 | non-enum or set data type | |
297 | only print if we need to | |
298 | only save PossibleValues to its own attribute if not an enum or set data type... otherwise, it's part of the data type | |
310 | dont set a MaxSize for int with maxsize=1. this field doesn't matter anyway. it's for left-zero padding | |
313 | dont set MaxSize for binary with maxsize=1. this is default for binary columns | |
316 | dont set MaxSize for decimal with maxsize="14,4". this is default for binary columns | |
318 | filters pass. print MaxSize | |
322 | true is default, so only print if false | |
325 | true is default, so only print if false | |
331 | true is default, so only print if false | |
334 | true is default, so only print if false | |
343 | auto-increment shouldnt be required, otherwise we dont get the autoincrement value | |
355 | "text" is default, so only print if something else | |
368 | SortOrder not yet implemented | |
369 | $xml .= ' SortOrder="'.$Column->SortOrder.'"'; | |
378 | handle related columns (ie foreign keys) | |
412 | write xml to file? | |
427 | database table/column structure | |
429 | key is the table name, value is an array containing all inhertied table names. (ie key table inherits value tables) | |
441 | track inherited tables. will handle adding inherited columns after all regular tables/column have been added | |
442 | "InheritsTableName" attribute is old and deprecated. use the plural "InheritsTableNames" since it is supported now | |
444 | $inheritsTableNames could be CSV of multiple table names | |
451 | optimization. we'll manually call $table->Refresh() after all columns have been added | |
459 | add column aliases | |
460 | if the "Aliases" attribute exists.. | |
461 | convert CSV string into array or FALSE if it's an empty string (false will avoid the foreach loop) | |
469 | enum data type | |
471 | parse out the enum values | |
474 | set data type | |
476 | parse out the set values | |
479 | non-enum or set data type | |
489 | default value is true | |
490 | default value is true | |
492 | default value is true | |
493 | default value is true | |
501 | "text" is default value | |
502 | auto-increment shouldnt be required, otherwise we dont get the autoincrement value | |
508 | add column possible values. if set and the data type is enum or set, these will be used as the only possible values instead of the enum/set values (ie you can use a subset of the possible values specified in the enum/set data type) | |
509 | if the "PossibleValues" attribute exists.. | |
510 | convert CSV string into array or FALSE if it's an empty string | |
515 | if the Column is a set data type, we need to verify each of the PossibleValues isn't a subset of a different PossibleValue. | |
516 | ex: "tree" and "apple tree" will not be accepted because MySQL uses %tree% to search set like a CSV, so %tree% would match the 'apple tree' element as well | |
517 | well just check for it and not allow it to avoid problems ahead of time | |
518 | this is the behavior of MySQL - https://dev.mysql.com/doc/refman/5.7/en/set.html | |
532 | optimization by doing this manually instead of using $table->AutoRefresh | |
533 | re-enable auto refresh | |
536 | foreach($allXmlClasses | |
538 | is_array($allXmlClasses) | |
540 | related columns | |
546 | compile all in this relation | |
552 | set all in this relation | |
570 | handle inherited tables | |
588 | this table is already ready to go. move along | |
595 | inherited table is not ready yet, build it first | |
622 | libxml_use_internal_errors(true); //uncomment to show xml parse errors | |
627 | tried to pull in default values from the XSD document (for "AllowSet", "AllowGet", etc). could never get it to work. instead, we just set those default values in the XML parser and in the SmartColumn class itself | |
628 | if($xsdFilePath){ | |
629 | $reader->setSchema($xsdFilePath); | |
630 | } | |
644 | v=value) | |
647 | a=attributes | |
664 | when validating data, if any error is encountered, libxml will generate PHP Warnings, | |
665 | which is something I think is very annoying. to avoid that, you can disable libxml errors | |
666 | and get them yourself. remember! this function must be called before you instantiate any DomDocument object! | |
669 | creating a DomDocument object | |
671 | loading the xml data | |
673 | tries to validade the file | |
675 | get errors | |
676 | each element of the array $allErrors will be a LibXmlError Object | |
683 | ///////////////////////////// SyncDb /////////////////////////////////// | |
689 | if true, prints all Sync SQL instead of executing it | |
690 | if true, creates a backup table before altering any existing tables | |
691 | if true, tables and columns will be created if they do not exist | |
692 | if true, existing SQL columns will be updated to match properties defined in the SmartDatabase | |
693 | if true, columns that do not exist on a SmartDb managed table will be removed (note: unmanaged TABLES are never deleted!) | |
701 | default options | |
708 | overwrite $defaultOptions with any $options specified | |
717 | print_nice($syncStructure); | |
719 | TODO: support other databases | |
722 | parameters: DoSync($dbManager, $newDbStructure, $backupTables=true, $doInsert=true, $doUpdate=true, $doDelete=true, $debugMode=false) | |
732 | abstract tables do not actually go in the database, but they can be inherited from | |
734 | if table name was updated programmatically, we need this to be right in our sync structure | |
738 | if column name was updated programmatically, we need this to be right in our sync structure | |
740 | Field | |
743 | Type | |
746 | enum.. and set.. types | |
750 | ..char.. type | |
754 | ..int.. type | |
757 | ..int.. primary key | |
761 | ..binary.. type | |
765 | ..decimal.. type | |
767 | default precision | |
774 | array, object types | |
775 | use text for array/object types. we can make the size configurable somehow if we need to down the road | |
778 | Null | |
783 | Key | |
792 | Fulltext index | |
796 | Nonunique index | |
805 | Default | |
808 | Extra | |
813 | Collation | |
818 | TODO: get this hard-coded SQL out of here... move to Sync class for a MySQL database | |
822 | all columns | |
831 | forced character set | |
832 | reference: http://dev.mysql.com/doc/refman/5.0/en/charset-charsets.html | |
844 | no need for more yet. also may need to add a collation option | |
850 | null | |
856 | default value | |
857 | blob/text types cant have default values in mysql | |
861 | auto increment | |
866 | primary key | |
872 | unique | |
874 | no need to specify as UNIQUE if it's a primary key. this will make 2 indexes | |
879 | fulltext index | |
884 | nonunique index | |
892 | key columns | |
899 | fulltext columns | |
904 | nonunique columns | |
915 | ///////////////////////////// ReadDatabase ////////////////////////////////// | |
921 | if true, the current smart database structure will be preserved. existing tables/column will be overwritten by the db definitions | |
922 | will not import tables that start with the given prefix | |
923 | string - if provided, will only read the structure of the given table name | |
929 | default options | |
934 | overwrite $defaultOptions with any $options specified | |
941 | reset current database structure store in smartdb | |
946 | TODO: support other databases | |
947 | currently only works with PMA_MYSQL_INT_VERSION >= 50002 | |
950 | print_nice($sqlStructure); | |
954 | ignoring this table due to prefix match | |
957 | existing table (likely preserve-current option set to true) | |
960 | new table (likely preserve-current option set to false) | |
964 | optimization. we'll manually call $table->Refresh() after all columns have been added | |
966 | track the column number | |
968 | existing column (likely preserve-current option set to true) | |
971 | new column (likely preserve-current option set to false) | |
976 | $columnProps are the following: | |
977 | int(1) unsigned | |
987 | use datatype to determine each of the following vars: | |
995 | check for ENUM and SET data types | |
997 | find parenthesis in column type | |
998 | $pos contains parenthesis position | |
999 | ex type: "int(1) unsigned" | |
1000 | "int" | |
1001 | "(1) unsigned" | |
1002 | "(1)" - $unsigned will be 0 or 1 | |
1003 | 1 | |
1007 | parse out the enum/set values | |
1010 | size just holds the possible values. dont keep it around | |
1014 | no parenthesis in column's data type | |
1028 | these datatypes will never really be set in SQL, so this IF statement is pretty much worthless | |
1035 | for debugging | |
1059 | auto-increment shouldnt be required, otherwise we dont get the autoincrement value | |
1063 | use the column name to come up with something display friendly | |
1089 | replace hyphens and underscore with space | |
1090 | upper case the first words and trim | |
1092 | only set the display name if it's different from the column name, otherwise there's no need | |
1101 | optimization by doing this manually instead of using $table->AutoRefresh | |
1102 | re-enable auto refresh | |
1107 | $smartStructure = $this->BuildSyncStructure(); //current structure of the smartdb | |
1108 | print_nice($smartStructure); | |
1111 | ///////////////////////////// ArrayAccess /////////////////////////////////// | |
1140 | ///////////////////////////// Countable /////////////////////////////////// | |
1149 | ///////////////////////////// ERROR ON INVALID FUNCTIONS/VARS ////////////////////////// | |
1169 | ////////////////////////////// STATIC - GET SmartDatabase OBJECT FROM MEMCACHED //////////////////////////////// | |
1173 | options are same as SmartDatabase constructor, plus a few extra for memcached | |
1175 | DbManager - The DbManager instance that will be used to perform operations on the actual database. If null, no database operations can be performed (use for 'in-memory' instances) | |
1176 | string - REQUIRED for caching - the database schema file to load. If left null, you will need to either build the database yourself useing ->AddTable() or load a schema from XML using ->LoadSchema() | |
1177 | if set, $SmartDb->DefaultTimezone will be set to this value | |
1178 | boolean - development mode toggle. When true, does extra verifications (ie data types, columns, etc) that are a must for development, but may slow things down a bit when running in production. | |
1179 | boolean. if true and in $DEV_MODE, warnings will be shown for like missing classes and etc. | |
1180 | string. REQUIRED for caching. memcached lookup key | |
1181 | string. memcached connection host | |
1182 | int. memcached connection port | |
1183 | int. failover fast-ish | |
1184 | a much better serializer than the default one in PHP | |
1185 | actually makes things faster too | |
1192 | we'll make sure memcached exists before using it | |
1194 | default options | |
1195 | 'db-manager' => null, | |
1196 | 'xml-schema-file-path' => null, //REQUIRED for caching to work properly! | |
1197 | 'default-timezone' => '' //if set, $SmartDb->DefaultTimezone will be set to this value | |
1200 | REQUIRED for caching to work properly | |
1203 | override default. make failover fast-ish | |
1204 | a much better serializer than the default one in PHP | |
1205 | actually makes things faster too | |
1207 | overwrite $defaultOptions with any $options specified | |
1212 | check for all required arguments | |
1219 | check for cached smartdb | |
1223 | set options | |
1228 | try to get the key from cache | |
1231 | log an error if we didn't get a key. we'll see a lot of these if the cache server is down | |
1246 | check if cachedDb is found and valid | |
1248 | compare XML dates on cached schema to make sure cache is not expired. also make sure we're using the same version of the SmartDatabase | |
1253 | dates and smartdb version match. valid cached db | |
1254 | update the db manager. this can't be cached | |
1256 | timezone could change from what was cached | |
1261 | set our global to the cached db | |
1265 | if no valid cache db found. create a new smartdb and store it in cache | |
1268 | update cache (if no errors trying to fetch from memcached earlier) | |
1277 | end class | |
1284 | capture the output of print_r | |
1287 | replace something like '[element] => <newline> (' with <a href="javascript:toggleDisplay('...');">...</a><div id="..." style="display: none;"> | |
1290 | replace ')' on its own on a new line (surrounded by whitespace is ok) with '</div> | |
1293 | print the javascript function toggleDisplay() and then the transformed output | |
TODO | 67 | fully implement this. already has some stuff in SmartCell and SmartRow |
Type | Line | Description |
---|---|---|
4 | www.phpsmartdb.com/ | |
8 | www.phpsmartdb.com/license | |
42 | utility functions | |
47 | database management |
Type | Line | Description |
---|---|---|
4 | www.phpsmartdb.com/ | |
8 | www.phpsmartdb.com/license | |
22 | Variables | |
31 | encrypted. use $this->GetPassword(); | |
34 | default. see consts below | |
35 | deprecated in PHP v5.5. not recommended | |
38 | the PHP_INT_MAX constant doesnt work in some encrypters | |
46 | should be "AND" or "OR" only | |
54 | for mysqli driver, when false, persistent connections are used (recommended). for mysql driver, this is the 4th parameters for mysql_connect. see mysql_connect documentation | |
55 | for mysql driver only- this is the 5th parameters for mysql_connect. see mysql_connect documentation | |
56 | if set, OpenConnection does a mysql_set_charset() with the given option (ie 'utf8mb4'). ref: http://dev.mysql.com/doc/refman/5.7/en/charset-connection.html | |
57 | if set with charset, OpenConnection does a "SET NAMES..." with the given option (ie 'utf8mb4_unicode_ci'). ref: http://dev.mysql.com/doc/refman/5.7/en/charset-connection.html | |
58 | can be 'mysql' or 'mysqli' - the PHP extension to use for sql interaction. note- PHP v5.5+ deprecates 'mysql' driver | |
59 | TODO: make default '+0:00'. empty will use system default time (not recommended). use hard numbers like '+0:00' cause timezone abbreviations must be defined in mysql otherwise, otherwise they may take no effect | |
66 | for mysqli driver, when false, persistent connections are used (recommended). for mysql driver, this is the 4th parameters for mysql_connect. see mysql_connect documentation | |
67 | for mysql driver only- this is the 5th parameters for mysql_connect. see mysql_connect documentation | |
68 | if set, OpenConnection does a mysqli_set_charset() with the given option (ie 'utf8mb4'). ref: http://dev.mysql.com/doc/refman/5.7/en/charset-connection.html | |
69 | if set with charset, OpenConnection does a "SET NAMES..." with the given option (ie 'utf8mb4_unicode_ci'). ref: http://dev.mysql.com/doc/refman/5.7/en/charset-connection.html | |
70 | can be 'mysql' or 'mysqli' - the PHP extension to use for sql interaction. note- PHP v5.5+ deprecates 'mysql' driver | |
71 | TODO: make default '+0:00'. empty will use system default time (not recommended). use hard numbers like '+0:00' cause timezone abbreviations must be defined in mysql otherwise, otherwise they may take no effect | |
79 | SEE self::$DefaultOptions | |
80 | this is the 4th parameters for mysql_connect. see mysql_connect documentation | |
81 | this is the 5th parameters for mysql_connect. see mysql_connect documentation | |
82 | if set, OpenConnection does a mysql_set_charset() with the given option (ie 'utf8mb4'). ref: http://dev.mysql.com/doc/refman/5.7/en/charset-connection.html | |
83 | if set with charset, OpenConnection does a "SET NAMES..." with the given option (ie 'utf8mb4_unicode_ci'). ref: http://dev.mysql.com/doc/refman/5.7/en/charset-connection.html | |
84 | can be 'mysql' or 'mysqli' - the PHP extension to use for sql interaction | |
85 | recommended this is set to '+0:00'. empty will use system default time (not recommended). use hard numbers like '+0:00' cause timezone abbreviations must be defined in mysql otherwise, otherwise they may take no effect | |
101 | merge in options | |
102 | merge passed options with DefaultOptions | |
107 | set the db driver from options (mysql or mysqli) | |
111 | the rest of the options are our connection params | |
127 | default | |
149 | query MySQL to set client charset & collation. ref: http://dev.mysql.com/doc/refman/5.7/en/charset-connection.html | |
166 | $this->_server.$this->_user will be our encrypt key | |
174 | $this->_server.$this->_user will be our encrypt key | |
183 | doesn't do a mysql_select_db. good for creating databases and etc management | |
196 | -- mysql | |
200 | -- mysqli | |
201 | "new link" is created by default with mysqli | |
202 | persistent connections are special (to help avoid max_user_connections | |
203 | see http://php.net/manual/en/mysqli.persistconns.php - "To open a persistent connection you must prepend p: to the hostname when connecting." | |
205 | store active 'links' for each server/username combination for reuse | |
208 | no connection yet, create one and cache in static links array | |
211 | connect to database using cached link | |
223 | see if a charset is set (ie "utf8mb4"); | |
226 | get options | |
230 | -- mysql | |
231 | set PHP driver charset | |
234 | query MySQL to set client charset & collation. ref: http://dev.mysql.com/doc/refman/5.7/en/charset-connection.html | |
239 | -- mysqli | |
240 | set PHP driver charset | |
243 | query MySQL to set client charset & collation. ref: http://dev.mysql.com/doc/refman/5.7/en/charset-connection.html | |
262 | exception show's the password passed through the constructor. only use for debugging | |
264 | die("Bad arguments for DbManager constructor. Msg: ".$e->getMessage()); | |
277 | -- mysql | |
280 | -- mysqli | |
293 | if true, will immediately call mysql_select_db() with the database passed to this class | |
322 | -- mysql | |
325 | -- mysqli | |
339 | if true, does a SELECT DISTINCT for the select. Note: there must only be 1 select field, otherwise an exception is thrown | |
341 | if true, overwrites any other 'column-quotes' options (below) and will add column quotes to everything | |
342 | if true, automatically adds `quotes` around the `column names` in select fields | |
343 | if true, automatically adds `quotes` around the `column names` in the where clause | |
344 | if true, automatically adds `quotes` around the `column names` in the order clause | |
346 | if true, overwrites any other 'dot-notation' options (below) and will add dot notation to everything | |
347 | if true, automatically adds dot.notation before column names in select fields | |
348 | if true, automatically adds dot.notation before column names in the where clause | |
349 | if true, automatically adds dot.notation before column names in the order clause | |
351 | if true, numerics will always be quoted in the where clause (ie "WHERE `price`='123'" instead of "WHERE `price`=123"). NOTE- this is for reverse compatibility. only used if $table is a string and not a SmartTable object | |
352 | if true, will always call mysql_select_db() with the database passed to this class | |
371 | default to "SELECT * ..." | |
387 | extended options | |
391 | should handle $limit==0, which is invalid. | |
392 | matches "10" or "100,10". will incorrectly match "0", but "0,10" is correct. the if statement above should handle the "0" case though | |
409 | if true, overwrites any other 'column-quotes' options (below) and will add column quotes to everything | |
410 | if true, overwrites any other 'dot-notation' options (below) and will add dot notation to everything | |
411 | if true, will call mysql_select_db() with the database passed to this class | |
429 | Compile SQL fields | |
432 | save column name without quotes or dot notation | |
438 | Compile SQL values | |
441 | now() | |
462 | if true, overwrites any other 'column-quotes' options (below) and will add column quotes to everything | |
463 | if true, overwrites any other 'dot-notation' options (below) and will add dot notation to everything | |
464 | if true, will call mysql_select_db() with the database passed to this class | |
465 | if true, numerics will always be quoted in the where clause (ie ...WHERE `price`='123'... instead of ... WHERE `price`=123...). NOTE- this is for reverse compatibility. only used if $table is a string and not a SmartTable object | |
486 | save column name without quotes or dot notation | |
494 | now() | |
505 | extended options | |
525 | if true, overwrites any other 'column-quotes' options (below) and will add column quotes to everything | |
526 | if true, overwrites any other 'dot-notation' options (below) and will add dot notation to everything | |
527 | if true, will call mysql_select_db() with the database passed to this class | |
528 | if true, numerics will always be quoted in the where clause (ie ...WHERE `price`='123'... instead of ... WHERE `price`=123...). NOTE- this is for reverse compatibility. only used if $table is a string and not a SmartTable object | |
545 | extended options | |
565 | set to true if writing a query without dot notation (database.table.field) AND your app uses multiple databases with 1 connection (ie not using the 'new_link' flag on any database connection) | |
566 | if true, will skip any call to mysql_select_db. good for creating databases and etc management | |
567 | (NOT SUPPORTED WITH DRIVER 'mysql') - if true, will use mysqli_multi_query. use NextResult() to iterate through each query's result set. throws an exception on error | |
585 | reset vars | |
591 | lazy connect | |
593 | the reason for this else: if we just connected, database was just selected. no need to select it again here. | |
597 | -- mysql | |
598 | NOT SUPPORTED with mysql | |
603 | -- mysqli | |
612 | if last_result is false and there is no error, this could have been an insert. this is valid | |
618 | var_dump($query); | |
619 | var_dump($this->_connection); | |
621 | var_dump($this->_lastResult); | |
639 | -- mysql //NOT SUPPORTED with mysql | |
642 | -- mysqli | |
645 | no more results | |
653 | if last_result is false and there is no error, this could have been an insert. this is valid | |
663 | php.net/manual/en/mysqli.multi-query.php | |
669 | -- mysql //NOT SUPPORTED with mysql | |
670 | throw new Exception("NextResult(), FlushResults(), and 'multi-query' are not supported with driver 'mysql' (use mysqli)"); | |
673 | -- mysqli | |
684 | -- mysql | |
687 | -- mysqli | |
726 | so an empty array is returned if no rows are set. avoids "Warning: Invalid argument supplied for foreach()" | |
765 | so an empty array is returned if no rows are set. avoids "Warning: Invalid argument supplied for foreach()" | |
798 | -- mysql | |
801 | -- mysqli | |
828 | -- mysql | |
831 | -- mysqli | |
846 | -- mysql | |
849 | -- mysqli | |
861 | -- mysql | |
864 | -- mysqli | |
876 | -- mysql | |
879 | -- mysqli | |
896 | -- mysql | |
899 | -- mysqli | |
911 | TODO: get rid of this completely and disable magic quotes: http://www.php.net/manual/en/info.configuration.php#ini.magic-quotes-gpc | |
912 | if (get_magic_quotes_gpc()) { //DEPRECATED! will be removed in PHP 6 | |
913 | $string = stripslashes($string); | |
914 | } | |
918 | -- mysql | |
921 | -- mysqli | |
941 | $direction is actually the col name them because user input array like array("id","col1"); assume asc for cols | |
947 | else $colName = $colName; | |
970 | clean up val | |
973 | yes dot notation | |
974 | no dot notation, but yes column quotes | |
975 | no dot notation or column quotes | |
989 | get table name. if $table is not a string, it has to be a SmartTable object | |
1009 | if true, numerics will always be quoted in the where clause (ie ...WHERE `price`='123'... instead of ... WHERE `price`=123...). NOTE- this is for reverse compatibility. only used if $table is a string and not a SmartTable object | |
1026 | need to add an " AND " (or " OR ") in between clauses. see constructor options | |
1028 | force "AND" or "OR" | |
1056 | check if key is a condition | |
1059 | check if key is an operator | |
1062 | if the key is not a keyword and not numeric, it is assumed to be the column name | |
1066 | the value returned | |
1067 | $val can either be a scalar or an array | |
1068 | value is an array, recurse. | |
1072 | need to add an " AND " or " OR " in between clauses | |
1078 | wrap in parenthesis | |
1080 | $val is a scalar. this is the end of the recursion | |
1099 | the value returned | |
1100 | clean up field name | |
1104 | save column name without quotes or dot notation | |
1108 | else $column = $column; | |
1111 | null is special | |
1113 | 'is not null' for null | |
1115 | 'is null' for null | |
1117 | value is not null | |
1118 | SPECIAL CASES FOR "LIKE" CONDITION | |
1119 | See: http://stackoverflow.com/questions/3683746/escaping-mysql-wild-cards | |
1121 | to make sure we don't over-escape single quotes, we'll escape single quotes as "''" instead of "\'" | |
1122 | underscore ('_') is a wildcard in LIKE matching one character. need to escape it to match the actual underscore | |
1123 | see http://dev.mysql.com/doc/refman/5.1/en/string-literals.html | |
1126 | "To search for "\", specify it as "\\\\"; this is because the backslashes are stripped once by the | |
1127 | parser and again when the pattern match is made, leaving a single backslash to be matched against." | |
1128 | see http://dev.mysql.com/doc/refman/5.0/en/string-comparison-functions.html | |
1135 | HACK-ish: MySQL doesn't recognize NULL as '!=' a value or 'not like' a value. | |
1136 | so we have to force null checking for operators that negate. | |
1167 | match operator | |
1168 | match condition | |
1169 | no match | |
1182 | operators | |
1187 | no match | |
1201 | conditions | |
1212 | special conditions | |
1214 | special conditions | |
1217 | no match | |
1225 | for reverse compatibility. only used if $table is a string and not a SmartTable object | |
1236 | default options | |
1238 | overwrite $defaultOptions with any $options specified | |
1244 | HACKish - handle SmartCells in case someone accidentally forgets to call ->GetValue() on the smart cell | |
1249 | null is null | |
1254 | if $table is not a string, it has to be a SmartTable object. we can use this to get the column type | |
1257 | handle booleans. | |
1259 | boolean false is '\0'. make booleans default to 1 and 0 | |
1264 | get the column's data type to determine if the value should be quoted | |
1266 | $table is a SmartTable object | |
1268 | dont quote numbers | |
1285 | needs quotes. this data type stores binary strings that have no character set or collation (it is NOT strictly ones and zeros) | |
1286 | force binary to be 0 if nothing is set | |
1290 | quote non-numbers | |
1292 | false should evalute to empty string | |
1299 | notify us of the invalid column and table, but don't error out | |
1300 | trigger_error($e->getMessage(), E_USER_WARNING ); | |
1305 | if we get here, we dont have database structure info and need to try to best guess how quotes should be used (also for reverse compatibility) | |
1306 | note that the following will incorrectly not quote something like "053" or even "546t" for varchar fields, and 53 or 546 get used instead. | |
1307 | this is why a SmartDb is recommended for db structure info | |
1360 | table doesn't exist to drop | |
1367 | table still exists | |
1368 | table doesn't exist anymore | |
1380 | table doesn't exist to drop | |
1397 | database already exists | |
1406 | database wasn't created | |
1407 | database created | |
1417 | database doesn't exist to drop | |
1426 | database still exists | |
1427 | database doesn't exist anymore | |
1448 | default options | |
1455 | overwrite $defaultOptions with any $options specified | |
1460 | make sure the source database exists | |
1465 | drop the destination database if it already exists and $options['drop-existing-database']==true | |
1471 | create the destination database if it doesnt already exist | |
1477 | set our dbmanager to the $sourceDatabaseName so we can select the tables/data | |
1478 | we'll restore this after the copy operation | |
1481 | need to restore the database connection if something fails | |
1482 | get all table records in the source database | |
1486 | loop through all source table records | |
1490 | copy the structure of the table | |
1500 | copy the data with primary keys and indexes and etc | |
1506 | restore the database connection if something goes wrong | |
1511 | restore the database connection | |
1653 | ********************* password management ******************************** | |
1665 | pad with null characters |
Type | Line | Description |
---|---|---|
4 | www.phpsmartdb.com/ | |
8 | www.phpsmartdb.com/license | |
23 | ///////////////////////////// SERIALIZATION - At top so we don't forget to update these when we add new vars ////////////////////////// | |
50 | //////////////////////////////////////////////////////////////////////////////////// | |
72 | default to false | |
90 | ///////////////////////////// Table Structure /////////////////////////////////// | |
91 | Key is the column name, Value is the Column instance. | |
92 | Key is the column alias name, value is the actual column name | |
94 | computed from $this->_columns | |
95 | computed from $this->_columns | |
96 | computed from $this->_columns | |
97 | computed from $this->_columns | |
99 | key is the function name, value is the DbManager results to cache | |
222 | clear column aliases | |
239 | handle columns with aliases | |
257 | a little error checking to make sure the structure checks out | |
262 | ///////////////////////////// Column Management /////////////////////////////////// | |
274 | make $this table the column's table | |
275 | save this column with the column name as key | |
289 | the actual column exists | |
292 | a column alias exists | |
311 | $this table is no longer the column's table | |
326 | ///////////////////////////// Table Inheritance /////////////////////////////////// | |
358 | already inherited | |
363 | clone so when AddColumn() changes the Table of the Column, it doesnt affect the original Column's Table reference | |
364 | false so we don't replace existing columns. Need this for table inheritance since the regular columns are added first, then the inherited columns. dont want to replace a regular column wiht an inherited one | |
366 | inherit relations from $Column | |
368 | this column has relations | |
369 | add a relation between this table and the original table | |
371 | add relation between this table and the inherited columns that were set from the original table | |
380 | ///////////////////////////// Invoke /////////////////////////////////// | |
396 | ///////////////////////////// ArrayAccess /////////////////////////////////// | |
425 | ///////////////////////////// Countable /////////////////////////////////// | |
436 | ///////////////////////////// Table Data Functions /////////////////////////////////// | |
438 | used internally to track max depth of the lookupAssoc in VerifyLookupAssoc() | |
448 | INTERNAL GLOBAL! this is determined within VerifyLookupAssocHelper | |
459 | This extra array wrapping can be ignored once we are sure the DbManager will always AND by default for multi-elements within the first dimension of lookup arrays | |
460 | not a multi-dimension array... wrap another array around this one so we AND by default instead of OR (as the DbManager does for backwards compatibility) | |
461 | extra array needed for the backwards compatibility within DbManager | |
472 | track array's depth internally | |
475 | verify $key is numeric, a column name, or a keyword (ie "AND", "OR", "<", "!=", etc) | |
476 | not numeric. must be a column or a keyword | |
479 | save to recurse | |
482 | save to recurse | |
484 | not keyword, must be column | |
487 | check aliases | |
488 | save to recurse | |
489 | gets the real column name in case the $key is a column alias | |
490 | if these are different, we have a column alias | |
491 | transfer alias lookup settings to the actual column | |
493 | unset alias | |
498 | hack for MySQL database | |
499 | 'SET' data type needs some special data handling for where clauses | |
500 | ex: "$lookupAssoc = ['AND'=>['a','c']]" should give us "...WHERE set = 'a,c'" and not "...WHERE set = 'a' AND set = 'c'" | |
501 | ex: "$lookupAssoc = ['OR'=>['!='=>['a','c']]]" should give us "...WHERE set != 'a,c'" and not "...WHERE set != 'a' AND set != 'c'" | |
502 | ex: "$lookupAssoc = ['LIKE'=>['OR'=>'b,a']] should give us "...WHERE set LIKE '%a%' OR set LIKE '%b%'" | |
503 | TODO: MOVE THIS INTO MySQL DB MANAGER??? Is this considered database specific...? Or maybe just an "if(mysql){" statement around this logic here. | |
504 | The MySQL Db manager has no knowledge over column data types, and this case only applies to SETs. | |
507 | look for a sub-array. if none, this particular array is the set of "AND" and "=" values we need to match. | |
511 | key could be numeric or a keyword | |
516 | value could be an array to recurse on or a CSV of SET values. if either, we need to recurse | |
517 | recurse? | |
521 | if subVal is a CSV of values... | |
522 | convert CSV to an array so we can recurse as normal | |
531 | combine array of values into a CSV for this edge case | |
534 | $val will go through VerifyValueType() below to handle sorting and etc. needed for MySQL also | |
537 | data handling | |
538 | recurse? | |
544 | the actual lookup value. normalize data, based on column data type | |
547 | don't convert serialized objects/arrays so we can do raw string comparisons | |
551 | hack for MySQL database | |
552 | 'SET' data type needs some special data handling for where clauses for "LIKE" to work with sets | |
553 | where we need to put the mysql wildcard '%' around all strings. | |
554 | mysql stores sets as CSV in the database and does basic string searching in WHERE clauses | |
555 | to see if a particular value is within the set *along with* other values (ie: "...WHERE set LIKE '%a%,%c%';" to match 'a,b,c,d' set data) | |
556 | TODO: MOVE THIS INTO MySQL DB MANAGER??? Is this considered database specific...? Or maybe just an "if(mysql){" statement around this logic here. | |
557 | The MySQL Db manager has no knowledge over column data types, and this case only applies to SETs. | |
579 | check that the 'return-next-row' option is set | |
581 | option not not set | |
584 | verify the 'return-next-row' option is passed by reference. it MUST be | |
587 | copy options array and test if the 'return-next-row' is passed by reference | |
590 | not passed by reference | |
594 | 'return-next-row' is passed by reference. | |
595 | restore the original return-next-row option. | |
596 | make sure the original is an int | |
597 | if $curVal is >0 here, then we're returning the NEXT row and should have a cached dbmanager to use | |
598 | no cached dbmanager? assume this is the first call and we should return the first row of the result set | |
611 | Either a string of the column to sort ASC by, or an assoc array of "ColumnName"=>"ASC"|"DESC" to sort by. An exception will be thrown if a column does not exist. | |
612 | function - if set, this function will be invoked for each row and the full result set will NOT be returned- only the LAST ROW in the set will be returned (if there is one). the function's signature should be function($row, $i){} where $row is the actual SmartRow, and $i is the 1-based index of the row being returned | |
613 | if true, the returned assoc-array will have the row's primary key column value as its key (if a non-composite primary key exists on the table. otherwise this option is ignored) and the Row instance as its value. ie array("2"=>$row,...) instead of just array($row,...); | |
614 | OUT variable. integer. if you set this parameter in the $options array, then this function will return only 1 row of the result set at a time. If there are no rows selected or left to iterate over, null is returned. | |
615 | THIS PARAMETER MUST BE PASSED BY REFERENCE - i.e. array( "return-next-row" => &$curCount ) - the incoming value of this parameter doesn't matter and will be overwritten) | |
616 | After this function is executed, this OUT variable will be set with the number of rows that have been returned thus far. | |
617 | Each consecutive call to this function with the 'return-next-row' option set will return the next row in the result set, and also increment the 'return-next-row' variable to the number of rows that have been returned thus far | |
618 | With one argument (ie $limit="10"), the value specifies the number of rows to return from the beginning of the result set | |
619 | With two arguments (ie $limit="100,10"), the first argument specifies the offset of the first row to return, and the second specifies the maximum number of rows to return. The offset of the initial row is 0 (not 1): | |
620 | OUT variable only. integer. after this function is executed, this variable will be set with the number of rows being returned. Usage ex: array('return-count'=>&$count) | |
621 | if true, the return-count will be returned instead of the rows. A good optimization if you dont need to read any data from the rows and just need the rowcount of the search | |
634 | table must have a single primary key column | |
639 | get DbManager we need to use. could be a stored result set if $returnNextRow > 0 | |
643 | check for the 'return-next-row' option to return 1 row at a time | |
644 | returns INT >= 0 or FALSE | |
646 | check the 'callback' option | |
649 | verify we have an anonymous function or a function name in global scope | |
653 | do the query if we're not returning the next row from our result set | |
654 | spelling out both cases for clarity - $returnNextRow could be 0 or false here. both should run the new query | |
655 | clear any cached result sets we may have | |
660 | $lookupAssoc is not required. if no $lookupAssoc is given, this will be identical to GetAllRows(). | |
665 | do the new query | |
671 | check the 'return-count-only' option | |
675 | fetch SQL results | |
676 | specifically check for FALSE here (zero is valid for returning the 1st row of the set) | |
677 | if we're returning the first row of a result set, we need to store this particular result dbmanager to iterate over later, so clone our current DbManager and save it to this Table object | |
682 | return just a single result at a time from the stored DbManager's result set | |
683 | just 1 row. | |
684 | no more rows to fetch in this result set | |
686 | track the number of records we've returned | |
688 | take SQL results and return SmartRows | |
691 | callback? | |
693 | call the user's function | |
703 | if we're returning one row at a time, we need to store this particular result dbmanager to iterate over later, so clone our current DbManager and save it to this Table object | |
706 | get row | |
710 | call the user's function | |
714 | clear cached result sets we may have | |
715 | clear any cached result sets we may have | |
722 | 'return-next-row' option is not set. return array of all results | |
723 | get an array of all of the rows | |
725 | take SQL results and return SmartRows | |
732 | take SQL results and return SmartRows | |
735 | specifically check for FALSE here (zero is valid for returning the 1st row of the set) | |
736 | return only a single row at a time | |
739 | return all rows as an assoc array with row-key as array-key | |
744 | return all rows pushed onto an array | |
754 | specifically check for FALSE here (zero is valid for returning the 1st row of the set) | |
755 | return only a single row at a time | |
758 | return all rows as an assoc array with row-key as array-key | |
763 | return all rows pushed onto an array | |
785 | handle $lookupVals as a non-array... only works if column is a non-composite primary key | |
786 | NON-ARRAY. special case where $lookupVals is just the key column value | |
798 | table must have a single primary key column | |
810 | match | |
822 | no match. return a new instance with this value set. | |
833 | try to set the column values to what was looked up since the row was not found | |
834 | force disable commit changes immediately in this case | |
838 | filter column names in the lookup assoc | |
844 | set values on the row to be returned | |
852 | set commit changes immediately back to its old value | |
872 | if the key is not a keyword and not numeric, it is assumed to be the column name | |
874 | check if key is a condition | |
878 | check if key is an operator | |
882 | if the key is not a keyword and not numeric, it is assumed to be the column name | |
886 | $val can either be a scalar or an array | |
887 | value is an array, recurse. | |
892 | $val is a scalar. this is the end of the recursion | |
893 | clean up field name | |
896 | only track columns with an '=' condition and columns that are not defined multiple times | |
901 | hopefully this is unique enough :) | |
906 | on final pass, remove any ___ignore___ columns | |
918 | Either a string of the column to sort ASC by, or an assoc array of "ColumnName"=>"ASC"|"DESC" to sort by. An exception will be thrown if a column does not exist. | |
919 | If true, only unique values will be returned. Note: array keys in the returned array will NOT be the key column when this is true) | |
920 | if true, the returned assoc-array will have the row's primary key column value as its key (if a non-composite primary key exists on the table. otherwise this option is ignored) and the $returnColumn's value as its value. ie array("2"=>$returnColumnValue,...) instead of just array($returnColumnValue,...); | |
921 | With one argument (ie $limit="10"), the value specifies the number of rows to return from the beginning of the result set | |
922 | With two arguments (ie $limit="100,10"), the first argument specifies the offset of the first row to return, and the second specifies the maximum number of rows to return. The offset of the initial row is 0 (not 1): | |
923 | OUT variable only. integer. after this function is executed, this variable will be set with the number of values being returned. Usage ex: array('return-count'=>&$count) | |
924 | if true, the return-count will be returned instead of the rows. A good optimization if you dont need to read any data from the rows and just need the rowcount of the search | |
933 | reverse-compatibility: $lookupAssoc used to be first parameter, then $returnColumn was second. handle both situations | |
934 | if this is true "$returnColumn" is actually "$lookupAssoc" (reverse compatibility). need to swap these parameters | |
935 | tmp store the actual $returnColumn (in $lookupAssoc) so we can overwrite $lookupAssoc | |
936 | overwrite $lookupAssoc to be the actual lookup array | |
937 | overwrite $returnColumn with the actual column | |
942 | column may be an alias and/or may need to unserialize the returned data. get the actual column and check if it's serialized | |
944 | override $returnColumn name. handles aliases | |
946 | $lookupAssoc is not required. if no $lookupAssoc is given, this will work similar to SmartColumn->GetAllValues(). | |
958 | table must have a single primary key column | |
965 | check the 'return-count-only' option | |
968 | return an assoc array | |
971 | depending on the column's data type, we may need to normalize the raw database value for everyday use | |
975 | return a regular array | |
978 | depending on the column's data type, we may need to normalize the raw database value for everyday use | |
983 | no primary key or returning UNIQUE results only | |
987 | check the 'return-count-only' option | |
992 | depending on the column's data type, we may need to normalize the raw database value for everyday use | |
1008 | row not found | |
1023 | If true, all row-level "Delete" callbacks will be skipped. This can substantially improve the performance of very large bulk deletions. | |
1037 | skipping delete callbacks on the row-level will delete rows directly on the DB level for efficiency | |
1038 | yes, skip callbacks. faster. | |
1039 | handle $lookupAssoc as a non-array... only works if column is a non-composite primary key | |
1040 | NON-ARRAY. special case where $lookupAssoc is just the key column value | |
1050 | make sure we're only looking up with key/unique columns | |
1065 | dont skip callbacks. need to lookup the row and delete the row directly. slower than the above | |
1067 | 1 row deleted | |
1068 | 0 rows deleted | |
1078 | If true, all row-level "Delete" callbacks will be skipped. This can substantially improve the performance of very large bulk deletions. | |
1090 | skipping delete callbacks on the row-level will delete rows directly on the DB level for efficiency | |
1091 | yes, skip callbacks. faster. | |
1098 | dont skip callbacks. need to lookup each row and delete each row directly. slower than the above | |
1101 | delete row and increase count if successful | |
1114 | If true, all row-level "Delete" callbacks will be skipped. This can substantially improve the performance of very large bulk deletions. | |
1125 | skipping delete callbacks on the row-level will delete rows directly on the DB level for efficiency | |
1126 | yes, skip callbacks. faster. | |
1131 | dont skip callbacks. need to lookup each row and delete each row directly. slower than the above | |
1134 | delete row and increase count if successful | |
1146 | Either a string of the column to sort ASC by, or an assoc array of "ColumnName"=>"ASC"|"DESC" to sort by. An exception will be thrown if a column does not exist. | |
1147 | function - if set, this function will be invoked for each row and the full result set will NOT be returned- only the LAST ROW in the set will be returned (if there is one). the function's signature should be function($row, $i){} where $row is the actual SmartRow, and $i is the 1-based index of the row being returned | |
1148 | if true, the returned assoc-array will have the row's primary key column value as its key and the row as its value. ie array("2"=>$row,...) instead of just array($row,...); | |
1149 | OUT variable. integer. if you set this parameter in the $options array, then this function will return only 1 row of the result set at a time. If there are no rows selected or left to iterate over, null is returned. | |
1150 | THIS PARAMETER MUST BE PASSED BY REFERENCE - i.e. array( "return-next-row" => &$curCount ) - the incoming value of this parameter doesn't matter and will be overwritten) | |
1151 | After this function is executed, this OUT variable will be set with the number of rows that have been returned thus far. | |
1152 | Each consecutive call to this function with the 'return-next-row' option set will return the next row in the result set, and also increment the 'return-next-row' variable to the number of rows that have been returned thus far | |
1153 | With one argument (ie $limit="10"), the value specifies the number of rows to return from the beginning of the result set | |
1154 | With two arguments (ie $limit="100,10"), the first argument specifies the offset of the first row to return, and the second specifies the maximum number of rows to return. The offset of the initial row is 0 (not 1): | |
1155 | OUT variable only. integer. after this function is executed, this variable will be set with the number of rows being returned. Usage ex: array('return-count'=>&$count) | |
1156 | if true, the return-count will be returned instead of the rows. A good optimization if you dont need to read any data from the rows and just need the rowcount of the search | |
1187 | //////////////////////// PRIVATE HELPER CLASSES ////////////////////////// | |
1198 | $key is column name. 'asc' or 'desc' is the $val | |
1202 | default | |
1205 | $val is column name ($key is nothing). default to 'asc' | |
1207 | default | |
1210 | column exists | |
1211 | column may be an alias. get the actual column name | |
1213 | override $sortBy name with actual name | |
1215 | set final sort val | |
1223 | use a string as a single column name to sort by | |
1225 | default for a single string column | |
1226 | column exists. default to ASC | |
1227 | column may be an alias. get the actual column name | |
1229 | override $sortBy name with actual name | |
1231 | set final sort val | |
1242 | ///////////////////////////// ERROR ON INVALID FUNCTIONS/VARS ////////////////////////// | |
1264 | end class | |
TODO | 1165 | Make all tables work with this function |
Type | Line | Description |
---|---|---|
4 | www.phpsmartdb.com/ | |
8 | www.phpsmartdb.com/license | |
31 | implement custom functionality using $this | |
33 | ---------- START EXAMPLE CUSTOM FUNCTIONALITY ------------// | |
34 | formats an alpha-numeric "Price" column | |
35 | if we have any alpha characters, return the price as is. otherwise, we'll format it up (i.e. could return "$12.43" or "CALL FOR PRICE") | |
37 | $this is the current SmartRow instance, containing our row data for/from the database | |
46 | helper function - turns something like "$12,300.50" or "$12300.50" or "12300.50" into "12300.5", which can then be formatted exactly as needed. | |
50 | ---------- END EXAMPLE CUSTOM FUNCTIONALITY ------------// | |
58 | There are 2 signatures for this (which allows for extending on this class, but using a different table) | |
59 | 1. __construct($Database, $keyColumnValues=null, $options=null) //uses table "YOUR_TABLE_NAME" | |
60 | 2. __construct($tableName, $Database, $keyColumnValues=null, $options=null) //uses table $tableName | |
65 | implement custom functionality using $this | |
79 | ///////////////////////////// SERIALIZATION - At top so we don't forget to update these when we add new vars ////////////////////////// | |
109 | //////////////////////////////////////////////////////////////////////////////////// | |
126 | Key is the column name, value is the Cell instance. | |
128 | true when changes need to be committed to the database | |
129 | true when this instance represents a row that exists in the database; false if this row is not yet in the database | |
130 | true if initial column values have been pulled from the database (if the row exist in the database. if it does not, this bool will be false) | |
146 | if set to false, the default values will not be set on any Cell of the new row | |
159 | save the Database | |
160 | save the dbManager for easy access | |
163 | initialize all Cells of this row | |
168 | this column has a default value | |
173 | handle $keyColumnValues that may have been passed through | |
175 | ARRAY | |
183 | 1 NON-ARRAY | |
247 | no exception on error | |
257 | If true: does not validate the key columns. If false: validates all columns | |
258 | If true: only cells that have been set (i.e. isset()==true) will be verified (not recommended if this info will be committed to db). If false: all cells will be verified (should be used if this info will be committed to db). | |
259 | appended to each error message | |
267 | default options | |
270 | overwrite $defaultOptions with any $options specified | |
287 | If true: does not validate the key columns. If false: validates all columns | |
288 | If true: only cells that have been set (i.e. isset()==true) will be verified (not recommended if this info will be committed to db). If false: all cells will be verified (should be used if this info will be committed to db). | |
320 | the actual column exists | |
325 | a column alias exists | |
396 | true if changes have been made to the key from what was previously defined before calling this function | |
399 | only working with NON auto-increment key columns | |
402 | get the passed value... either with the real column name or the first found alias (ignores multiple matches) | |
405 | compare the passed key value to the current key value | |
413 | only working with NON auto-increment key columns | |
419 | check if this new key already exists in database | |
420 | build the where clause array | |
422 | only working with NON auto-increment key columns | |
423 | get the passed value... either with the real column name or the first found alias (ignores multiple matches) | |
433 | a row with this key already exists | |
437 | delete old row from database with old key from before calling this method | |
441 | set new key columns | |
442 | only working with NON auto-increment key columns | |
445 | get the passed value... either with the real column name or the first found alias (ignores multiple matches) | |
454 | automatically commit changes now? | |
467 | get the passed value... either with the real column name or first found alias (ignores multiple matches) | |
468 | real column name | |
471 | check aliased columns | |
477 | real column name | |
499 | info must be setup as $assocArray = array('TableName'=>array('ColumnName1'=>value, ...)) | |
503 | check real columns | |
509 | real columns | |
512 | real column notifier | |
513 | notifier let us know this column was in use on the page, but as a checkbox, its POST does not get sent if the checkbox is not checked. so set the 'not checked' value | |
515 | check column alias only as a last resort if the real column name was not found | |
518 | aliased column | |
521 | aliased column notifier | |
522 | notifier let us know this column was in use on the page, but as a checkbox, its POST does not get sent if the checkbox is not checked. so set the 'not checked' value | |
554 | for reverse compatibility. the $options variable used to be a variable for $onlyAddSetColumns. false by default. | |
571 | for reverse compatibility. the $options variable used to be a variable for $onlyAddSetColumns. false by default. | |
588 | If false, populates the provided assoc-array with ALL get-able key columns. If true, populates the provided assoc-array with only the get-able columns that have been set (i.e. isset()==true) | |
589 | if true, key columns are returned in the array. if false, key columns are not returned in the array | |
590 | if true, non-key columns are returned in the array. if false, non-key columns are not returned in the array | |
591 | set this to auto-format date columns. ref formarts that work with php's date() function (http://php.net/date) | |
599 | for reverse compatibility. the $options variable used to be a variable for $onlyAddSetColumns. false by default. | |
603 | default options | |
606 | set this to auto-format date columns. ref formarts that work with php's date() function (http://php.net/date) | |
608 | overwrite $defaultOptions with any $options specified | |
618 | ignore key columns | |
619 | ignore non-key columns | |
621 | normalize dates? | |
623 | true so value goes through strtotime() | |
624 | strtotime could have failed to parse for some reason | |
625 | using "date()" instead of "gmdate()" will return timestamp in whatever LOCAL time in, so be sure to include a timezone indicator in the date format | |
631 | do not normalize dates | |
647 | Either a string of the column to sort ASC by, or an assoc array of "ColumnName"=>"ASC"|"DESC" to sort by. An exception will be thrown if a column does not exist. | |
648 | With one argument (ie $limit="10"), the value specifies the number of rows to return from the beginning of the result set | |
649 | With two arguments (ie $limit="100,10"), the first argument specifies the offset of the first row to return, and the second specifies the maximum number of rows to return. The offset of the initial row is 0 (not 1): | |
650 | OUT variable only. integer. after this function is executed, this variable will be set with the number of values being returned. Usage ex: array('return-count'=>&$count) | |
651 | if true, the return-count will be returned instead of the rows. A good optimization if you dont need to read any data from the rows and just need the rowcount of the search | |
683 | 1 row found | |
686 | check if the 1 found row has the same key as $this row | |
695 | different row. update this $row with the data from the database | |
708 | check the 'return-count-only' option | |
713 | num or rows selected != 1 | |
714 | check the 'return-count-only' option | |
732 | get the extended version of the class if exists | |
735 | the extended version doesnt exist or is not in scope, so just return the Base class | |
745 | ///////////////////////////// The Major Row-To-Database Communications /////////////////////////////////// | |
755 | this row/table has no key columns, so nothing to look up | |
759 | some sort of primary key exists | |
760 | make sure every primary key is set. if not, do not query the database | |
762 | if key is not set, don't lookup row | |
766 | primary key is not yet set in this row/table, so nothing is in the database to get. | |
773 | primary key is set in this row/table, so get the record from the database that matches this primary key | |
782 | successfully got matching row from database table | |
789 | value coming out of DB does not have timezone by default. it will assume LOCAL time unless specified. | |
798 | matching row not found in database table | |
799 | primary key is auto-increment | |
806 | primary key is not auto-increment | |
829 | row is not in database yet. insert a new row | |
830 | event could be cancelled. make sure this is 0 at this point for our return value | |
834 | returns number of rows inserted. should be 1 on success, 0 on fail (or TRUE/FALSE) | |
840 | row exists in database. Update it | |
841 | nothing to commit | |
843 | event could be cancelled. make sure this is 0 at this point for our return value | |
862 | all changes have been written to database. not dirty anymore | |
877 | build arrays | |
908 | error inserting new column into database | |
911 | todo: handle this nicely? | |
914 | successfuly inserted column. set the new column unique key value | |
917 | primary key now has an id that was chosen by auto_increment in database | |
920 | no primary key or primary key exists and is composite or non-autoincrement | |
921 | todo: handle this nicely? | |
935 | only delete if a key column is defined | |
938 | not initialized yet. need to initialize to see if this row exists in database | |
939 | row does not exist to delete | |
963 | if 0 rows deleted, row still exists in database. this typically should not happen | |
964 | if the row still exists in the database, the isDirty status will not have changed. otherwise the row doesnt exist, so not dirty | |
966 | clear the values of auto-increment key columns | |
977 | ///////////////////////////// ArrayAccess /////////////////////////////////// | |
1015 | ///////////////////////////// JsonSerializable /////////////////////////////////// | |
1025 | ///////////////////////////// TO STRING /////////////////////////////////// | |
1080 | $str .= $this->InputValidation->ToString(); | |
1084 | //////////////////////////// INTERNAL CALLBACKS ////////////////////////////// | |
1093 | automatically commit changes now? | |
1096 | ///////////////////////////// PUBLIC CALLBACKS /////////////////////////////////// | |
1128 | row callback arrays | |
1129 | callbacks to be fired before the row has been committed to database (can be insert or update) | |
1130 | callbacks to be fired after the row has been committed to database (can be insert or update) | |
1131 | callbacks to be fired before the has been insertted to database (doesnt include update) | |
1132 | callbacks to be fired after the row has been insertted to database (doesnt include update) | |
1133 | callbacks to be fired before the row has been updated to database (doesnt include insert) | |
1134 | callbacks to be fired after the row has been updated to database (doesnt include insert) | |
1135 | callbacks to be fired before the row has been deleted from database | |
1136 | callbacks to be fired after the row has been deleted from database | |
1138 | callbacks to be fired before any Cell of this row has been set | |
1139 | callbacks to be fired before any Cell of this row has been set | |
1140 | callbacks to be fired after any Cell of this row has been set | |
1148 | no callbacks defined or callbacks disabled | |
1151 | pass $this->Row reference back through to the callback | |
1165 | setting 'cancel-event' to true within your $callbackFunction will prevent the event from continuing | |
1209 | setting 'cancel-event' to true within your $callbackFunction will prevent the event from continuing | |
1253 | setting 'cancel-event' to true within your $callbackFunction will prevent the event from continuing | |
1297 | setting 'cancel-event' to true within your $callbackFunction will prevent the event from continuing | |
1334 | /////// Cell callbacks ///////// | |
1371 | setting 'cancel-event' to true within your $callbackFunction will prevent the event from continuing | |
1372 | the Cell that fired the event (Cell's contain all Column functionality and properties) | |
1373 | the current value of this column, BEFORE it has changed to 'new-value' | |
1374 | the value that this column is going to be set to, replacing the 'current-value' | |
1389 | verify we have an anonymous function or a function name in global scope | |
1417 | setting 'cancel-event' to true within your $callbackFunction will prevent the event from continuing | |
1418 | the Cell that fired the event | |
1419 | the current value of this column, BEFORE it has changed to 'new-value' | |
1420 | the value that this column is going to be set to, replacing the 'current-value' | |
1435 | verify we have an anonymous function or a function name in global scope | |
1462 | the Cell that fired the event | |
1463 | the current value of this column, AFTER it has been changed from 'old-value' | |
1464 | the value that this column was set to before it was updated with the 'current-value' | |
1479 | verify we have an anonymous function or a function name in global scope | |
1498 | ///////////////////////////// ERROR ON INVALID FUNCTIONS/VARS ////////////////////////// | |
1521 | end class | |
TODO | 753 | add comments that explain what happens if no primary key exists |
Type | Line | Description |
---|---|---|
4 | www.phpsmartdb.com/ | |
8 | www.phpsmartdb.com/license | |
19 | ///////////////////////////// SERIALIZATION - At top so we don't forget to update these when we add new vars ////////////////////////// | |
62 | //////////////////////////////////////////////////////////////////////////////////// | |
104 | php.net/manual/en/timezones.php | |
139 | MaxSize is something like (14,4) for decimals. first number is precision, second number is scale | |
141 | add 1 for a decimal point | |
240 | ///////////////////////////// Column Relations /////////////////////////////////// | |
269 | set relation on $this column | |
272 | set relation on related column | |
295 | unset relation on related column | |
316 | make sure $columnName isnt an alias | |
317 | gets the real name of the column if $columnName is an alias | |
322 | ///////////////////////////// Column Aliases /////////////////////////////////// | |
334 | if true, the returned array will just be an array of alias names | |
358 | set relation on $this column | |
392 | ///////////////////////////// Column Data Functions /////////////////////////////////// | |
407 | may need to transform the value to it's original type for array and object types | |
412 | 'set' type is CSV internally, but we work with arrays | |
413 | empty array if not set | |
417 | is a date column | |
419 | match. special check for "0000-00-00...". different OS's and PHP versions handle strtotim("0000-00-00 00:00:00") differently | |
425 | is a timezone column | |
434 | is a date column | |
436 | check for a default timezone | |
437 | if value is set... | |
438 | column level defaults take precedence over database level, if both defaults are set. | |
441 | always stored as UTC when timezone in use | |
442 | convert to that timezone | |
455 | Either a string of the column to sort ASC by, or an assoc array of "ColumnName"=>"ASC"|"DESC" to sort by. An exception will be thrown if a column does not exist. | |
456 | If true, only unique values will be returned. Note: array keys in the returned array will NOT be the key column when this is true) | |
457 | if true, the returned assoc-array will have the row's primary key column value as its key and the row as its value. ie array("2"=>$row,...) instead of just array($row,...); | |
458 | With one argument (ie $limit="10"), the value specifies the number of rows to return from the beginning of the result set | |
459 | With two arguments (ie $limit="100,10"), the first argument specifies the offset of the first row to return, and the second specifies the maximum number of rows to return. The offset of the initial row is 0 (not 1): | |
460 | OUT variable only. integer. after this function is executed, this variable will be set with the number of values being returned. Usage ex: array('return-count'=>&$count) | |
461 | if true, the return-count will be returned instead of the rows. A good optimization if you dont need to read any data from the rows and just need the rowcount of the search. | |
507 | MySQL reference - http://dev.mysql.com/doc/refman/5.0/en/group-by-functions.html | |
520 | make sure lookup assoc is valid, if given | |
527 | todo- move aggregate functions to DbManager somehow | |
535 | may need to normalize the raw data for use. depends on the column's data type (mostly dates, in this case) | |
548 | Either a string of the column to sort ASC by, or an assoc array of "ColumnName"=>"ASC"|"DESC" to sort by. An exception will be thrown if a column does not exist. | |
549 | if true, the returned assoc-array will have the row's primary key column value as its key and the row as its value. ie array("2"=>$row,...) instead of just array($row,...); | |
550 | function - if set, this function will be invoked for each row and the full result set will NOT be returned- only the LAST ROW in the set will be returned (if there is one). the function's signature should be function($row, $i){} where $row is the actual SmartRow, and $i is the 1-based index of the row being returned | |
551 | OUT variable. integer. if you set this parameter in the $options array, then this function will return only 1 row of the result set at a time. If there are no rows selected or left to iterate over, null is returned. | |
552 | THIS PARAMETER MUST BE PASSED BY REFERENCE - i.e. array( "return-next-row" => &$curCount ) - the incoming value of this parameter doesn't matter and will be overwritten) | |
553 | After this function is executed, this OUT variable will be set with the number of rows that have been returned thus far. | |
554 | Each consecutive call to this function with the 'return-next-row' option set will return the next row in the result set, and also increment the 'return-next-row' variable to the number of rows that have been returned thus far | |
555 | With one argument (ie $limit="10"), the value specifies the number of rows to return from the beginning of the result set | |
556 | With two arguments (ie $limit="100,10"), the first argument specifies the offset of the first row to return, and the second specifies the maximum number of rows to return. The offset of the initial row is 0 (not 1): | |
557 | OUT variable only. integer. after this function is executed, this variable will be set with the number of rows being returned. Usage ex: array('return-count'=>&$count) | |
558 | if true, the return-count will be returned instead of the rows. A good optimization if you dont need to read any data from the rows and just need the rowcount of the search. | |
568 | normalize serialized data | |
594 | normalize serialized data | |
615 | If true, all row-level "Delete" callbacks will be skipped. This can substantially improve the performance of very large bulk deletions. | |
623 | skipping delete callbacks on the row-level will delete rows directly on the DB level for efficiency | |
624 | yes, skip callbacks. faster. | |
628 | normalize serialized data | |
633 | dont skip callbacks. need to lookup each row and delete each row directly. slower than the above | |
636 | delete row and increase count if successful | |
657 | If true, all row-level callbacks AND error-checking will be skipped. This can substantially improve the performance on very large tables. | |
658 | Only available in conjunction with 'skip-callbacks'=true. If both of these options are true, all row-level error checking will be skipped when each updated Row is Commit()'ed. | |
668 | skipping callbacks on the row-level will update rows directly on the DB level for efficiency | |
669 | yes, skip callbacks. faster. | |
673 | normalize serialized data | |
678 | dont skip callbacks. need to lookup each row and update each row directly. slower than the above | |
682 | update row and increase count if successful | |
683 | note: this will call VerifyValueType(), so no need to here. | |
691 | ///////////////////////////// Data Normalization /////////////////////////////////// | |
697 | If true, serialized data will be left as-is (i.e. for using strings in lookup assocs) | |
698 | if true, SET data is returned as a CSV. SmartDb uses a CSV internally, as MySQL does basically. | |
707 | handle special type conversions | |
708 | development mode | |
709 | convert objects to strings if the column type is not an object | |
721 | "set" can be an array of all selected values, or a csv of selected values | |
726 | production mode | |
727 | convert objects to strings if the column type is not an object | |
732 | null is null. let it go | |
735 | handle booleans. | |
737 | boolean false is '\0'. make booleans default to 1 and 0 | |
742 | handle date columns | |
743 | can be a string of a date format or an int timestamp value since 1970 | |
746 | match. special check for "0000-00-00...". different OS's and PHP versions handle strtotim("0000-00-00 00:00:00") differently | |
751 | value is set. if a timezone is in use, use gmdate(). otherwise use date() | |
752 | "date" DataType has a slightly different format than other DateColumns | |
756 | column level defaults take precedence over database level, if both defaults are set. | |
758 | a timezone is in use, always store a gmdate (not system time) | |
759 | if value is int and < 100000000, we'll assume it's not a raw timestamp (100000000 puts us in 1970s somewhere) | |
761 | strtotime( <int> ) returns false. if <int> data type, we assume $value is the raw timestamp value we should use, and skip strtotime | |
764 | try to parse string. might return false if invalid | |
766 | invalid date format | |
770 | parsed successfully | |
775 | no timezone in use, use date (system time) | |
776 | if value is int and < 100000000, we'll assume it's not a raw timestamp (100000000 puts us in 1970s somewhere) | |
778 | strtotime( <int> ) returns false. if <int> data type, we assume $value is the raw timestamp value we should use, and skip strtotime | |
784 | must set to null since there is no "0" date (i.e. TIMESTAMP has a range of '1970-01-01 00:00:01' UTC to '2038-01-19 03:14:07' UTC) | |
789 | set needs to be sorted accordingly (for mysql WHERE clauses) | |
790 | also if $value is an array, make it a CSV | |
796 | strongly type the data | |
798 | dont quote numbers | |
804 | trim leading $ before the hard cast to int (PHP will cast something like "$3.50" to 0 otherwise) | |
805 | regular whitespace trim PLUS dollar sign. ref: http://php.net/manual/en/function.trim.php | |
814 | trim leading $ before the hard cast to float (PHP will cast something like "$3.50" to 0 otherwise) | |
815 | regular whitespace trim PLUS dollar sign. ref: http://php.net/manual/en/function.trim.php | |
821 | needs quotes. this data type stores binary strings that have no character set or collation (it is NOT strictly ones and zeros) | |
822 | force binary to be 0 if nothing is set | |
826 | case 'set': | |
827 | handled above since we already have a bool if this is true | |
842 | false should evalute to empty string | |
850 | ///////////////////////////// Serialize/Unserialize Array/Object functions /////////////////////////////////// | |
893 | force null if nothing is set. note, this includes an empty array | |
894 | verify array type | |
895 | not an array, though it may already be serialized. test it | |
896 | returns false if not serialized | |
897 | not valid array or serizlied array | |
898 | make the given $array valid. return the passed value as the only item in the serialized array | |
911 | force null if nothing is set | |
912 | verify object type | |
913 | not an object, though it may already be serialized. test it | |
914 | returns false if not serialized | |
915 | not valid object or serizlied object | |
929 | return empty array always instead of null | |
931 | could not unserialize | |
932 | return value as is, inside an array | |
948 | ///////////////////////////// "SET" data type functions /////////////////////////////////// | |
952 | dev.mysql.com/doc/refman/5.7/en/set.html | |
962 | simple cache | |
969 | turn a CSV to array so we can sort the data | |
975 | sort (trimmed and case-insensitive just as mysql does with SETs) | |
982 | empty element. remove. consider it null | |
986 | not found | |
989 | use the actual "PossibleValue" | |
992 | don't remove this case. handle the empty elemenet it in your app. | |
995 | array values need to be sorted. i thought php did this by default when working with <int> array keys, but that doesn't seem to be the case. so we sort. | |
997 | sorted | |
999 | if the array is empty, equate this to null across the board. null/not set is either allowed or not... it's all or nothing | |
1001 | return csv if forced or if input data is in CSV format (keep it the same) | |
1012 | simple cache | |
1019 | turn a CSV to array so we can sort the data | |
1024 | sort (trimmed and case-insensitive just as mysql does with SETs) | |
1031 | empty element. remove. consider it null | |
1034 | not found | |
1038 | SET data column cannot contain set data AND null/empty in same set | |
1042 | ////////////////////////// FORM STUFF ////////////////////////////////// | |
1060 | ///////////////////////////// Invoke /////////////////////////////////// | |
1073 | ///////////////////////////// ERROR ON INVALID FUNCTIONS/VARS ////////////////////////// | |
1095 | end class | |
TODO | 567 | Implement table's with composite keys into this function |
TODO | 593 | Implement table's with composite keys into this function |
TODO | 162 | implement this |
TODO | 167 | implement this. and maybe default to true instead of false |
TODO | 227 | Implement the SortOrder property for columns. 1-indexed to distinguish 0 from null/not set? |
Type | Line | Description |
---|---|---|
4 | www.phpsmartdb.com/ | |
8 | www.phpsmartdb.com/license | |
21 | ///////////////////////////// SERIALIZATION - At top so we don't forget to update these when we add new vars ////////////////////////// | |
38 | ////////////////////////////////////////////////////////////////////////////////////////////////////// | |
90 | ///////////////////////////// COLUMN WRAPPERS /////////////////////////////// | |
112 | ///////////////////////////////////////////////////////////////////////////// | |
120 | this shorthand is recommended: | |
121 | same thing as $row['YOUR_COLUMN_NAME']->GetValue(); | |
122 | same thing as $row['YOUR_COLUMN_NAME']->GetValue(true); | |
124 | NOTE: This is not recommended, but you can skip the function call (i.e. $row['YOUR_COLUMN_NAME']) when the returned value is used as a STRING ONLY! Otherwise, $row['YOUR_COLUMN_NAME'] gives you the actual SmartCell object. For example: | |
125 | is fine and will echo the column value | |
126 | is fine and will compare the column value to "my data" | |
127 | is NOT fine since we're not doing string comparison. this statement will try to compare the actual SmartCell object with the int 3 and will lead to bad things. | |
128 | is fine | |
129 | is fine and RECOMMENDED (just always invoke the Column/Cell directly like this) | |
130 | is fine | |
139 | initialize the row if not a primary key. may set $this->_value | |
143 | depending on the column's data type, we may need to normalize the raw database value for everyday use | |
146 | handle special return options (as described in the function comments) | |
147 | note- serialized columns (arrays, objects) do not have special return options, so ignore that parameter for those types. | |
149 | is a date column | |
152 | if false, strtotime failed and couldn't parse a date | |
155 | not a date column | |
171 | initialize the row if not a primary key. may set $this->_value | |
191 | changing a primary key column value? | |
193 | setting a non-autoincrement, non composite key | |
199 | changing a non primary key column value | |
203 | event cancelled, do not set the value | |
213 | notify the row that a cell's value had changed | |
244 | do this instead of unset. unset loses our private $_value and forces the value to be set on the Column level next time through, thanks to magic functions | |
247 | TODO: may need these Compress() and Uncompress() functions at that point? | |
254 | private function Compress($txt){ | |
255 | return base64_encode(gzcompress($txt)); | |
256 | } | |
263 | private function Uncompress($txt){ | |
264 | return gzuncompress(base64_decode($txt)); | |
265 | } | |
273 | check null first. only allow null special if this column is NOT required (ie NULL sf a valid value) | |
284 | special case with \0 not recognized as null/false | |
287 | special case with \0 not recognized as null/false | |
303 | $compareValues will be a CSV at this point, as is _value | |
304 | $compareValue will be serialized at this point, as is _value | |
305 | $compareValue will be serialized at this point, as is _value | |
320 | Either a string of the column to sort ASC by, or an assoc array of "ColumnName"=>"ASC"|"DESC" to sort by. An exception will be thrown if a column does not exist. | |
321 | if true, the returned assoc-array will have the row's primary key column value as its key and the row as its value. ie array("2"=>$row,...) instead of just array($row,...); | |
322 | OUT variable. integer. if you set this parameter in the $options array, then this function will return only 1 row of the result set at a time. If there are no rows selected or left to iterate over, null is returned. | |
323 | THIS PARAMETER MUST BE PASSED BY REFERENCE - i.e. array( "return-next-row" => &$curCount ) - the incoming value of this parameter doesn't matter and will be overwritten) | |
324 | After this function is executed, this OUT variable will be set with the number of rows that have been returned thus far. | |
325 | Each consecutive call to this function with the 'return-next-row' option set will return the next row in the result set, and also increment the 'return-next-row' variable to the number of rows that have been returned thus far | |
326 | With one argument (ie $limit="10"), the value specifies the number of rows to return from the beginning of the result set | |
327 | With two arguments (ie $limit="100,10"), the first argument specifies the offset of the first row to return, and the second specifies the maximum number of rows to return. The offset of the initial row is 0 (not 1): | |
328 | OUT variable only. integer. after this function is executed, this variable will be set with the number of rows being returned. Usage ex: array('return-count'=>&$count) | |
329 | if true, the return-count will be returned instead of the rows. A good optimization if you dont need to read any data from the rows and just need the rowcount of the search. | |
338 | shortcut support for GetRelatedRows(tableName, options) | |
342 | shortcut support for GetRelatedRows(tableName) | |
378 | ///////////////////////////// CALLBACK STUFF /////////////////////////////////// | |
379 | event callback arrays | |
380 | callbacks to be fired when this column has been set (not necessarily 'changed') | |
381 | callbacks to be fired before this column has been changed | |
382 | callbacks to be fired after this column has been changed | |
395 | no callbacks defined or callbacks disabled | |
397 | pass $this->Row reference back through to the callback | |
411 | setting 'cancel-event' to true within your $callbackFunction will prevent the event from continuing | |
412 | a reference to the Cell that fired the event | |
413 | the current value of this column, BEFORE it has changed to 'new-value' | |
414 | the value that this column is going to be set to, replacing the 'current-value'. Changing this value in your $callbackFunction will change the value that the column will be set to. | |
435 | setting 'cancel-event' to true within your $callbackFunction will prevent the event from continuing | |
436 | a reference to the Cell that fired the event | |
437 | the current value of this column, BEFORE it has changed to 'new-value' | |
438 | the value that this column is going to be set to, replacing the 'current-value'. Changing this value in your $callbackFunction will change the value that the column will be set to. | |
462 | a reference to the Cell that fired the event | |
463 | the current value of this column, AFTER it has been changed from 'old-value' | |
464 | the value that this column was set to before it was updated with the 'current-value' | |
479 | ///////////////////////////// FORM STUFF /////////////////////////////////// | |
524 | if true, a '*' will be appended to the end of the input field (note: default value may be set on the Column. use this field to overwrite the default value) | |
525 | can be either: 1. array("functionName", $obj) if function belongs to $obj, 2. array("functionName", "className") if the function is static within class "classname", or 3. just "functionName" if function is in global scope. this function will be called when getting the form object and the value returned by it will be used as the form object's value. the callback's signiture is functionName($value), where $value is the current cell value | |
535 | OPTIONS | |
536 | default options | |
539 | overwrite $defaultOptions with any $options specified | |
544 | get $currentValue (note: BuildAttribsHtml() does htmlspecialchars) | |
546 | serialized columns should present the 'raw' serialized text data | |
549 | set columns should present the 'raw' csv text data | |
553 | ATTRIBS | |
567 | overwrite $defaultAttribs with any $customAttribs specified | |
573 | formatter callback | |
585 | should be something unique, doesnt matter what | |
591 | if true, a '*' will be appended to the end of the input field (note: default value may be set on the Column. use this field to overwrite the default value) | |
592 | can be either: 1. array("functionName", $obj) if function belongs to $obj, 2. array("functionName", "className") if the function is static within class "classname", or 3. just "functionName" if function is in global scope. this function will be called when getting the form object and the value returned by it will be used as the form object's value. the callback's signiture is functionName($value), where $value is the current cell value | |
602 | OPTIONS | |
603 | default options | |
606 | overwrite $defaultOptions with any $options specified | |
611 | get $currentValue (note: BuildAttribsHtml() does htmlspecialchars) | |
613 | serialized columns should present the 'raw' serialized text data | |
616 | set columns should present the 'raw' csv text data | |
624 | ATTRIBS | |
638 | overwrite $defaultAttribs with any $customAttribs specified | |
644 | formatter callback | |
659 | if true, a '*' will be appended to the end of the input field (note: default value may be set on the Column. use this field to overwrite the default value) | |
660 | can be either: 1. array("functionName", $obj) if function belongs to $obj, 2. array("functionName", "className") if the function is static within class "classname", or 3. just "functionName" if function is in global scope. this function will be called when getting the form object and the value returned by it will be used as the form object's value. the callback's signiture is functionName($value), where $value is the current cell value | |
671 | OPTIONS | |
672 | default options | |
675 | overwrite $defaultOptions with any $options specified | |
680 | get $currentValue (note: BuildAttribsHtml() does htmlspecialchars) | |
682 | serialized columns should present the 'raw' serialized text data | |
686 | set columns should present the 'raw' csv text data | |
692 | not checked. but need a value for the checkbox in case user checks it | |
693 | set columns should present the 'raw' csv text data | |
694 | use first item, if we have one | |
700 | current value is set | |
705 | ATTRIBS | |
716 | overwrite $defaultAttribs with any $customAttribs specified | |
722 | formatter callback | |
731 | HIDDEN NOTIFIER ATTRIBS | |
741 | overwrite $defaultAttribs with any $customAttribs specified | |
759 | if true, a '*' will be appended to the end of the input field (note: default value may be set on the Column. use this field to overwrite the default value) | |
760 | can be either: 1. array("functionName", $obj) if function belongs to $obj, 2. array("functionName", "className") if the function is static within class "classname", or 3. just "functionName" if function is in global scope. this function will be called when getting the form object and the value returned by it will be used as the form object's value. the callback's signiture is functionName($value), where $value is the current cell value | |
761 | if true, an empty option will be the first option printed | |
762 | string. if set, the given key within $keyValuePairs will be forced as the selected option (if found. if not found, the browser's default choice will be selected, probably the first in the list) | |
763 | if true, this will populate the select object with the "PossibleValues" for this particular column (as defined in the xml db schema) | |
776 | OPTIONS | |
777 | default options | |
781 | overwrite $defaultOptions with any $options specified | |
786 | set the 'use-possible-values' option to true if this parameter is true. it's a shortcut | |
792 | add brackets (array notation) for multi-selects going into php | |
796 | ATTRIBS | |
802 | sets allow multiple select | |
803 | 'size' => count($keyValuePairs) IF between 2 and 10 | |
805 | overwrite $defaultAttribs with any $customAttribs specified | |
812 | get $currentValue | |
814 | serialized columns should present the 'raw' serialized text data | |
818 | OPTIONS | |
827 | populate select values from xml | |
832 | multi select (multiple current values) | |
833 | currentValue should be array here, but might be a CSV | |
843 | get formatted $currentValue | |
855 | try to make the multiple selects the right size (within reasonable limits) | |
863 | get formatted $currentValue | |
866 | non-multi select (1 current value) | |
878 | SELECT TAG | |
892 | if true, a '*' will be appended to the end of the input field (note: default value may be set on the Column. use this field to overwrite the default value) | |
893 | can be either: 1. array("functionName", $obj) if function belongs to $obj, 2. array("functionName", "className") if the function is static within class "classname", or 3. just "functionName" if function is in global scope. this function will be called when getting the form object and the value returned by it will be used as the form object's value. the callback's signiture is functionName($value), where $value is the current cell value | |
894 | the actual shown value of the text area (if not using the default value from this cell) | |
904 | get $currentValue | |
906 | serialized columns should present the 'raw' serialized text data | |
909 | set columns should present the 'raw' csv text data | |
913 | get formatted $currentValue | |
916 | OPTIONS | |
917 | default options | |
921 | overwrite $defaultOptions with any $options specified | |
927 | ATTRIBS | |
937 | overwrite $defaultAttribs with any $customAttribs specified | |
957 | can be either: 1. array("functionName", $obj) if function belongs to $obj, 2. array("functionName", "className") if the function is static within class "classname", or 3. just "functionName" if function is in global scope. this function will be called when getting the form object and the value returned by it will be used as the form object's value. the callback's signiture is functionName($value), where $value is the current cell value | |
967 | OPTIONS | |
969 | default options | |
971 | overwrite $defaultOptions with any $options specified | |
977 | get $currentValue (note: BuildAttribsHtml() does htmlspecialchars) | |
979 | serialized columns should present the 'raw' serialized text data | |
982 | set columns should present the 'raw' csv text data | |
986 | ATTRIBS | |
995 | overwrite $defaultAttribs with any $customAttribs specified | |
1001 | formatter callback | |
1017 | if true, this radio button will be checked regardless of the current Cell value. if false, this radio button will be checked only if the value matches the one currently in the Cell | |
1018 | if true, this radio button will be checked only if the current Cell value for thi column is null. defaults to true if the current value is 0 or empty string | |
1019 | a string for the text of the label next to the radio button. if this field is left empty, no label will be included with the button | |
1020 | can be "left" or "right", relative to the radio button (only if ['include-label']=true) | |
1021 | can be either: 1. array("functionName", $obj) if function belongs to $obj, 2. array("functionName", "className") if the function is static within class "classname", or 3. just "functionName" if function is in global scope. this function will be called when getting the form object and the value returned by it will be used as the form object's value. the callback's signiture is functionName($value), where $value is the current cell value | |
1033 | OPTIONS | |
1034 | default options | |
1036 | defaults to true if the current value is 0 or empty string | |
1037 | deprecated. alias to checked-if-null | |
1041 | overwrite $defaultOptions with any $options specified | |
1043 | support legacy options | |
1047 | get $currentValue (note: BuildAttribsHtml() does htmlspecialchars) | |
1049 | serialized columns should present the 'raw' serialized text data | |
1054 | set columns need to check if this $formValue is part of the active set | |
1055 | $currentValue is an array | |
1062 | "checked-if-null" radio option should default to true if the current value is 0 or empty string | |
1063 | if(!$formValue && ($currentValue === 0 || $currentValue === '')){ | |
1064 | $options['checked-if-null'] = true; | |
1065 | } | |
1072 | ATTRIBS | |
1082 | overwrite $defaultAttribs with any $customAttribs specified | |
1088 | formatter callback | |
1105 | strips any characters not valid for an HTML ID | |
1123 | if true, a '*' will be appended to the end of the input field (note: default value may be set on the Column. use this field to overwrite the default value) | |
1124 | can be either: 1. array("functionName", $obj) if function belongs to $obj, 2. array("functionName", "className") if the function is static within class "classname", or 3. just "functionName" if function is in global scope. this function will be called when getting the form object and the value returned by it will be used as the form object's value. the callback's signiture is functionName($value), where $value is the current cell value | |
1134 | OPTIONS | |
1135 | default options | |
1138 | overwrite $defaultOptions with any $options specified | |
1143 | get $currentValue (note: BuildAttribsHtml() does htmlspecialchars) | |
1145 | serialized columns should present the 'raw' serialized text data | |
1148 | set columns should present the 'raw' csv text data | |
1152 | ATTRIBS | |
1166 | overwrite $defaultAttribs with any $customAttribs specified | |
1172 | formatter callback | |
1186 | if true, a '*' will be appended to the end of the input field (note: default value may be set on the Column. use this field to overwrite the default value) | |
1187 | can be either: 1. array("functionName", $obj) if function belongs to $obj, 2. array("functionName", "className") if the function is static within class "classname", or 3. just "functionName" if function is in global scope. this function will be called when getting the form object and the value returned by it will be used as the form object's value. the callback's signiture is functionName($value), where $value is the current cell value | |
1197 | OPTIONS | |
1198 | default options | |
1201 | overwrite $defaultOptions with any $options specified | |
1206 | get $currentValue (note: BuildAttribsHtml() does htmlspecialchars) | |
1208 | serialized columns should present the 'raw' serialized text data | |
1211 | set columns should present the 'raw' csv text data | |
1215 | ATTRIBS | |
1229 | overwrite $defaultAttribs with any $customAttribs specified | |
1235 | formatter callback | |
1249 | if true, a '*' will be appended to the end of the input field (note: default value may be set on the Column. use this field to overwrite the default value) | |
1250 | can be either: 1. array("functionName", $obj) if function belongs to $obj, 2. array("functionName", "className") if the function is static within class "classname", or 3. just "functionName" if function is in global scope. this function will be called when getting the form object and the value returned by it will be used as the form object's value. the callback's signiture is functionName($value), where $value is the current cell value | |
1260 | OPTIONS | |
1261 | default options | |
1264 | overwrite $defaultOptions with any $options specified | |
1269 | get $currentValue (note: BuildAttribsHtml() does htmlspecialchars) | |
1271 | serialized columns should present the 'raw' serialized text data | |
1274 | set columns should present the 'raw' csv text data | |
1278 | ATTRIBS | |
1289 | overwrite $defaultAttribs with any $customAttribs specified | |
1295 | formatter callback | |
1327 | the id of the form object that this label is for. this should be left as default on most cases as the default name will be generated so it can be tracked by this class; custom names require you to handle organization of matching label names to form object ids | |
1328 | the text or html of the label. empty will use the column's DisplayName (if set), otherwise uses the ColumnName | |
1329 | adds a text or html prefix to the label | |
1330 | adds a text or html suffix to the label | |
1331 | if true, will html-special-chars the prefix, label-text, and suffix | |
1338 | reverse compatible | |
1339 | default options | |
1346 | overwrite $defaultOptions with any $options specified | |
1351 | if true, will html-special-chars the prefix, label-text, and suffix | |
1361 | ///////////////////////////// INPUT VALIDATION /////////////////////////////////// | |
1370 | If true: does not validate the key columns. If false: validates all columns | |
1371 | If true: only cells that have been set (i.e. isset()==true) will be verified (not recommended if this info will be committed to db). If false: all cells will be verified (should be used if this info will be committed to db). | |
1372 | appended to each error message | |
1379 | default options | |
1382 | overwrite $defaultOptions with any $options specified | |
1394 | need to validate that the value is valid (mostly for enumerations and sets) | |
1395 | for mysql, enum has null and "" as separate valid values and "" is ALWAYS valid... wtf? make it so "" and null are equal and always valid. will be caught later if null is not allowed | |
1399 | non-null value | |
1400 | all set values must be within the list of PossibleValues | |
1403 | invalid. show error message | |
1412 | enum (and other types thta might have PossibleValues set, but why would you do that?) | |
1413 | for mysql, enums are case-insensetitive! "AAA"=="aAa" as valid enum values | |
1414 | case-insensitive array search | |
1424 | int 0 is different from "0" (http://php.net/manual/en/types.comparisons.php). int 0 will consider the column as set for all datatypes except binary | |
1425 | so.. if the column is binary and the value is int 0, this is an error. if the column is anything else besides binary, this is NOT an error | |
1444 | ignore this if the field is required and empty. already have that error message | |
1447 | let this case pass because input is not required | |
1457 | ignore regex if the field is required and empty. already have that error message | |
1459 | let this case pass because input is not required | |
1461 | both PHP and javascript do case-insensitive regex checking | |
1471 | ignore 'null' values when checking uniqueness | |
1476 | $this row doesnt exist, so the found value is in use in another row | |
1478 | get formatted $currentValue | |
1484 | $this row does exist. see if the found value is part of $this row by comparing key column(s) | |
1489 | found row is not $this row, so found value is in use in another row | |
1491 | get formatted $currentValue | |
1500 | no other way to automatically determine if the found value is part of this row. leave it to the programmer/mysql errors for duplicates | |
1510 | ///////////////////////////// ArrayAccess /////////////////////////////////// | |
1557 | ///////////////////////////// Countable /////////////////////////////////// | |
1568 | ////////////////////////// IteratorAggregate ///////////////////////////// | |
1579 | end class |
Type | Line | Description |
---|---|---|
4 | www.phpsmartdb.com/ | |
8 | www.phpsmartdb.com/license | |
23 | validate page properties form | |
81 | $Column doesnt matter if $Table isnt set, so no need to check it | |
82 | return rules for the entire Database | |
92 | return rules for the given $Column | |
97 | if(!empty($Table)){ | |
98 | return rules for the given $Table | |
115 | Makes the element always required. | |
118 | Makes the element require a given minimum length. | |
122 | Makes the element require a given maxmimum length. | |
125 | Makes the element require matching the regex | |
130 | if($Column->){ | |
131 | $js .= "number: {$Column->MinSize},"; //Makes the element require a decimal number. | |
132 | } | |
136 | if($Column->){ | |
137 | $js .= "digits: {$Column->Digits},"; //Makes the element require digits only. | |
138 | } |