{"id":20100745,"url":"https://github.com/mattbit/mysql-compat","last_synced_at":"2025-05-06T06:32:36.565Z","repository":{"id":62525214,"uuid":"42375267","full_name":"mattbit/mysql-compat","owner":"mattbit","description":"Backward compatibility for old mysql_* functions","archived":false,"fork":false,"pushed_at":"2019-07-01T12:51:14.000Z","size":54,"stargazers_count":25,"open_issues_count":0,"forks_count":6,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-25T17:46:46.559Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mattbit.png","metadata":{"files":{"readme":"readme.md","changelog":null,"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":"2015-09-12T22:22:31.000Z","updated_at":"2024-07-03T07:08:25.000Z","dependencies_parsed_at":"2022-11-02T14:15:54.712Z","dependency_job_id":null,"html_url":"https://github.com/mattbit/mysql-compat","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mattbit%2Fmysql-compat","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mattbit%2Fmysql-compat/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mattbit%2Fmysql-compat/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mattbit%2Fmysql-compat/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mattbit","download_url":"https://codeload.github.com/mattbit/mysql-compat/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252633773,"owners_count":21779918,"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":[],"created_at":"2024-11-13T17:16:59.641Z","updated_at":"2025-05-06T06:32:36.294Z","avatar_url":"https://github.com/mattbit.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# Old mysql functions compatibility for PHP5.6 and PHP7\n\n[![Build Status](https://travis-ci.org/mattbit/mysql-compat.svg?branch=master)](https://travis-ci.org/mattbit/mysql-compat)\n[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/mattbit/mysql-compat/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/mattbit/mysql-compat/?branch=master)\n[![SensioLabsInsight](https://insight.sensiolabs.com/projects/d9fcd340-4f29-46ac-966a-9df364b87aae/mini.png)](https://insight.sensiolabs.com/projects/d9fcd340-4f29-46ac-966a-9df364b87aae)\n\nThis library tries to provide backward compatibility with the deprecated `mysql_*` functions.\n\n## Caveat\n\nYou really should not use this unless strictly needed: it's much better to refactor the existing code to use `PDO` and prepared statements directly or an ORM like [Eloquent](https://github.com/illuminate/database).\n\nAlthough library provides an hackish replacement for `mysql_real_escape_string`, you ought to refactor your code to use prepared statements.\n\n## Requirements\n\n`PHP \u003e= 5.6` with the `PDO` driver is required (`PHP 7` is supported).\n\n## Installation\n\nYou can install `mysql-compat` via [composer](https://getcomposer.org/):\n\n```\ncomposer require mattbit/mysql-compat\n```\n\n## Usage\n\nThe `mysql_`-equivalent functions are available through the facade class `Mattbit\\MysqlCompat\\Mysql`.\n\n```php\nrequire __DIR__ . '/vendor/autoload.php';\n\nuse Mattbit\\MysqlCompat\\Mysql;\n\nMysql::connect('host', 'user', 'password');\nMysql::selectDb('my_db');\n\n$result = Mysql::query('SELECT * FROM my_table');\n\n$row = Mysql::fetchArray($result);\n```\n\nNote that the static methods are named in a camel-case like version of the original functions, e.g. `mysql_fetch_array` becomes `Mysql::fetchArray`.\n\nIf you are using PHP7 and want to re-define the old global functions and constants without touching existing code, you can use the `Mysql::defineGlobals` method:\n\n```php\nrequire __DIR__ . '/vendor/autoload.php';\n\nMattbit\\MysqlCompat\\Mysql::defineGlobals();\n\nmysql_connect('host', 'user', 'password');\nmysql_select_db('my_db');\n\n$result = mysql_query('SELECT * FROM my_table');\n\n$row = mysql_fetch_array($result, MYSQL_BOTH);\n```\n\nIf you need more control over the connections, the database manager allows you to access the underlying objects.\n\n```php\nrequire __DIR__ . '/vendor/autoload.php';\n\nuse Mattbit\\MysqlCompat\\Mysql;\n\n$manager = Mysql::getManager();\n\n// Create a connection by specifying a custom DSN.\n$connection = $manager-\u003econnect('mysql:dbname=mydatabase;host=myhost', 'user', 'pass');\n\n// You can access the underlying PDO object\n$pdo = $connection-\u003egetPdo();\n\n// The rest of the code will use the last connection registered in the manager\n$res = Mysql::query('SELECT * FROM my_table');\n\n// But you can specify explicitly a connection as well\n$res = Mysql::query('SELECT * FROM my_table', $connection);\n```\n\nThis is particularly useful if you need to customize connection's DSN (e.g. to specify the charset):\n\n```php\n$manager = Mysql::getManager();\n$manager-\u003econnect('mysql:dbname=database;host=hostname;charset=customCharset', 'user', 'password');\n\n// This will automatically use the connection above, with the right charset.\n$res = Mysql::query('SELECT * FROM my_table');\n```\n\n## To do\n\n- [X] `mysql_​affected_​rows`\n- [ ] `mysql_​client_​encoding`\n- [X] `mysql_​close`\n- [X] `mysql_​connect`\n- [ ] `mysql_​create_​db`\n- [X] ~~mysql_​data_​seek~~ (not supported)\n- [ ] `mysql_​db_​name`\n- [ ] `mysql_​db_​query`\n- [ ] `mysql_​drop_​db`\n- [X] `mysql_​errno`\n- [X] `mysql_​error`\n- [X] `mysql_​escape_​string`\n- [X] `mysql_​fetch_​array`\n- [X] `mysql_​fetch_​assoc`\n- [X] `mysql_​fetch_​field`\n- [X] `mysql_​fetch_​lengths`\n- [X] `mysql_​fetch_​object`\n- [X] `mysql_​fetch_​row`\n- [ ] `mysql_​field_​flags`\n- [ ] `mysql_​field_​len`\n- [ ] `mysql_​field_​name`\n- [ ] `mysql_​field_​seek`\n- [ ] `mysql_​field_​table`\n- [ ] `mysql_​field_​type`\n- [ ] `mysql_​free_​result`\n- [ ] `mysql_​get_​client_​info`\n- [ ] `mysql_​get_​host_​info`\n- [ ] `mysql_​get_​proto_​info`\n- [ ] `mysql_​get_​server_​info`\n- [ ] `mysql_​info`\n- [X] `mysql_​insert_​id`\n- [ ] `mysql_​list_​dbs`\n- [ ] `mysql_​list_​fields`\n- [ ] `mysql_​list_​processes`\n- [ ] `mysql_​list_​tables`\n- [ ] `mysql_​num_​fields`\n- [X] `mysql_​num_​rows`\n- [ ] `mysql_​pconnect`\n- [ ] `mysql_​ping`\n- [X] `mysql_​query`\n- [X] `mysql_​real_​escape_​string`\n- [X] `mysql_​result`\n- [ ] `mysql_​select_​db`\n- [X] ~~`mysql_​set_​charset`~~ (see [issue #7](https://github.com/mattbit/mysql-compat/pull/7#issuecomment-467030421) for information)\n- [ ] `mysql_​stat`\n- [ ] `mysql_​tablename`\n- [ ] `mysql_​thread_​id`\n- [ ] `mysql_​unbuffered_​query`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmattbit%2Fmysql-compat","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmattbit%2Fmysql-compat","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmattbit%2Fmysql-compat/lists"}