diff options
-rw-r--r-- | README.md | 11 | ||||
-rw-r--r-- | composer.json | 2 | ||||
-rw-r--r-- | composer.lock | 502 | ||||
-rw-r--r-- | lib/mysql.php | 35 |
4 files changed, 529 insertions, 21 deletions
@@ -1,3 +1,6 @@ +[](https://travis-ci.org/dshafik/php7-mysql-shim) +[](https://scrutinizer-ci.com/g/dshafik/php7-mysql-shim/?branch=master) +[](https://scrutinizer-ci.com/g/dshafik/php7-mysql-shim/?branch=master) # PHP 7 Shim for ext/mysql This library attempts to create a drop-in replacement for ext/mysql on PHP 7 using mysqli. @@ -21,7 +24,7 @@ Once the file is included, it will create `mysql_*` function if they don't alrea ## Caveats -The only things that should break are calls to `is_resource()` on MySQL connections and results, as these -are now their `mysqli` equivalents. - -Additionally, some errors are now from `ext/mysqli`, and others are `E_USER_WARNING` instead of `E_WARNING`. +- Calls to `is_resource()` and `get_resource_type()` on MySQL connections and results will fail as these are now their `mysqli` equivalents. +-Some errors are now from `ext/mysqli`, and others are `E_USER_WARNING` instead of `E_WARNING`. +- Column lengths reported by `mysql_field_len()` assume latin1 +- You must prefix all calls to `mysql_*` with a `\` (e.g. `\mysql_connect()`; diff --git a/composer.json b/composer.json index 329eef4..aa53015 100644 --- a/composer.json +++ b/composer.json @@ -10,6 +10,8 @@ } ], "require-dev": { + "squizlabs/php_codesniffer": "^2.3", + "fabpot/php-cs-fixer": "^1.9", "phpunit/phpunit": "~5.1" }, "autoload": { diff --git a/composer.lock b/composer.lock index 4ca167d..34261d6 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "a879f677a37578594990cd73798b4f84", + "hash": "4029c3ee9d261492406caa51871b7ca6", "packages": [], "packages-dev": [ { @@ -62,6 +62,60 @@ "time": "2015-06-14 21:17:01" }, { + "name": "fabpot/php-cs-fixer", + "version": "v1.11", + "source": { + "type": "git", + "url": "https://github.com/FriendsOfPHP/PHP-CS-Fixer.git", + "reference": "bd3ec2c2b774e0e127ac2c737ec646d9cf2f9eef" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/FriendsOfPHP/PHP-CS-Fixer/zipball/bd3ec2c2b774e0e127ac2c737ec646d9cf2f9eef", + "reference": "bd3ec2c2b774e0e127ac2c737ec646d9cf2f9eef", + "shasum": "" + }, + "require": { + "ext-tokenizer": "*", + "php": ">=5.3.6", + "sebastian/diff": "~1.1", + "symfony/console": "~2.3|~3.0", + "symfony/event-dispatcher": "~2.1|~3.0", + "symfony/filesystem": "~2.1|~3.0", + "symfony/finder": "~2.1|~3.0", + "symfony/process": "~2.3|~3.0", + "symfony/stopwatch": "~2.5|~3.0" + }, + "require-dev": { + "satooshi/php-coveralls": "0.7.*@dev" + }, + "bin": [ + "php-cs-fixer" + ], + "type": "application", + "autoload": { + "psr-4": { + "Symfony\\CS\\": "Symfony/CS/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Dariusz RumiĆski", + "email": "dariusz.ruminski@gmail.com" + }, + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + } + ], + "description": "A tool to automatically fix PHP code style", + "time": "2015-12-01 22:34:33" + }, + { "name": "myclabs/deep-copy", "version": "1.5.0", "source": { @@ -996,6 +1050,452 @@ "time": "2015-06-21 13:59:46" }, { + "name": "squizlabs/php_codesniffer", + "version": "2.4.0", + "source": { + "type": "git", + "url": "https://github.com/squizlabs/PHP_CodeSniffer.git", + "reference": "32a879f4f35019d78d568db2885d7779ca084a33" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/32a879f4f35019d78d568db2885d7779ca084a33", + "reference": "32a879f4f35019d78d568db2885d7779ca084a33", + "shasum": "" + }, + "require": { + "ext-tokenizer": "*", + "ext-xmlwriter": "*", + "php": ">=5.1.2" + }, + "bin": [ + "scripts/phpcs", + "scripts/phpcbf" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "CodeSniffer.php", + "CodeSniffer/CLI.php", + "CodeSniffer/Exception.php", + "CodeSniffer/File.php", + "CodeSniffer/Fixer.php", + "CodeSniffer/Report.php", + "CodeSniffer/Reporting.php", + "CodeSniffer/Sniff.php", + "CodeSniffer/Tokens.php", + "CodeSniffer/Reports/", + "CodeSniffer/Tokenizers/", + "CodeSniffer/DocGenerators/", + "CodeSniffer/Standards/AbstractPatternSniff.php", + "CodeSniffer/Standards/AbstractScopeSniff.php", + "CodeSniffer/Standards/AbstractVariableSniff.php", + "CodeSniffer/Standards/IncorrectPatternException.php", + "CodeSniffer/Standards/Generic/Sniffs/", + "CodeSniffer/Standards/MySource/Sniffs/", + "CodeSniffer/Standards/PEAR/Sniffs/", + "CodeSniffer/Standards/PSR1/Sniffs/", + "CodeSniffer/Standards/PSR2/Sniffs/", + "CodeSniffer/Standards/Squiz/Sniffs/", + "CodeSniffer/Standards/Zend/Sniffs/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Greg Sherwood", + "role": "lead" + } + ], + "description": "PHP_CodeSniffer tokenizes PHP, JavaScript and CSS files and detects violations of a defined set of coding standards.", + "homepage": "http://www.squizlabs.com/php-codesniffer", + "keywords": [ + "phpcs", + "standards" + ], + "time": "2015-11-23 21:30:59" + }, + { + "name": "symfony/console", + "version": "v3.0.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/console.git", + "reference": "175871ca8d1ef16ff8d8cac395a1c73afa8d0e63" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/console/zipball/175871ca8d1ef16ff8d8cac395a1c73afa8d0e63", + "reference": "175871ca8d1ef16ff8d8cac395a1c73afa8d0e63", + "shasum": "" + }, + "require": { + "php": ">=5.5.9", + "symfony/polyfill-mbstring": "~1.0" + }, + "require-dev": { + "psr/log": "~1.0", + "symfony/event-dispatcher": "~2.8|~3.0", + "symfony/process": "~2.8|~3.0" + }, + "suggest": { + "psr/log": "For using the console logger", + "symfony/event-dispatcher": "", + "symfony/process": "" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.0-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\Console\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony Console Component", + "homepage": "https://symfony.com", + "time": "2015-11-30 12:36:17" + }, + { + "name": "symfony/event-dispatcher", + "version": "v3.0.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/event-dispatcher.git", + "reference": "d36355e026905fa5229e1ed7b4e9eda2e67adfcf" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/event-dispatcher/zipball/d36355e026905fa5229e1ed7b4e9eda2e67adfcf", + "reference": "d36355e026905fa5229e1ed7b4e9eda2e67adfcf", + "shasum": "" + }, + "require": { + "php": ">=5.5.9" + }, + "require-dev": { + "psr/log": "~1.0", + "symfony/config": "~2.8|~3.0", + "symfony/dependency-injection": "~2.8|~3.0", + "symfony/expression-language": "~2.8|~3.0", + "symfony/stopwatch": "~2.8|~3.0" + }, + "suggest": { + "symfony/dependency-injection": "", + "symfony/http-kernel": "" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.0-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\EventDispatcher\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony EventDispatcher Component", + "homepage": "https://symfony.com", + "time": "2015-10-30 23:35:59" + }, + { + "name": "symfony/filesystem", + "version": "v3.0.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/filesystem.git", + "reference": "692d98d813e4ef314b9c22775c86ddbeb0f44884" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/filesystem/zipball/692d98d813e4ef314b9c22775c86ddbeb0f44884", + "reference": "692d98d813e4ef314b9c22775c86ddbeb0f44884", + "shasum": "" + }, + "require": { + "php": ">=5.5.9" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.0-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\Filesystem\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony Filesystem Component", + "homepage": "https://symfony.com", + "time": "2015-11-23 10:41:47" + }, + { + "name": "symfony/finder", + "version": "v3.0.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/finder.git", + "reference": "3577eb98dba90721d1a0a3edfc6956ab8b1aecee" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/finder/zipball/3577eb98dba90721d1a0a3edfc6956ab8b1aecee", + "reference": "3577eb98dba90721d1a0a3edfc6956ab8b1aecee", + "shasum": "" + }, + "require": { + "php": ">=5.5.9" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.0-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\Finder\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony Finder Component", + "homepage": "https://symfony.com", + "time": "2015-10-30 23:35:59" + }, + { + "name": "symfony/polyfill-mbstring", + "version": "v1.0.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-mbstring.git", + "reference": "0b6a8940385311a24e060ec1fe35680e17c74497" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/0b6a8940385311a24e060ec1fe35680e17c74497", + "reference": "0b6a8940385311a24e060ec1fe35680e17c74497", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Polyfill\\Mbstring\\": "" + }, + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill for the Mbstring extension", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "mbstring", + "polyfill", + "portable", + "shim" + ], + "time": "2015-11-04 20:28:58" + }, + { + "name": "symfony/process", + "version": "v3.0.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/process.git", + "reference": "01383ed02a1020759bc8ee5d975fcec04ba16fbf" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/process/zipball/01383ed02a1020759bc8ee5d975fcec04ba16fbf", + "reference": "01383ed02a1020759bc8ee5d975fcec04ba16fbf", + "shasum": "" + }, + "require": { + "php": ">=5.5.9" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.0-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\Process\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony Process Component", + "homepage": "https://symfony.com", + "time": "2015-11-30 12:36:17" + }, + { + "name": "symfony/stopwatch", + "version": "v3.0.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/stopwatch.git", + "reference": "6aeac8907e3e1340a0033b0a9ec075f8e6524800" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/stopwatch/zipball/6aeac8907e3e1340a0033b0a9ec075f8e6524800", + "reference": "6aeac8907e3e1340a0033b0a9ec075f8e6524800", + "shasum": "" + }, + "require": { + "php": ">=5.5.9" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.0-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\Stopwatch\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony Stopwatch Component", + "homepage": "https://symfony.com", + "time": "2015-10-30 23:35:59" + }, + { "name": "symfony/yaml", "version": "v3.0.0", "source": { diff --git a/lib/mysql.php b/lib/mysql.php index e1a8013..15a91b1 100644 --- a/lib/mysql.php +++ b/lib/mysql.php @@ -1,5 +1,6 @@ <?php namespace { + if (!function_exists('\mysql_connect')) { define('MYSQL_CLIENT_COMPRESS', MYSQLI_CLIENT_COMPRESS); define('MYSQL_CLIENT_IGNORE_SPACE', MYSQLI_CLIENT_IGNORE_SPACE); @@ -11,8 +12,8 @@ namespace { $username = null, $password = null, $new = false, - $flags = 0) - { + $flags = 0 + ) { if ($new !== false) { trigger_error('Argument $new is no longer supported in PHP > 7', E_USER_WARNING); } @@ -70,8 +71,8 @@ namespace { $hostname = null, $username = null, $password = null, - $flags = 0) - { + $flags = 0 + ) { $hostname = 'p:' . $hostname; return mysql_connect($hostname, $username, $password, false, $flags); } @@ -305,7 +306,7 @@ namespace { if (\Dshafik\MySQL::checkValidResult($result, __FUNCTION__)) { return false; } - return \Dshafik\MySQL::mysql_field_info($result, $field, 'name'); + return \Dshafik\MySQL::mysqlFieldInfo($result, $field, 'name'); } function mysql_field_table($result, $field) @@ -313,7 +314,7 @@ namespace { if (\Dshafik\MySQL::checkValidResult($result, __FUNCTION__)) { return false; } - return \Dshafik\MySQL::mysql_field_info($result, $field, 'table'); + return \Dshafik\MySQL::mysqlFieldInfo($result, $field, 'table'); } function mysql_field_len($result, $field) @@ -321,7 +322,7 @@ namespace { if (\Dshafik\MySQL::checkValidResult($result, __FUNCTION__)) { return false; } - return \Dshafik\MySQL::mysql_field_info($result, $field, 'length'); + return \Dshafik\MySQL::mysqlFieldInfo($result, $field, 'length'); } function mysql_field_type($result, $field) @@ -329,7 +330,7 @@ namespace { if (\Dshafik\MySQL::checkValidResult($result, __FUNCTION__)) { return false; } - return \Dshafik\MySQL::mysql_field_info($result, $field, 'type'); + return \Dshafik\MySQL::mysqlFieldInfo($result, $field, 'type'); } function mysql_field_flags($result, $field) @@ -337,7 +338,7 @@ namespace { if (\Dshafik\MySQL::checkValidResult($result, __FUNCTION__)) { return false; } - return \Dshafik\MySQL::mysql_field_info($result, $field, 'flags'); + return \Dshafik\MySQL::mysqlFieldInfo($result, $field, 'flags'); } function mysql_escape_string($unescapedString) @@ -506,11 +507,13 @@ namespace { } namespace Dshafik { - class MySQL { - static public $last_connection = null; - static public $connections = []; - static public function getConnection($link = null, $func = null) + class MySQL + { + public static $last_connection = null; + public static $connections = []; + + public static function getConnection($link = null, $func = null) { if ($link !== null) { return $link; @@ -528,7 +531,7 @@ namespace Dshafik { return static::$last_connection; } - static public function mysql_field_info(\mysqli_result $result, $field, $what) + public static function mysqlFieldInfo(\mysqli_result $result, $field, $what) { if (!\mysqli_data_seek($result, $field)) { trigger_error( @@ -560,7 +563,7 @@ namespace Dshafik { $matches[$what] = null; } if ($what == 'length') { - return static::getFieldLength($matches[$what], $field['Type']); + return static::getFieldLength($matches[$what], $field['Type']); } return static::getFieldType($matches[$what]); case "flags": @@ -604,7 +607,7 @@ namespace Dshafik { return false; } - static function checkValidResult($result, $function) + public static function checkValidResult($result, $function) { if (!($result instanceof \mysqli_result)) { trigger_error( |