summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.gitignore2
-rw-r--r--Dockerfile17
-rw-r--r--README.md27
-rw-r--r--composer.json21
-rw-r--r--composer.lock1057
-rw-r--r--lib/mysql.php416
-rw-r--r--phpunit.xml.dist20
-rw-r--r--tests/MySqlShimTest.php204
-rw-r--r--tests/bootstrap.php2
9 files changed, 1766 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..e9418d0
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,2 @@
+build/
+vendor/
diff --git a/Dockerfile b/Dockerfile
new file mode 100644
index 0000000..6d40336
--- /dev/null
+++ b/Dockerfile
@@ -0,0 +1,17 @@
+FROM oraclelinux:latest
+ENV PACKAGE_URL https://repo.mysql.com/yum/mysql-5.7-community/docker/x86_64/mysql-community-server-minimal-5.7.9-1.el7.x86_64.rpm
+
+# Install server
+RUN rpmkeys --import http://repo.mysql.com/RPM-GPG-KEY-mysql \
+ && yum install -y $PACKAGE_URL \
+ && yum install -y libpwquality \
+ && rm -rf /var/cache/yum/*
+RUN mkdir /docker-entrypoint-initdb.d
+
+VOLUME /var/lib/mysql
+
+COPY docker-entrypoint.sh /entrypoint.sh
+ENTRYPOINT ["/entrypoint.sh"]
+
+EXPOSE 3306
+CMD ["mysqld"]
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..8abfae5
--- /dev/null
+++ b/README.md
@@ -0,0 +1,27 @@
+# PHP 7 Shim for ext/mysql
+
+This library attempts to create a drop-in replacement for ext/mysql on PHP 7 using mysqli.
+
+For the most part, it should _just work_, although you either need to prefix all calls with a `\` (only internal functions will fallback to the global scope)
+or import the functions into every file (e.g. `use function \mysql_connect`).
+
+## Installation
+
+To install, either add `dshafik/php7-mysql-shim` to your `composer.json`:
+
+```sh
+$ composer require dshafik/php7-mysql-shim
+```
+
+or, clone/download this repo, and include `mysql.php` in your project.
+
+## Usage
+
+Once the file is included, it will create `mysql_*` function if they don't already exist.
+
+## 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`.
diff --git a/composer.json b/composer.json
new file mode 100644
index 0000000..4330c57
--- /dev/null
+++ b/composer.json
@@ -0,0 +1,21 @@
+{
+ "name": "dshafik/php7-mysql-shim",
+ "description": "A PHP 7 shim for ext/mysql",
+ "license": "Apache 2.0",
+ "authors": [
+ {
+ "name": "Davey Shafik",
+ "email": "me@daveyshafik.com",
+ "homepage": "https://daveyshafik.com"
+ }
+ ],
+ "require": {
+ "php": ">= 7.0"
+ },
+ "require-dev": {
+ "phpunit/phpunit": "~5.1"
+ },
+ "autoload": {
+ "files": ["lib/mysql.php"]
+ }
+}
diff --git a/composer.lock b/composer.lock
new file mode 100644
index 0000000..83d5a1e
--- /dev/null
+++ b/composer.lock
@@ -0,0 +1,1057 @@
+{
+ "_readme": [
+ "This file locks the dependencies of your project to a known state",
+ "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
+ "This file is @generated automatically"
+ ],
+ "hash": "d013d162a236a506068e204c5cb14353",
+ "packages": [],
+ "packages-dev": [
+ {
+ "name": "doctrine/instantiator",
+ "version": "1.0.5",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/doctrine/instantiator.git",
+ "reference": "8e884e78f9f0eb1329e445619e04456e64d8051d"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/doctrine/instantiator/zipball/8e884e78f9f0eb1329e445619e04456e64d8051d",
+ "reference": "8e884e78f9f0eb1329e445619e04456e64d8051d",
+ "shasum": ""
+ },
+ "require": {
+ "php": ">=5.3,<8.0-DEV"
+ },
+ "require-dev": {
+ "athletic/athletic": "~0.1.8",
+ "ext-pdo": "*",
+ "ext-phar": "*",
+ "phpunit/phpunit": "~4.0",
+ "squizlabs/php_codesniffer": "~2.0"
+ },
+ "type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "1.0.x-dev"
+ }
+ },
+ "autoload": {
+ "psr-4": {
+ "Doctrine\\Instantiator\\": "src/Doctrine/Instantiator/"
+ }
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "Marco Pivetta",
+ "email": "ocramius@gmail.com",
+ "homepage": "http://ocramius.github.com/"
+ }
+ ],
+ "description": "A small, lightweight utility to instantiate objects in PHP without invoking their constructors",
+ "homepage": "https://github.com/doctrine/instantiator",
+ "keywords": [
+ "constructor",
+ "instantiate"
+ ],
+ "time": "2015-06-14 21:17:01"
+ },
+ {
+ "name": "myclabs/deep-copy",
+ "version": "1.5.0",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/myclabs/DeepCopy.git",
+ "reference": "e3abefcd7f106677fd352cd7c187d6c969aa9ddc"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/e3abefcd7f106677fd352cd7c187d6c969aa9ddc",
+ "reference": "e3abefcd7f106677fd352cd7c187d6c969aa9ddc",
+ "shasum": ""
+ },
+ "require": {
+ "php": ">=5.4.0"
+ },
+ "require-dev": {
+ "doctrine/collections": "1.*",
+ "phpunit/phpunit": "~4.1"
+ },
+ "type": "library",
+ "autoload": {
+ "psr-4": {
+ "DeepCopy\\": "src/DeepCopy/"
+ }
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "description": "Create deep copies (clones) of your objects",
+ "homepage": "https://github.com/myclabs/DeepCopy",
+ "keywords": [
+ "clone",
+ "copy",
+ "duplicate",
+ "object",
+ "object graph"
+ ],
+ "time": "2015-11-07 22:20:37"
+ },
+ {
+ "name": "phpdocumentor/reflection-docblock",
+ "version": "2.0.4",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/phpDocumentor/ReflectionDocBlock.git",
+ "reference": "d68dbdc53dc358a816f00b300704702b2eaff7b8"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/d68dbdc53dc358a816f00b300704702b2eaff7b8",
+ "reference": "d68dbdc53dc358a816f00b300704702b2eaff7b8",
+ "shasum": ""
+ },
+ "require": {
+ "php": ">=5.3.3"
+ },
+ "require-dev": {
+ "phpunit/phpunit": "~4.0"
+ },
+ "suggest": {
+ "dflydev/markdown": "~1.0",
+ "erusev/parsedown": "~1.0"
+ },
+ "type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "2.0.x-dev"
+ }
+ },
+ "autoload": {
+ "psr-0": {
+ "phpDocumentor": [
+ "src/"
+ ]
+ }
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "Mike van Riel",
+ "email": "mike.vanriel@naenius.com"
+ }
+ ],
+ "time": "2015-02-03 12:10:50"
+ },
+ {
+ "name": "phpspec/prophecy",
+ "version": "v1.5.0",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/phpspec/prophecy.git",
+ "reference": "4745ded9307786b730d7a60df5cb5a6c43cf95f7"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/phpspec/prophecy/zipball/4745ded9307786b730d7a60df5cb5a6c43cf95f7",
+ "reference": "4745ded9307786b730d7a60df5cb5a6c43cf95f7",
+ "shasum": ""
+ },
+ "require": {
+ "doctrine/instantiator": "^1.0.2",
+ "phpdocumentor/reflection-docblock": "~2.0",
+ "sebastian/comparator": "~1.1"
+ },
+ "require-dev": {
+ "phpspec/phpspec": "~2.0"
+ },
+ "type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "1.4.x-dev"
+ }
+ },
+ "autoload": {
+ "psr-0": {
+ "Prophecy\\": "src/"
+ }
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "Konstantin Kudryashov",
+ "email": "ever.zet@gmail.com",
+ "homepage": "http://everzet.com"
+ },
+ {
+ "name": "Marcello Duarte",
+ "email": "marcello.duarte@gmail.com"
+ }
+ ],
+ "description": "Highly opinionated mocking framework for PHP 5.3+",
+ "homepage": "https://github.com/phpspec/prophecy",
+ "keywords": [
+ "Double",
+ "Dummy",
+ "fake",
+ "mock",
+ "spy",
+ "stub"
+ ],
+ "time": "2015-08-13 10:07:40"
+ },
+ {
+ "name": "phpunit/php-code-coverage",
+ "version": "3.0.2",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/sebastianbergmann/php-code-coverage.git",
+ "reference": "f7bb5cddf4ffe113eeb737b05241adb947b43f9d"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/f7bb5cddf4ffe113eeb737b05241adb947b43f9d",
+ "reference": "f7bb5cddf4ffe113eeb737b05241adb947b43f9d",
+ "shasum": ""
+ },
+ "require": {
+ "php": ">=5.6",
+ "phpunit/php-file-iterator": "~1.3",
+ "phpunit/php-text-template": "~1.2",
+ "phpunit/php-token-stream": "~1.3",
+ "sebastian/environment": "^1.3.2",
+ "sebastian/version": "~1.0"
+ },
+ "require-dev": {
+ "ext-xdebug": ">=2.1.4",
+ "phpunit/phpunit": "~5"
+ },
+ "suggest": {
+ "ext-dom": "*",
+ "ext-xdebug": ">=2.2.1",
+ "ext-xmlwriter": "*"
+ },
+ "type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "3.0.x-dev"
+ }
+ },
+ "autoload": {
+ "classmap": [
+ "src/"
+ ]
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "BSD-3-Clause"
+ ],
+ "authors": [
+ {
+ "name": "Sebastian Bergmann",
+ "email": "sb@sebastian-bergmann.de",
+ "role": "lead"
+ }
+ ],
+ "description": "Library that provides collection, processing, and rendering functionality for PHP code coverage information.",
+ "homepage": "https://github.com/sebastianbergmann/php-code-coverage",
+ "keywords": [
+ "coverage",
+ "testing",
+ "xunit"
+ ],
+ "time": "2015-11-12 21:08:20"
+ },
+ {
+ "name": "phpunit/php-file-iterator",
+ "version": "1.4.1",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/sebastianbergmann/php-file-iterator.git",
+ "reference": "6150bf2c35d3fc379e50c7602b75caceaa39dbf0"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/6150bf2c35d3fc379e50c7602b75caceaa39dbf0",
+ "reference": "6150bf2c35d3fc379e50c7602b75caceaa39dbf0",
+ "shasum": ""
+ },
+ "require": {
+ "php": ">=5.3.3"
+ },
+ "type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "1.4.x-dev"
+ }
+ },
+ "autoload": {
+ "classmap": [
+ "src/"
+ ]
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "BSD-3-Clause"
+ ],
+ "authors": [
+ {
+ "name": "Sebastian Bergmann",
+ "email": "sb@sebastian-bergmann.de",
+ "role": "lead"
+ }
+ ],
+ "description": "FilterIterator implementation that filters files based on a list of suffixes.",
+ "homepage": "https://github.com/sebastianbergmann/php-file-iterator/",
+ "keywords": [
+ "filesystem",
+ "iterator"
+ ],
+ "time": "2015-06-21 13:08:43"
+ },
+ {
+ "name": "phpunit/php-text-template",
+ "version": "1.2.1",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/sebastianbergmann/php-text-template.git",
+ "reference": "31f8b717e51d9a2afca6c9f046f5d69fc27c8686"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/sebastianbergmann/php-text-template/zipball/31f8b717e51d9a2afca6c9f046f5d69fc27c8686",
+ "reference": "31f8b717e51d9a2afca6c9f046f5d69fc27c8686",
+ "shasum": ""
+ },
+ "require": {
+ "php": ">=5.3.3"
+ },
+ "type": "library",
+ "autoload": {
+ "classmap": [
+ "src/"
+ ]
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "BSD-3-Clause"
+ ],
+ "authors": [
+ {
+ "name": "Sebastian Bergmann",
+ "email": "sebastian@phpunit.de",
+ "role": "lead"
+ }
+ ],
+ "description": "Simple template engine.",
+ "homepage": "https://github.com/sebastianbergmann/php-text-template/",
+ "keywords": [
+ "template"
+ ],
+ "time": "2015-06-21 13:50:34"
+ },
+ {
+ "name": "phpunit/php-timer",
+ "version": "1.0.7",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/sebastianbergmann/php-timer.git",
+ "reference": "3e82f4e9fc92665fafd9157568e4dcb01d014e5b"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/3e82f4e9fc92665fafd9157568e4dcb01d014e5b",
+ "reference": "3e82f4e9fc92665fafd9157568e4dcb01d014e5b",
+ "shasum": ""
+ },
+ "require": {
+ "php": ">=5.3.3"
+ },
+ "type": "library",
+ "autoload": {
+ "classmap": [
+ "src/"
+ ]
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "BSD-3-Clause"
+ ],
+ "authors": [
+ {
+ "name": "Sebastian Bergmann",
+ "email": "sb@sebastian-bergmann.de",
+ "role": "lead"
+ }
+ ],
+ "description": "Utility class for timing",
+ "homepage": "https://github.com/sebastianbergmann/php-timer/",
+ "keywords": [
+ "timer"
+ ],
+ "time": "2015-06-21 08:01:12"
+ },
+ {
+ "name": "phpunit/php-token-stream",
+ "version": "1.4.8",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/sebastianbergmann/php-token-stream.git",
+ "reference": "3144ae21711fb6cac0b1ab4cbe63b75ce3d4e8da"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/3144ae21711fb6cac0b1ab4cbe63b75ce3d4e8da",
+ "reference": "3144ae21711fb6cac0b1ab4cbe63b75ce3d4e8da",
+ "shasum": ""
+ },
+ "require": {
+ "ext-tokenizer": "*",
+ "php": ">=5.3.3"
+ },
+ "require-dev": {
+ "phpunit/phpunit": "~4.2"
+ },
+ "type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "1.4-dev"
+ }
+ },
+ "autoload": {
+ "classmap": [
+ "src/"
+ ]
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "BSD-3-Clause"
+ ],
+ "authors": [
+ {
+ "name": "Sebastian Bergmann",
+ "email": "sebastian@phpunit.de"
+ }
+ ],
+ "description": "Wrapper around PHP's tokenizer extension.",
+ "homepage": "https://github.com/sebastianbergmann/php-token-stream/",
+ "keywords": [
+ "tokenizer"
+ ],
+ "time": "2015-09-15 10:49:45"
+ },
+ {
+ "name": "phpunit/phpunit",
+ "version": "5.1.0",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/sebastianbergmann/phpunit.git",
+ "reference": "01fb97441708f1616a97cfd3f5c36101db81c635"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/01fb97441708f1616a97cfd3f5c36101db81c635",
+ "reference": "01fb97441708f1616a97cfd3f5c36101db81c635",
+ "shasum": ""
+ },
+ "require": {
+ "ext-dom": "*",
+ "ext-json": "*",
+ "ext-pcre": "*",
+ "ext-reflection": "*",
+ "ext-spl": "*",
+ "myclabs/deep-copy": "~1.3",
+ "php": ">=5.6",
+ "phpspec/prophecy": "^1.3.1",
+ "phpunit/php-code-coverage": "~3.0",
+ "phpunit/php-file-iterator": "~1.4",
+ "phpunit/php-text-template": "~1.2",
+ "phpunit/php-timer": ">=1.0.6",
+ "phpunit/phpunit-mock-objects": ">=3.0",
+ "sebastian/comparator": "~1.1",
+ "sebastian/diff": "~1.2",
+ "sebastian/environment": "~1.3",
+ "sebastian/exporter": "~1.2",
+ "sebastian/global-state": "~1.0",
+ "sebastian/resource-operations": "~1.0",
+ "sebastian/version": "~1.0",
+ "symfony/yaml": "~2.1|~3.0"
+ },
+ "suggest": {
+ "phpunit/php-invoker": "~1.1"
+ },
+ "bin": [
+ "phpunit"
+ ],
+ "type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "5.1.x-dev"
+ }
+ },
+ "autoload": {
+ "classmap": [
+ "src/"
+ ]
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "BSD-3-Clause"
+ ],
+ "authors": [
+ {
+ "name": "Sebastian Bergmann",
+ "email": "sebastian@phpunit.de",
+ "role": "lead"
+ }
+ ],
+ "description": "The PHP Unit Testing framework.",
+ "homepage": "https://phpunit.de/",
+ "keywords": [
+ "phpunit",
+ "testing",
+ "xunit"
+ ],
+ "time": "2015-12-03 16:45:01"
+ },
+ {
+ "name": "phpunit/phpunit-mock-objects",
+ "version": "3.0.4",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/sebastianbergmann/phpunit-mock-objects.git",
+ "reference": "b28b029356e65091dfbf8c2bc4ef106ffece509e"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/b28b029356e65091dfbf8c2bc4ef106ffece509e",
+ "reference": "b28b029356e65091dfbf8c2bc4ef106ffece509e",
+ "shasum": ""
+ },
+ "require": {
+ "doctrine/instantiator": "^1.0.2",
+ "php": ">=5.6",
+ "phpunit/php-text-template": "~1.2",
+ "sebastian/exporter": "~1.2"
+ },
+ "require-dev": {
+ "phpunit/phpunit": "~5"
+ },
+ "suggest": {
+ "ext-soap": "*"
+ },
+ "type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "3.0.x-dev"
+ }
+ },
+ "autoload": {
+ "classmap": [
+ "src/"
+ ]
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "BSD-3-Clause"
+ ],
+ "authors": [
+ {
+ "name": "Sebastian Bergmann",
+ "email": "sb@sebastian-bergmann.de",
+ "role": "lead"
+ }
+ ],
+ "description": "Mock Object library for PHPUnit",
+ "homepage": "https://github.com/sebastianbergmann/phpunit-mock-objects/",
+ "keywords": [
+ "mock",
+ "xunit"
+ ],
+ "time": "2015-11-09 15:37:17"
+ },
+ {
+ "name": "sebastian/comparator",
+ "version": "1.2.0",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/sebastianbergmann/comparator.git",
+ "reference": "937efb279bd37a375bcadf584dec0726f84dbf22"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/937efb279bd37a375bcadf584dec0726f84dbf22",
+ "reference": "937efb279bd37a375bcadf584dec0726f84dbf22",
+ "shasum": ""
+ },
+ "require": {
+ "php": ">=5.3.3",
+ "sebastian/diff": "~1.2",
+ "sebastian/exporter": "~1.2"
+ },
+ "require-dev": {
+ "phpunit/phpunit": "~4.4"
+ },
+ "type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "1.2.x-dev"
+ }
+ },
+ "autoload": {
+ "classmap": [
+ "src/"
+ ]
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "BSD-3-Clause"
+ ],
+ "authors": [
+ {
+ "name": "Jeff Welch",
+ "email": "whatthejeff@gmail.com"
+ },
+ {
+ "name": "Volker Dusch",
+ "email": "github@wallbash.com"
+ },
+ {
+ "name": "Bernhard Schussek",
+ "email": "bschussek@2bepublished.at"
+ },
+ {
+ "name": "Sebastian Bergmann",
+ "email": "sebastian@phpunit.de"
+ }
+ ],
+ "description": "Provides the functionality to compare PHP values for equality",
+ "homepage": "http://www.github.com/sebastianbergmann/comparator",
+ "keywords": [
+ "comparator",
+ "compare",
+ "equality"
+ ],
+ "time": "2015-07-26 15:48:44"
+ },
+ {
+ "name": "sebastian/diff",
+ "version": "1.3.0",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/sebastianbergmann/diff.git",
+ "reference": "863df9687835c62aa423a22412d26fa2ebde3fd3"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/863df9687835c62aa423a22412d26fa2ebde3fd3",
+ "reference": "863df9687835c62aa423a22412d26fa2ebde3fd3",
+ "shasum": ""
+ },
+ "require": {
+ "php": ">=5.3.3"
+ },
+ "require-dev": {
+ "phpunit/phpunit": "~4.2"
+ },
+ "type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "1.3-dev"
+ }
+ },
+ "autoload": {
+ "classmap": [
+ "src/"
+ ]
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "BSD-3-Clause"
+ ],
+ "authors": [
+ {
+ "name": "Kore Nordmann",
+ "email": "mail@kore-nordmann.de"
+ },
+ {
+ "name": "Sebastian Bergmann",
+ "email": "sebastian@phpunit.de"
+ }
+ ],
+ "description": "Diff implementation",
+ "homepage": "http://www.github.com/sebastianbergmann/diff",
+ "keywords": [
+ "diff"
+ ],
+ "time": "2015-02-22 15:13:53"
+ },
+ {
+ "name": "sebastian/environment",
+ "version": "1.3.3",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/sebastianbergmann/environment.git",
+ "reference": "6e7133793a8e5a5714a551a8324337374be209df"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/6e7133793a8e5a5714a551a8324337374be209df",
+ "reference": "6e7133793a8e5a5714a551a8324337374be209df",
+ "shasum": ""
+ },
+ "require": {
+ "php": ">=5.3.3"
+ },
+ "require-dev": {
+ "phpunit/phpunit": "~4.4"
+ },
+ "type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "1.3.x-dev"
+ }
+ },
+ "autoload": {
+ "classmap": [
+ "src/"
+ ]
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "BSD-3-Clause"
+ ],
+ "authors": [
+ {
+ "name": "Sebastian Bergmann",
+ "email": "sebastian@phpunit.de"
+ }
+ ],
+ "description": "Provides functionality to handle HHVM/PHP environments",
+ "homepage": "http://www.github.com/sebastianbergmann/environment",
+ "keywords": [
+ "Xdebug",
+ "environment",
+ "hhvm"
+ ],
+ "time": "2015-12-02 08:37:27"
+ },
+ {
+ "name": "sebastian/exporter",
+ "version": "1.2.1",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/sebastianbergmann/exporter.git",
+ "reference": "7ae5513327cb536431847bcc0c10edba2701064e"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/7ae5513327cb536431847bcc0c10edba2701064e",
+ "reference": "7ae5513327cb536431847bcc0c10edba2701064e",
+ "shasum": ""
+ },
+ "require": {
+ "php": ">=5.3.3",
+ "sebastian/recursion-context": "~1.0"
+ },
+ "require-dev": {
+ "phpunit/phpunit": "~4.4"
+ },
+ "type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "1.2.x-dev"
+ }
+ },
+ "autoload": {
+ "classmap": [
+ "src/"
+ ]
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "BSD-3-Clause"
+ ],
+ "authors": [
+ {
+ "name": "Jeff Welch",
+ "email": "whatthejeff@gmail.com"
+ },
+ {
+ "name": "Volker Dusch",
+ "email": "github@wallbash.com"
+ },
+ {
+ "name": "Bernhard Schussek",
+ "email": "bschussek@2bepublished.at"
+ },
+ {
+ "name": "Sebastian Bergmann",
+ "email": "sebastian@phpunit.de"
+ },
+ {
+ "name": "Adam Harvey",
+ "email": "aharvey@php.net"
+ }
+ ],
+ "description": "Provides the functionality to export PHP variables for visualization",
+ "homepage": "http://www.github.com/sebastianbergmann/exporter",
+ "keywords": [
+ "export",
+ "exporter"
+ ],
+ "time": "2015-06-21 07:55:53"
+ },
+ {
+ "name": "sebastian/global-state",
+ "version": "1.1.1",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/sebastianbergmann/global-state.git",
+ "reference": "bc37d50fea7d017d3d340f230811c9f1d7280af4"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/bc37d50fea7d017d3d340f230811c9f1d7280af4",
+ "reference": "bc37d50fea7d017d3d340f230811c9f1d7280af4",
+ "shasum": ""
+ },
+ "require": {
+ "php": ">=5.3.3"
+ },
+ "require-dev": {
+ "phpunit/phpunit": "~4.2"
+ },
+ "suggest": {
+ "ext-uopz": "*"
+ },
+ "type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "1.0-dev"
+ }
+ },
+ "autoload": {
+ "classmap": [
+ "src/"
+ ]
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "BSD-3-Clause"
+ ],
+ "authors": [
+ {
+ "name": "Sebastian Bergmann",
+ "email": "sebastian@phpunit.de"
+ }
+ ],
+ "description": "Snapshotting of global state",
+ "homepage": "http://www.github.com/sebastianbergmann/global-state",
+ "keywords": [
+ "global state"
+ ],
+ "time": "2015-10-12 03:26:01"
+ },
+ {
+ "name": "sebastian/recursion-context",
+ "version": "1.0.1",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/sebastianbergmann/recursion-context.git",
+ "reference": "994d4a811bafe801fb06dccbee797863ba2792ba"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/994d4a811bafe801fb06dccbee797863ba2792ba",
+ "reference": "994d4a811bafe801fb06dccbee797863ba2792ba",
+ "shasum": ""
+ },
+ "require": {
+ "php": ">=5.3.3"
+ },
+ "require-dev": {
+ "phpunit/phpunit": "~4.4"
+ },
+ "type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "1.0.x-dev"
+ }
+ },
+ "autoload": {
+ "classmap": [
+ "src/"
+ ]
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "BSD-3-Clause"
+ ],
+ "authors": [
+ {
+ "name": "Jeff Welch",
+ "email": "whatthejeff@gmail.com"
+ },
+ {
+ "name": "Sebastian Bergmann",
+ "email": "sebastian@phpunit.de"
+ },
+ {
+ "name": "Adam Harvey",
+ "email": "aharvey@php.net"
+ }
+ ],
+ "description": "Provides functionality to recursively process PHP variables",
+ "homepage": "http://www.github.com/sebastianbergmann/recursion-context",
+ "time": "2015-06-21 08:04:50"
+ },
+ {
+ "name": "sebastian/resource-operations",
+ "version": "1.0.0",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/sebastianbergmann/resource-operations.git",
+ "reference": "ce990bb21759f94aeafd30209e8cfcdfa8bc3f52"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/sebastianbergmann/resource-operations/zipball/ce990bb21759f94aeafd30209e8cfcdfa8bc3f52",
+ "reference": "ce990bb21759f94aeafd30209e8cfcdfa8bc3f52",
+ "shasum": ""
+ },
+ "require": {
+ "php": ">=5.6.0"
+ },
+ "type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "1.0.x-dev"
+ }
+ },
+ "autoload": {
+ "classmap": [
+ "src/"
+ ]
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "BSD-3-Clause"
+ ],
+ "authors": [
+ {
+ "name": "Sebastian Bergmann",
+ "email": "sebastian@phpunit.de"
+ }
+ ],
+ "description": "Provides a list of PHP built-in functions that operate on resources",
+ "homepage": "https://www.github.com/sebastianbergmann/resource-operations",
+ "time": "2015-07-28 20:34:47"
+ },
+ {
+ "name": "sebastian/version",
+ "version": "1.0.6",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/sebastianbergmann/version.git",
+ "reference": "58b3a85e7999757d6ad81c787a1fbf5ff6c628c6"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/sebastianbergmann/version/zipball/58b3a85e7999757d6ad81c787a1fbf5ff6c628c6",
+ "reference": "58b3a85e7999757d6ad81c787a1fbf5ff6c628c6",
+ "shasum": ""
+ },
+ "type": "library",
+ "autoload": {
+ "classmap": [
+ "src/"
+ ]
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "BSD-3-Clause"
+ ],
+ "authors": [
+ {
+ "name": "Sebastian Bergmann",
+ "email": "sebastian@phpunit.de",
+ "role": "lead"
+ }
+ ],
+ "description": "Library that helps with managing the version number of Git-hosted PHP projects",
+ "homepage": "https://github.com/sebastianbergmann/version",
+ "time": "2015-06-21 13:59:46"
+ },
+ {
+ "name": "symfony/yaml",
+ "version": "v3.0.0",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/symfony/yaml.git",
+ "reference": "177a015cb0e19ff4a49e0e2e2c5fc1c1bee07002"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/symfony/yaml/zipball/177a015cb0e19ff4a49e0e2e2c5fc1c1bee07002",
+ "reference": "177a015cb0e19ff4a49e0e2e2c5fc1c1bee07002",
+ "shasum": ""
+ },
+ "require": {
+ "php": ">=5.5.9"
+ },
+ "type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "3.0-dev"
+ }
+ },
+ "autoload": {
+ "psr-4": {
+ "Symfony\\Component\\Yaml\\": ""
+ },
+ "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 Yaml Component",
+ "homepage": "https://symfony.com",
+ "time": "2015-11-30 12:36:17"
+ }
+ ],
+ "aliases": [],
+ "minimum-stability": "stable",
+ "stability-flags": [],
+ "prefer-stable": false,
+ "prefer-lowest": false,
+ "platform": {
+ "php": "~5.6"
+ },
+ "platform-dev": []
+}
diff --git a/lib/mysql.php b/lib/mysql.php
new file mode 100644
index 0000000..ecfb767
--- /dev/null
+++ b/lib/mysql.php
@@ -0,0 +1,416 @@
+<?php
+namespace {
+ if (!function_exists('\mysql_connect')) {
+ function mysql_connect(
+ $hostname = null,
+ $username = null,
+ $password = null,
+ $new = false,
+ $flags = 0)
+ {
+ if ($new !== false) {
+ trigger_error('Argument $new is no longer supported in PHP > 7', E_USER_WARNING);
+ }
+
+ if ($flags === 0) {
+ $conn = \Dshafik\MySQL::$last_connection = mysqli_connect($hostname, $username, $password);
+ return $conn;
+ }
+
+ try {
+ $conn = \Dshafik\MySQL::$last_connection = mysqli_init();
+
+ mysqli_options($conn, $flags);
+
+ mysqli_real_connect($conn, $hostname, $username, $password);
+
+ return $conn;
+ } catch (\Throwable $e) {
+ var_dump($e);
+ }
+ }
+
+ function mysql_pconnect(
+ $hostname = null,
+ $username = null,
+ $password = null,
+ $flags = 0)
+ {
+ $hostname = 'p:' . $hostname;
+ return mysql_connect($hostname, $username, $password, false, $flags);
+ }
+
+ function mysql_close(\mysqli $link = null)
+ {
+ $isDefault = ($link === null);
+
+ $link = \Dshafik\MySQL::getConnection($link, __FUNCTION__);
+ if ($link === null) {
+ return false;
+ }
+
+ $return = mysqli_close($link);
+ if ($isDefault) {
+ Dshafik\MySQL::$last_connection = null;
+ }
+ return $return;
+ }
+
+ function mysql_select_db($databaseName, \mysqli $link = null)
+ {
+ $link = \Dshafik\MySQL::getConnection($link);
+
+ return mysqli_query(
+ $link,
+ "USE " . mysqli_real_escape_string($link)
+ ) !== false;
+ }
+
+ function mysql_query($query, \mysqli $link = null)
+ {
+ return mysqli_query(\Dshafik\MySQL::getConnection($link), $query);
+ }
+
+ function mysql_unbuffered_query($query, \mysqli $link = null)
+ {
+ $link = \Dshafik\MySQL::getConnection($link);
+ mysqli_real_query($link, $query);
+ return $link;
+ }
+
+ function mysql_db_query($databaseName, $query, \mysqli $link = null)
+ {
+ mysql_select_db($databaseName, $link);
+ return mysql_query($query, $link);
+ }
+
+ function mysql_list_dbs(\mysqli $link = null)
+ {
+ return mysql_query("SHOW DATABASES", $link);
+ }
+
+ function mysql_list_tables(\mysqli $link = null)
+ {
+ return mysql_query("SHOW TABLES", \Dshafik\MySQL::getConnection($link));
+ }
+
+ function mysql_list_fields($databaseName, $tableName, \mysqli $link = null)
+ {
+ $link = \Dshafik\MySQL::getConnection($link);
+ return mysql_query(
+ "SHOW COLUMNS FROM " .
+ mysqli_real_escape_string($link, $databaseName) . "." .
+ mysqli_real_escape_string($link, $tableName),
+ $link
+ );
+ }
+
+ function mysql_list_processes(\mysqli $link = null)
+ {
+ return mysql_query("SHOW PROCESSLIST", $link);
+ }
+
+ function mysql_error(\mysqli $link = null)
+ {
+ return mysqli_error(\Dshafik\MySQL::getConnection($link));
+ }
+
+ function mysql_errno(\mysqli $link = null)
+ {
+ return mysqli_errno(\Dshafik\MySQL::getConnection($link));
+ }
+
+ function mysql_affected_rows(\mysqli $link = null)
+ {
+ return mysqli_affected_rows(\Dshafik\MySQL::getConnection($link));
+ }
+
+ function mysql_insert_id($link = null) /*|*/
+ {
+ return mysqli_insert_id(\Dshafik\MySQL::getConnection($link));
+ }
+
+ function mysql_result(\mysqli_result $result, $row, $field = 0)
+ {
+ if (!mysqli_data_seek($result, $row)) {
+ return false;
+ }
+
+ if ($row = mysqli_fetch_array($result) === false) {
+ return false;
+ }
+
+ if (isset($row[$field])) {
+ return $row[$field];
+ }
+
+ return false;
+ }
+
+ function mysql_num_rows(\mysqli_result $result)
+ {
+ return mysqli_num_rows($result);
+ }
+
+ function mysql_num_fields(\mysqli_result $result)
+ {
+ return mysqli_num_fields($result);
+ }
+
+ function mysql_fetch_row(\mysqli_result $result) /* : array|null */
+ {
+ return mysqli_fetch_row($result);
+ }
+
+ function mysql_fetch_array(\mysqli_result $result) /* : array|null */
+ {
+ return mysqli_fetch_array($result);
+ }
+
+ function mysql_fetch_assoc(\mysqli_result $result) /* : array|null */
+ {
+ return mysqli_fetch_assoc($result);
+ }
+
+ function mysql_fetch_object(\mysqli_result $result, $class, array $params = []) /* : object|null */
+ {
+ return mysqli_fetch_object($result, $class, $params);
+ }
+
+ function mysql_data_seek(\mysqli_result $result, $offset)
+ {
+ return mysqli_data_seek($result, $offset);
+ }
+
+ function mysql_fetch_lengths(\mysqli_result $result) /* : array|*/
+ {
+ return mysqli_fetch_lengths($result);
+ }
+
+ function mysql_fetch_field(\mysqli_result $result) /* : object|*/
+ {
+ return mysqli_fetch_field($result);
+ }
+
+ function mysql_field_seek(\mysqli_result $result, $field)
+ {
+ return mysqli_field_seek($result, $field);
+ }
+
+ function mysql_free_result(\mysqli_result $result)
+ {
+ return mysqli_free_result($result);
+ }
+
+ function mysql_field_name(\mysqli_result $result, $field)
+ {
+ return \Dshafik\MySQL::mysql_field_info($result, $field, 'name');
+ }
+
+ function mysql_field_table(\mysqli_result $result, $field)
+ {
+ return \Dshafik\MySQL::mysql_field_info($result, $field, 'table');
+ }
+
+ function mysql_field_len(\mysql_result $result, $field)
+ {
+ return \Dshafik\MySQL::mysql_field_info($result, $field, 'length');
+ }
+
+ function mysql_field_type(\mysql_result $result, $field)
+ {
+ return \Dshafik\MySQL::mysql_field_info($result, $field, 'type');
+ }
+
+ function mysql_field_flags(\mysql_result $result, $field)
+ {
+ return \Dshafik\MySQL::mysql_field_info($result, $field, 'flags');
+ }
+
+ function mysql_escape_string($unescapedString)
+ {
+ return mysql_real_escape_string($unescapedString, null);
+ }
+
+ function mysql_real_escape_string($unescapedString, \mysqli $link = null)
+ {
+ return mysqli_escape_string(\Dshafik\MySQL::getConnection($link), $unescapedString);
+ }
+
+ function mysql_stat(\mysqli $link = null)
+ {
+ return mysqli_stat(\Dshafik\MySQL::getConnection($link));
+ }
+
+ function mysql_thread_id(\mysqli $link = null)
+ {
+ return mysqli_thread_id(\Dshafik\MySQL::getConnection($link));
+ }
+
+ function mysql_client_encoding(\mysqli $link = null)
+ {
+ return mysqli_character_set_name(\Dshafik\MySQL::getConnection($link));
+ }
+
+ function mysql_ping(\mysqli $link = null)
+ {
+ return mysqli_ping($link);
+ }
+
+ function mysql_get_client_info(\mysqli $link = null)
+ {
+ return mysqli_get_client_info(\Dshafik\MySQL::getConnection($link));
+ }
+
+ function mysql_get_host_info(\mysqli $link = null)
+ {
+ return mysqli_get_host_info(\Dshafik\MySQL::getConnection($link));
+ }
+
+ function mysql_get_proto_info(\mysqli $link = null)
+ {
+ return mysqli_get_proto_info(\Dshafik\MySQL::getConnection($link));
+ }
+
+ function mysql_get_server_info(\mysqli $link = null)
+ {
+ return mysqli_get_server_info(\Dshafik\MySQL::getConnection($link));
+ }
+
+ function mysql_info(\mysqli $link = null)
+ {
+ return mysqli_info(\Dshafik\MySQL::getConnection($link));
+ }
+
+ function mysql_set_charset($charset, \mysqli $link = null)
+ {
+ return mysqli_set_charset(\Dshafik\MySQL::getConnection($link), $charset);
+ }
+
+ function mysql_db_name(\mysqli_result $result)
+ {
+ return mysqli_fetch_row($result)['Database'];
+ }
+
+ function mysql_table_name(\mysqli_result $result)
+ {
+ return mysqli_fetch_row($result)['Table'];
+ }
+
+ /* Aliases */
+
+ function mysql_fieldname(\mysqli_result $result)
+ {
+ return mysql_field_name($result);
+ }
+
+ function mysql_fieldtable(\mysqli_result $result)
+ {
+ return mysql_field_table($result);
+ }
+
+ function mysql_fieldlen(\mysqli_result $result)
+ {
+ return mysql_field_len($result);
+ }
+
+ function mysql_fieldtype(\mysqli_result $result)
+ {
+ return mysql_field_type($result);
+ }
+
+ function mysql_fieldflags(\mysqli_result $result)
+ {
+ return mysql_field_flags($result);
+ }
+
+ function mysql_selectdb($databaseName, \mysql $link = null)
+ {
+ return mysql_select_db($databaseName, $link);
+ }
+
+ function mysql_freeresult(\mysqli_result $result)
+ {
+ return mysql_free_result($result);
+ }
+
+ function mysql_numfields(\mysqli_result $result)
+ {
+ return mysql_num_fields($result);
+ }
+
+ function mysql_numrows(\mysqli_result $result)
+ {
+ return mysql_num_rows($result);
+ }
+
+ function mysql_listdbs(... $args)
+ {
+ return mysql_list_dbs(... $args);
+ }
+
+ function mysql_listtables(... $args)
+ {
+ return mysql_list_tables(... $args);
+ }
+
+ function mysql_listfields(... $args)
+ {
+ return mysql_list_fields(... $args);
+ }
+
+ function mysql_dbname(\mysqli_result $result)
+ {
+ return mysql_db_name($result);
+ }
+
+ function mysql_tablename(\mysqli_result $result)
+ {
+ return mysql_table_name($result);
+ }
+ }
+}
+
+namespace Dshafik {
+ class MySQL {
+ static public $last_connection = null;
+
+ static public function getConnection($link = null, $func = null)
+ {
+ if ($link !== null) {
+ return $link;
+ }
+
+ if (static::$last_connection === null) {
+ $err = "A link to the server could not be established";
+ if ($func !== null) {
+ $err = $func . "(): no MySQL-Link resource supplied";
+ }
+ trigger_error($err, E_USER_WARNING);
+ }
+
+ return static::$last_connection;
+ }
+
+ static public function mysql_field_info(\mysqli_result $result, $field, $what)
+ {
+ $field = mysqli_fetch_field_direct($result, $field);
+ if ($field === false) {
+ trigger_error(
+ E_WARNING,
+ sprintf(
+ "Field %d is invalid for MySQL result index %s",
+ $field,
+ spl_object_hash($result)
+ )
+ );
+ }
+
+ if (isset($field->{$what})) {
+ return $field->{$what};
+ }
+
+ return false;
+ }
+ }
+}
diff --git a/phpunit.xml.dist b/phpunit.xml.dist
new file mode 100644
index 0000000..d4470de
--- /dev/null
+++ b/phpunit.xml.dist
@@ -0,0 +1,20 @@
+<phpunit colors="true" verbose="true" bootstrap="tests/bootstrap.php">
+ <php>
+ <ini name="display_errors" value="on"/>
+ </php>
+ <logging>
+ <log type="coverage-html" target="build/coverage/report"/>
+ <log type="coverage-xml" target="build/coverage/xml"/>
+ <log type="coverage-clover" target="build/coverage/coverage.clover"/>
+ </logging>
+ <testsuites>
+ <testsuite name="Unit Test">
+ <directory>./tests</directory>
+ </testsuite>
+ </testsuites>
+ <filter>
+ <whitelist processUncoveredFilesFromWhitelist="true">
+ <directory suffix=".php">./lib</directory>
+ </whitelist>
+ </filter>
+</phpunit>
diff --git a/tests/MySqlShimTest.php b/tests/MySqlShimTest.php
new file mode 100644
index 0000000..4739558
--- /dev/null
+++ b/tests/MySqlShimTest.php
@@ -0,0 +1,204 @@
+<?php
+/**
+ * php7-mysql-shim
+ *
+ * @author Davey Shafik <dshafik@akamai.com>
+ * @copyright Copyright 2015 Akamai Technologies, Inc. All rights reserved.
+ * @license Apache 2.0
+ * @link https://github.com/akamai-open/php7-mysql-shim
+ * @link https://developer.akamai.com
+ */
+
+namespace Dshafik\MySQL\Tests;
+
+use function \mysql_connect;
+
+class MySqlShimTest extends \PHPUnit_Framework_TestCase
+{
+ static $host;
+ static $container;
+ static $bin = [];
+
+ public function test_mysql_connect()
+ {
+ $mysql = mysql_connect(static::$host, 'root');
+
+ $this->assertTrue(
+ is_resource($mysql) && get_resource_type($mysql) == 'mysql link'
+ ||
+ $mysql instanceof \mysqli
+ );
+ }
+
+ /**
+ * @expectedException \PHPUnit_Framework_Error_Warning
+ * @expectedExceptionMessageRegExp /^mysql(i?)_connect\(\): (\(HY000\/1045\): )?Access denied for user ''@'(.*?)' \(using password: NO\)$/
+ */
+ public function test_mysql_connect_fail()
+ {
+ $mysql = mysql_connect(static::$host);
+
+ $this->assertFalse($mysql);
+ }
+
+ public function test_mysql_query()
+ {
+ \mysql_connect(static::$host, 'root');
+ $result = \mysql_query("SELECT VERSION()");
+
+ $this->assertTrue(
+ is_resource($result) && get_resource_type($result) == 'mysql result'
+ || $result instanceof \mysqli_result
+ );
+ }
+
+ public function test_mysql_query_nodata()
+ {
+ \mysql_connect(static::$host, 'root');
+ $result = \mysql_query("SET @test = 'foo'");
+
+ $this->assertTrue($result);
+ }
+
+ public function test_mysql_query_fail()
+ {
+ \mysql_connect(static::$host, 'root');
+ $result = \mysql_query("SELECT VERSION(");
+
+ $this->assertFalse($result);
+ }
+
+ public function test_mysql_fetch_array()
+ {
+ \mysql_connect(static::$host, 'root');
+
+ $result = \mysql_query("SELECT 'test' AS col");
+
+ $row = \mysql_fetch_array($result);
+ $this->assertTrue(is_array($row));
+ $this->assertArrayHasKey(0, $row);
+ $this->assertEquals($row[0], 'test');
+ $this->assertArrayHasKey('col', $row);
+ $this->assertEquals($row['col'], 'test');
+ }
+
+ public function test_mysql_fetch_array_multirow()
+ {
+ \mysql_connect(static::$host, 'root');
+
+ $result = \mysql_query("SHOW DATABASES");
+
+ while ($row = \mysql_fetch_array($result)) {
+ $this->assertTrue(is_array($row));
+ $this->assertArrayHasKey(0, $row);
+ $this->assertTrue(in_array($row[0], ["information_schema", "mysql", "performance_schema", "sys"]));
+ $this->assertArrayHasKey('Database', $row);
+ $this->assertTrue(in_array($row['Database'], ["information_schema", "mysql", "performance_schema", "sys"]));
+ }
+ }
+
+ public function test_mysql_num_rows()
+ {
+ \mysql_connect(static::$host, 'root');
+
+ $result = \mysql_query("SHOW DATABASES");
+
+ $this->assertEquals(4, \mysql_num_rows($result));
+ }
+
+ public function test_mysql_close()
+ {
+ \mysql_connect(static::$host, 'root');
+ $this->assertTrue(\mysql_close());
+ }
+
+ /**
+ * @expectedException \PHPUnit_Framework_Error_Warning
+ * @expectedExceptionMessage mysql_close(): no MySQL-Link resource supplied
+ */
+ public function test_mysql_close_fail()
+ {
+ $this->assertFalse(\mysql_close());
+ }
+
+ public function tearDown()
+ {
+ @\mysql_close();
+ }
+
+ public static function setUpBeforeClass()
+ {
+ fwrite(STDERR, "=> Finding binaries\n");
+ static::$bin['dm'] = $dm = exec('/usr/bin/env which docker-machine');
+ static::$bin['docker'] = $docker = exec('/usr/bin/env which docker');
+ if (empty($dm) && empty($docker)) {
+ static::markTestSkipped('Docker is required to run these tests');
+ }
+
+ if (!empty($dm)) {
+
+ fwrite(STDERR, "=> Starting Docker Machine\n");
+ exec($dm . ' create -d virtualbox mysql-shim');
+ exec($dm . ' start mysql-shim');
+
+ $env = '';
+ exec($dm . ' env mysql-shim', $env);
+ foreach ($env as $line) {
+ if ($line{0} !== '#') {
+ putenv(str_replace(["export ", '"'], "", $line));
+ }
+ }
+ }
+
+ fwrite(STDERR, "=> Running Docker Container: ");
+ static::$container = exec($docker . ' run -e MYSQL_ALLOW_EMPTY_PASSWORD=1 -P -d mysql/mysql-server');
+
+ if (empty(static::$container)) {
+ static::markTestSkipped("Unable to start docker container");
+ }
+
+ fwrite(STDERR, static::$container . "\n");
+
+ fwrite(STDERR, "=> Finding MySQL Host: ");
+ static::$host = exec($docker . ' port ' . self::$container . ' 3306');
+ fwrite(STDERR, static::$host . "\n");
+
+ if (!empty($dm)) {
+ fwrite(STDERR, "=> Using Docker Machine IP: ");
+ $info = explode(':', static::$host);
+ $port = array_pop($info);
+ static::$host = exec($dm . ' ip mysql-shim') . ':' . $port;
+ fwrite(STDERR, static::$host . "\n");
+ }
+
+ fwrite(STDERR, "=> Waiting on mysqld to start:");
+ $out = '';
+ while (trim($out) != 'mysqld') {
+ $out = exec(static::$bin['docker'] . ' exec ' . static::$container . ' ps ax | awk \'/mysqld/ {print $NF}\'');
+ }
+ fwrite(STDERR, " started\n");
+
+ fwrite(STDERR, "=> Docker Container Running\n\n");
+
+ error_reporting(E_ALL & ~E_DEPRECATED);
+
+ sleep(3);
+ }
+
+ public static function tearDownAfterClass()
+ {
+ fwrite(STDERR, "\n\nStopping Docker Container: ");
+ $output = exec(static::$bin['docker'] . ' stop ' .static::$container);
+ if (trim($output) !== static::$container) {
+ fwrite(STDERR, " Failed to stop container!\n");
+ return;
+ }
+
+ $output = exec(static::$bin['docker'] . ' rm ' .static::$container);
+ if (trim($output) !== static::$container) {
+ fwrite(STDERR, " Failed to remove container!\n");
+ return;
+ }
+ fwrite(STDERR, "Done\n");
+ }
+}
diff --git a/tests/bootstrap.php b/tests/bootstrap.php
new file mode 100644
index 0000000..f9e62ac
--- /dev/null
+++ b/tests/bootstrap.php
@@ -0,0 +1,2 @@
+<?php
+require_once __DIR__ . '/../vendor/autoload.php';