While this library is tested against SQLite, there are differences between MySQL/MariaDB syntax and SQLite syntax. Most notabliy is insertOrUpdate() and insertOrIgnore() which are not supported for SQLite. Use the custom SQL query support below instead.
PHFUI\ORM supports raw string queries for special cases or complex queries. The following static methods of \PHPFUI\ORM are supported:
Returns an ArrayCursor from any SQL statement.
getDataObjectCursor(string $sql = 'select 0 limit 0', array $input = []) : \PHPFUI\ORM\DataObjectCursor
Returns an DataObjectCursor from any SQL statement.
getRecordCursor(\PHPFUI\ORM\Record $crud, string $sql = 'select 0 limit 0', array $input = []) : \PHPFUI\ORM\RecordCursor
Returns an RecordCursor from any SQL statement.
Execute any SQL string. Useful for queries where you don't care about the results, or don't return results. True is returned on success.
Returns a single row of the first matching record or an empty array if an error
Returns the query results in an array. Because this reads all records into memory at the same time, it is recommended to use an ArrayCusor for interation on the data instead.
Returne the value from the first field in the first row returned by the querry, or blank if error
Returns the data values of the first element in each row of the query.
The \PHPFUI\ORM\Record class provides some simple data cleaning functions you can use where needed.
- cleanUpperCase(string $field) Converts the field to all upper case
- cleanLowerCase(string $field) Converts the field to all lower case
- cleanNumber(string $field) removes all non-digits (0-9 and -) from string representation of a number
- cleanFloat(string $field, int $decimalPoints = 2) removes all non-digits (0-9, . and -)
- cleanPhone(string $field, string $regExSeparators = '\-\.') removes all non-digits (0-9) and regex separators
- cleanProperName(string $field) Properly capitalizes proper names if in single case. Mixed case strings are not altered.
- cleanEmail(string $field) Lowercases and strips invalid email characters. Does not validate email address.
It is recommended to make versions of these example scripts customized to you needs:
Removes various attributes of the backup to make it easier to restore on another server.
Generates the models for your application based on your schema. You will want to change the PDO instance to your database connection string.
Generates the validators for your models based on your schema. You will want to change the PDO instance to your database connection string.
Example migration script.
The following namespaces are used in production but contains support classes or examples.
- PHPFUI\ORM\Tool used by model generation
- PHPFUI\ORM\Record contains example of migration table.
- PHPFUI\ORM\Table contains example of migration table.