Skip to content

Latest commit

 

History

History
61 lines (45 loc) · 3.56 KB

10. Miscellaneous.md

File metadata and controls

61 lines (45 loc) · 3.56 KB

PHPFUI\ORM Miscellaneous

SQLite Support

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.

Custom SQL Queries

PHFUI\ORM supports raw string queries for special cases or complex queries. The following static methods of \PHPFUI\ORM are supported:

getArrayCursor(string $sql = 'select 0 limit 0', array $input = []) : \PHPFUI\ORM\ArrayCursor

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(string $sql, array $input = []) : bool

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.

getRow(string $sql, array $input = []) : array<string, string>

Returns a single row of the first matching record or an empty array if an error

getRows(string $sql, array $input = [], int $fetchType = \PDO::FETCH_ASSOC) : array

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.

getValue(string $sql, array $input = []) : string

Returne the value from the first field in the first row returned by the querry, or blank if error

getValueArray(string $sql, array $input = []) : array

Returns the data values of the first element in each row of the query.

\PHPFUI\ORM\Record Data Cleaning Helpers

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.

Example Scripts

It is recommended to make versions of these example scripts customized to you needs:

cleanBackup.php

Removes various attributes of the backup to make it easier to restore on another server.

generateCRUD.php

Generates the models for your application based on your schema. You will want to change the PDO instance to your database connection string.

generateValidators.php

Generates the validators for your models based on your schema. You will want to change the PDO instance to your database connection string.

migrate.php

Example migration script.

Support Namespaces

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.