{"id":13599701,"url":"https://github.com/ezSQL/ezsql","last_synced_at":"2025-04-10T17:32:00.794Z","repository":{"id":2373090,"uuid":"3337723","full_name":"ezSQL/ezsql","owner":"ezSQL","description":"PHP class to make interacting with a database ridiculusly easy","archived":false,"fork":false,"pushed_at":"2023-01-15T01:40:07.000Z","size":1765,"stargazers_count":866,"open_issues_count":2,"forks_count":291,"subscribers_count":103,"default_branch":"master","last_synced_at":"2024-10-29T17:14:09.412Z","etag":null,"topics":["crud","dba","dbal","ezsql","mysql","mysqli","oracle","pdo","pgsql","php","shortcut","sql","sqlite3","sqlserver"],"latest_commit_sha":null,"homepage":"http://ezsql.github.io/ezsql","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"lgpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ezSQL.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-02-02T19:01:04.000Z","updated_at":"2024-09-26T03:13:52.000Z","dependencies_parsed_at":"2023-01-16T18:31:12.198Z","dependency_job_id":null,"html_url":"https://github.com/ezSQL/ezsql","commit_stats":null,"previous_names":[],"tags_count":19,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ezSQL%2Fezsql","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ezSQL%2Fezsql/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ezSQL%2Fezsql/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ezSQL%2Fezsql/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ezSQL","download_url":"https://codeload.github.com/ezSQL/ezsql/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223095334,"owners_count":17086613,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["crud","dba","dbal","ezsql","mysql","mysqli","oracle","pdo","pgsql","php","shortcut","sql","sqlite3","sqlserver"],"created_at":"2024-08-01T17:01:09.330Z","updated_at":"2024-11-07T01:30:30.404Z","avatar_url":"https://github.com/ezSQL.png","language":"PHP","readme":"# **ezsql**\n\n[![Windows](https://github.com/ezSQL/ezsql/workflows/Windows/badge.svg)](https://github.com/ezSQL/ezsql/actions?query=workflow%3AWindows)\n[![Linux](https://github.com/ezSQL/ezsql/workflows/Linux/badge.svg)](https://github.com/ezSQL/ezsql/actions?query=workflow%3ALinux)\n[![macOS](https://github.com/ezSQL/ezsql/workflows/macOS/badge.svg)](https://github.com/ezSQL/ezsql/actions?query=workflow%3AmacOS)\n[![codecov](https://codecov.io/gh/ezSQL/ezSQL/branch/master/graph/badge.svg)](https://codecov.io/gh/ezSQL/ezSQL)\n[![Codacy Badge](https://api.codacy.com/project/badge/Grade/aad1f6aaaaa14f60933e75615da900b8)](https://www.codacy.com/app/techno-express/ezsql?utm_source=github.com\u0026amp;utm_medium=referral\u0026amp;utm_content=ezSQL/ezsql\u0026amp;utm_campaign=Badge_Grade)\n[![Maintainability](https://api.codeclimate.com/v1/badges/6f6107f25e9de7bf4272/maintainability)](https://codeclimate.com/github/ezSQL/ezsql/maintainability)\n[![Total Downloads](https://poser.pugx.org/ezsql/ezsql/downloads)](https://packagist.org/packages/ezsql/ezsql)\n\n***A class to make it very easy to deal with database connections.***\n*An universal interchangeable **CRUD** system.*\n\nThis is [__Version 5__](https://github.com/ezSQL/ezsql/tree/v5) which will break users of **version 4**.\n\nMainly by:\n\n- The use of `namespace` in the `global` functions **ezFunctions.php** file.\n    Usage of the **global** functions will require the user to begin a `.php` file something like:\n\n    ```php\n    use function ezsql\\functions\\where;\n    // Or\n    use function ezsql\\functions\\{\n        getInstance,\n        selecting,\n        inserting,\n    };\n    ```\n\n- Class properties that was accessible by magic methods `get/set`, now PSR 1 camelCase.\n- Renamed `select` of `ez_mysqli` to `dbSelect`.\n- Renamed class method and behavior of `selecting` to `select`.\n- `selecting`, and new `inserting` methods, can be called without table name, only the other necessary parameters:\n    - The table *name* with *prefix*, can be preset/stored with methods `tableSetup(name, prefix), or setTable(name), setPrefix(append)`, if called without presetting, `false` is returned.\n    - This **feature** will be added to **all** database *CRUD* access methods , each method name will have an `ing` ending added.\n- Removed global functions where `table` name passed in, use functions using preset table names ending with `ing`.\n- renamed cleanInput to clean_string\n- renamed createCertificate to create_certificate\n- added global get_results to return result sets in different formats\n\n[__Version 4__](https://github.com/ezSQL/ezsql/tree/v4) has many modern programming practices in which will break users of version 3.\n\n[__Version 3__](https://github.com/ezSQL/ezsql/tree/v3) broke version 2.1.7 in one major way, it required *PHP 5.6*. Which drop mysql extension support, other than that, nothing as far using the library was changed, only additional features.\n\nThis library has an `Database` class, an combination of the [Factory](https://en.wikipedia.org/wiki/Factory_method_pattern) pattern with an [Dependency Injection](https://en.wikipedia.org/wiki/Dependency_injection) container hosting. This library now is following many OOP principles, one in which, the methods properties public access has been removed. This library also following PSR-2, PSR-4, PSR-11 conventions, and mostly PSR-1, that's still an work in progress.\n\n* More Todo...\n\nFor an full overview see [documentation Wiki](https://github.com/ezSQL/ezsql/wiki/Documentation), which is not completely finish.\n\n## Installation\n\n    composer require ezsql/ezsql\n\n## Usage\n\n```php\nrequire 'vendor/autoload.php';\n\n// **** is one of mysqli, pgsql, sqlsrv, sqlite3, or Pdo.\nuse ezsql\\Database;\n\n$db = Database::initialize('****', [$dsn_path_user, $password, $database, $other_settings], $optional_tag);\n\n// Is same as:\nuse ezsql\\Config;\nuse ezsql\\Database\\ez_****;\n\n$settings = new Config('****', [$dsn_path_user, $password, $database, $other_settings]);\n\n$db = new ez_****($settings);\n```\n\nThis library will assume the developer is using some sort of IDE with intellisense enabled. The comments/doc-block area will hold any missing documentations. For additional examples see __phpunit__ tests, The tests are fully functional integration tests, meaning the are live database tests, no mocks.\n\nThe following has been added since version 2.1.7.\n\n___General Methods___\n\n    to_string($arrays, $separation = ',');\n    clean($string);\n    create_cache(string $path = null);\n    secureSetup(string $key = 'certificate.key',\n        string $cert = 'certificate.crt',\n        string $ca = 'cacert.pem',\n        string $path = '.'._DS\n    );\n    secureReset();\n    create_certificate(string $privatekeyFile = certificate.key,\n        string $certificateFile = certificate.crt,\n        string $signingFile = certificate.csr,\n        string $ssl_path = null, array $details = [commonName =\u003e localhost]\n    );\n\n___Shortcut Table Methods___\n\n    create(string $table = null, ...$schemas);// $schemas requires... column()\n    column(string $column = null, string $type = null, ...$args);\n    primary(string $primaryName, ...$primaryKeys);\n    index(string $indexName, ...$indexKeys);\n    drop(string $table);\n\nExample\n\n```php\n// Creates an database table\ncreate('profile',\n    // and with database column name, datatype\n    // data types are global CONSTANTS\n    // SEQUENCE|AUTO is placeholder tag, to be replaced with the proper SQL drivers auto number sequencer word.\n    column('id', INTR, 11, AUTO, PRIMARY), // mysqli\n    column('name', VARCHAR, 50, notNULL),\n    column('email', CHAR, 25, NULLS),\n    column('phone', TINYINT)\n);\n```\n\n---\n\n    innerJoin(string $leftTable = null, string $rightTable = null,\n        string $leftColumn = null, string $rightColumn = null, string $tableAs = null, $condition = EQ);\n\n    leftJoin(string $leftTable = null, string $rightTable = null,\n        string $leftColumn = null, string $rightColumn = null, string $tableAs = null, $condition = EQ);\n\n    rightJoin(string $leftTable = null, string $rightTable = null,\n        string $leftColumn = null, string $rightColumn = null, string $tableAs = null, $condition = EQ);\n\n    fullJoin(string $leftTable = null, string $rightTable = null,\n        string $leftColumn = null, string $rightColumn = null, string $tableAs = null, $condition = EQ);\n---\n\n```php\nprepareOn(); // When activated will use prepare statements for all shortcut SQL Methods calls.\nprepareOff(); // When off shortcut SQL Methods calls will use vendors escape routine instead. This is the default behavior.\n```\n\n### Shortcut SQL Methods\n\n* `having(...$having);`\n* `groupBy($groupBy);`\n* `union(string $table = null, $columnFields = '*', ...$conditions);`\n* `unionAll(string $table = null, $columnFields = '*', ...$conditions);`\n* `orderBy($orderBy, $order);`\n* `limit($numberOf, $offset = null)`\n* `where( ...$whereConditions);`\n* `select(string $table = null, $columnFields = '*', ...$conditions);`\n* `create_select(string $newTable, $fromColumns, $oldTable = null, ...$conditions);`\n* `select_into(string $newTable, $fromColumns, $oldTable = null, ...$conditions);`\n* `update(string $table = null, $keyAndValue, ...$whereConditions);`\n* `delete(string $table = null, ...$whereConditions);`\n* `replace(string $table = null, $keyAndValue);`\n* `insert(string $table = null, $keyAndValue);`\n* `create(string $table = null, ...$schemas);`\n* `drop(string $table = null);`\n* `alter(string $table = null, ...$alteringSchema);`\n* `insert_select(string $toTable = null, $toColumns = '*', $fromTable = null, $fromColumns = '*', ...$conditions);`\n\n```php\n// The variadic ...$whereConditions, and ...$conditions parameters,\n//  represent the following global functions.\n// They are comparison expressions returning an array with the given arguments,\n//  the last arguments of _AND, _OR, _NOT, _andNOT will combine expressions\neq('column', $value, _AND), // combine next expression\nneq('column', $value, _OR), // will combine next expression again\nne('column', $value), // the default is _AND so will combine next expression\nlt('column', $value)\nlte('column', $value)\ngt('column', $value)\ngte('column', $value)\nisNull('column')\nisNotNull('column')\nlike('column', '_%?')\nnotLike('column', '_%?')\nin('column', ...$value)\nnotIn('column', ...$value)\nbetween('column', $value, $value2)\nnotBetween('column', $value, $value2)\n// The above should be used within the where( ...$whereConditions) clause\n// $value will protected by either using escape or prepare statement\n```\n\n```php\n// To allow simple grouping of basic $whereConditions,\n// wrap the following around a group of the above comparison\n// expressions within the where( ...$whereConditions) clause\ngrouping( eq(key, value, combiner ), eq(key, value, combiner ) )\n// The above will wrap beginning and end grouping in a where statement\n// where required to break down your where clause.\n```\n\n```php\n// Note: The usage of this method will require the user/developer to check\n// if `query_string` or `param_array` is valid.\n//\n// This is really an `private` internal method for other shortcut methods,\n// it's made public for `class development` usage only.\n//\n//\n// Supply the the whole `query` string, and placing '?' within, with the same number of arguments in an array.\n// It will then determine arguments type, execute, and return results.\nquery_prepared(string $query_string, array $param_array);\n// You will need to call this method to get last successful query result.\n// It wll return an object array.\nqueryResult();\n```\n\n#### Example for using prepare statements indirectly, with above shortcut SQL methods\n\n```php\n// To get all shortcut SQL methods calls to use prepare statements\n$db-\u003eprepareOn(); // This needs to be called at least once at instance creation\n\n$values = [];\n$values['name'] = $user;\n$values['email'] = $address;\n$values['phone'] = $number;\n$db-\u003einsert('profile', $values);\n$db-\u003einsert('profile', ['name' =\u003e 'john john', 'email' =\u003e 'john@email', 'phone' =\u003e 123456]);\n\n// returns result set given the table name, column fields, and ...conditions\n$result = $db-\u003eselect('profile', 'phone', eq('email', $email), between('id', 1, $values));\n\nforeach ($result as $row) {\n    echo $row-\u003ephone;\n}\n\n$result = $db-\u003eselect('profile', 'name, email',\n    // Conditionals can also be called, stacked with other functions like:\n    //  innerJoin(), leftJoin(), rightJoin(), fullJoin()\n    //      as (leftTable, rightTable, leftColumn, rightColumn, tableAs, equal condition),\n    //  where( eq( columns, values, _AND ), like( columns, _d ) ),\n    //  groupBy( columns ),\n    //  having( between( columns, values1, values2 ) ),\n    //  orderBy( columns, desc ),\n    //  limit( numberOfRecords, offset ),\n    //  union(table, columnFields, conditions),\n    //  unionAll(table, columnFields, conditions)\n    $db-\u003ewhere( eq('phone', $number, _OR), neq('id', 5) ),\n    //  another way: where( array(key, operator, value, combine, combineShifted) );\n    //  or as strings double spaced: where( \"key  operator  value  combine  combineShifted\" );\n    $db-\u003eorderBy('name'),\n    $db-\u003elimit(1)\n);\n\nforeach ($result as $row) {\n    echo $row-\u003ename.' '.$row-\u003eemail;\n}\n\n// To get results in `JSON` format\n$json = get_results(JSON, $db);\n```\n\n#### Example for using prepare statements directly, no shortcut SQL methods used\n\n```php\n$db-\u003equery_prepared('INSERT INTO profile( name, email, phone) VALUES( ?, ?, ? );', [$user, $address, $number]);\n\n$db-\u003equery_prepared('SELECT name, email FROM profile WHERE phone = ? OR id != ?', [$number, 5]);\n$result = $db-\u003equeryResult(); // the last query that has results are stored in `lastResult` protected property\n// Or for results in other formats use the global function, will use global database instance if no `$db` supplied\n$result = get_results(/* OBJECT|ARRAY_A|ARRAY_N|JSON */, $db); // Defaults to `OBJECT`\n\nforeach ($result as $row) {\n    echo $row-\u003ename.' '.$row-\u003eemail;\n}\n```\n\nMost of shortcut methods have counter **global** _functions_ available.\nThey can only be access by beginning your `.php` file like:\n\n```php\nuse function ezsql\\functions\\functionBelow;\n// Or as here, a complete list.\nuse function ezsql\\functions\\{\n    database,\n    mysqlInstance,\n    pgsqlInstance,\n    mssqlInstance,\n    sqliteInstance,\n    pdoInstance,\n    tagInstance,\n    setInstance,\n    getInstance,\n    clearInstance,\n    get_vendor,\n///\n    to_string,\n    clean_string,\n    is_traversal,\n    sanitize_path,\n    create_certificate,\n///\n    column,\n    primary,\n    foreign,\n    unique,\n    index,\n    addColumn,\n    dropColumn,\n    changingColumn,\n///\n    eq,\n    neq,\n    ne,\n    lt,\n    lte,\n    gt,\n    gte,\n    isNull,\n    isNotNull,\n    like,\n    in,\n    notLike,\n    notIn,\n    between,\n    notBetween,\n///\n    where,\n    grouping,\n    groupBy,\n    having,\n    orderBy,\n    limit,\n    innerJoin,\n    leftJoin,\n    rightJoin,\n    fullJoin,\n    union,\n    unionAll,\n///\n    creating,\n    deleting,\n    dropping,\n    replacing,\n    selecting,\n    inserting,\n    altering,\n    get_results,\n    table_setup,\n    set_table,\n    set_prefix,\n    select_into,\n    insert_select,\n    create_select,\n};\n```\n\nFor the functions **usage/docs** see [ezFunctions.php](https://github.com/ezSQL/ezsql/blob/v5/lib/ezFunctions.php).\n\n## For Authors and **[Contributors](https://github.com/ezSQL/ezsql/blob/master/CONTRIBUTORS.md)**\n\n## Contributing\n\nContributions are encouraged and welcome; I am always happy to get feedback or pull requests on Github :) Create [Github Issues](https://github.com/ezSQL/ezsql/issues) for bugs and new features and comment on the ones you are interested in.\n\n## License\n\n**ezsql** is open-sourced software licensed originally under (LGPL-3.0), and the addon parts under (MIT).\n","funding_links":[],"categories":["PHP"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FezSQL%2Fezsql","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FezSQL%2Fezsql","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FezSQL%2Fezsql/lists"}