diff --git a/.github/install_mssql.sh b/.github/install_mssql.sh new file mode 100644 index 00000000..64b19baa --- /dev/null +++ b/.github/install_mssql.sh @@ -0,0 +1,72 @@ +#!/bin/bash -e + +# Use the following variables to control your install: + +# Password for the SA user (required) +MSSQL_SA_PASSWORD='!Passw0rd' + +# Product ID of the version of SQL server you're installing +# Must be evaluation, developer, express, web, standard, enterprise, or your 25 digit product key +# Defaults to developer +MSSQL_PID='evaluation' + +# Install SQL Server Agent (recommended) +SQL_INSTALL_AGENT='y' + +# Install SQL Server Full Text Search (optional) +# SQL_INSTALL_FULLTEXT='y' + +# Create an additional user with sysadmin privileges (optional) +SQL_INSTALL_USER='ez_test' +SQL_INSTALL_USER_PASSWORD='ezTest' +SQL_INSTALL_DATABASE='ez_test' + +if [ -z $MSSQL_SA_PASSWORD ] +then + echo Environment variable MSSQL_SA_PASSWORD must be set for unattended install + exit 1 +fi + +echo Adding Microsoft repositories... +sudo curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add - +sudo curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add - +repoargs="$(curl https://packages.microsoft.com/config/ubuntu/18.04/mssql-server-2019.list)" +sudo add-apt-repository "${repoargs}" + +echo Running apt-get update -y... +sudo apt-get update -y + +echo Installing SQL Server... +sudo apt-get install -y mssql-server + +echo Running mssql-conf setup... +sudo MSSQL_SA_PASSWORD=$MSSQL_SA_PASSWORD \ + MSSQL_PID=$MSSQL_PID \ + /opt/mssql/bin/mssql-conf -n setup accept-eula + +# Configure firewall to allow TCP port 1433: +echo Configuring UFW to allow traffic on port 1433... +sudo ufw allow 1433/tcp +sudo ufw reload + +# Restart SQL Server after installing: +echo Restarting SQL Server... +sudo systemctl restart mssql-server + +# Optional new user creation: +if [ ! -z $SQL_INSTALL_USER ] && [ ! -z $SQL_INSTALL_USER_PASSWORD ] +then + echo Creating user $SQL_INSTALL_USER + sqlcmd \ + -S localhost \ + -U SA \ + -P $MSSQL_SA_PASSWORD \ + -Q "CREATE DATABASE ez_test" + sqlcmd \ + -S localhost \ + -U SA \ + -P $MSSQL_SA_PASSWORD \ + -Q "CREATE LOGIN [$SQL_INSTALL_USER] WITH PASSWORD=N'$SQL_INSTALL_USER_PASSWORD', DEFAULT_DATABASE=[$SQL_INSTALL_DATABASE], CHECK_EXPIRATION=OFF, CHECK_POLICY=OFF; ALTER SERVER ROLE [sysadmin] ADD MEMBER [$SQL_INSTALL_USER]" +fi + +echo Done! diff --git a/.github/workflows/ezsql-linux.yml b/.github/workflows/ezsql-linux.yml new file mode 100644 index 00000000..0bec9206 --- /dev/null +++ b/.github/workflows/ezsql-linux.yml @@ -0,0 +1,56 @@ +# GitHub Action for PHP with extensions +name: Linux + +on: + push: + branches: + - v4 + pull_request: + branches: + - v4 + +jobs: + linux: + name: Linux (PHP ${{ matrix.php-versions }} CI) + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + operating-system: [ubuntu-latest] + php-versions: ['7.4', '8.0'] + + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Setup PHP, with composer and extensions + uses: shivammathur/setup-php@v2 #https://github.com/shivammathur/setup-php + with: + php-version: ${{ matrix.php-versions }} + extensions: mbstring, fileinfo, mysqli, pdo_mysql, pgsql, pdo_pgsql, sqlite3, pdo_sqlite, sqlsrv, pdo_sqlsrv, xdebug + coverage: xdebug + - name: Start MySQL + run: sudo systemctl start mysql.service + - name: Setup MySQL Database + run: | + mysql -uroot -h127.0.0.1 -proot -e "CREATE DATABASE IF NOT EXISTS ez_test;" + mysql -uroot -h127.0.0.1 -proot -e "CREATE USER ez_test@localhost IDENTIFIED BY 'ezTest'; GRANT ALL ON ez_test.* TO ez_test@localhost; FLUSH PRIVILEGES;" + - name: Start PostgreSql + run: | + sudo systemctl start postgresql.service + pg_isready + - name: Create additional user + run: | + sudo -u postgres psql --command="CREATE USER ez_test PASSWORD 'ezTest'" --command="\du" + - name: Setup PostgreSql Database + run: | + sudo -u postgres createdb --owner=ez_test ez_test + - name: Setup SQLServer Database + run: | + chmod +x "${GITHUB_WORKSPACE}/.github/install_mssql.sh" + "${GITHUB_WORKSPACE}/.github/install_mssql.sh" + - name: Install dependencies + run: composer update + - name: Test with phpunit + run: vendor/bin/phpunit --coverage-clover=coverage.xml + - name: Submit code coverage + run: bash <(curl -s https://codecov.io/bash) diff --git a/.github/workflows/ezsql-macos.yml b/.github/workflows/ezsql-macos.yml new file mode 100644 index 00000000..382486d3 --- /dev/null +++ b/.github/workflows/ezsql-macos.yml @@ -0,0 +1,66 @@ +# GitHub Action for PHP with extensions +name: macOS + +on: + push: + branches: + - v4 + pull_request: + branches: + - v4 + +jobs: + windows: + name: macOS (PHP ${{ matrix.php-versions }} CI) + runs-on: macos-latest + continue-on-error: true + strategy: + fail-fast: false + matrix: + operating-system: [macos-latest] + php-versions: ['7.3'] + + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Setup PHP, with composer and extensions + uses: shivammathur/setup-php@v2 #https://github.com/shivammathur/setup-php + with: + php-version: ${{ matrix.php-versions }} + extensions: mbstring, fileinfo, mysqli, pdo_mysql, pgsql, pdo_pgsql, sqlite3, pdo_sqlite, xdebug + coverage: xdebug + - name: Brew Install MySQL + run: | + brew install mysql@5.7 + - name: Brew Start MySQL + run: | + brew services start mysql@5.7 + brew link mysql@5.7 --force + mysqld --initialize-insecure + mysql.server start + - name: Setup MySQL Database + run: | + mysql -u root -e "CREATE DATABASE IF NOT EXISTS ez_test;" + mysql -u root -e "CREATE USER ez_test@localhost IDENTIFIED BY 'ezTest'; GRANT ALL ON ez_test.* TO ez_test@localhost; FLUSH PRIVILEGES;" + - name: Brew Start PostgreSql + run: | + sudo mkdir /var/pgsql_socket/ + sudo ln -s /private/tmp/.s.PGSQL.5432 /var/pgsql_socket/ + pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start + brew services restart postgresql + - name: Setup PostgreSql Database + run: | + createuser -s postgres + psql -U postgres --command="CREATE USER ez_test PASSWORD 'ezTest'" --command="\du" + createdb --owner=ez_test ez_test + - name: Install dependencies + run: | + composer self-update + composer update + - name: Test with phpunit + run: ./vendor/bin/phpunit --coverage-clover=coverage.xml + - name: Submit code coverage + if: ${{ success() }} || ${{ failure() }} + uses: codecov/codecov-action@v1 + with: + file: ./coverage.xml # optional diff --git a/.github/workflows/ezsql-windows.yml b/.github/workflows/ezsql-windows.yml new file mode 100644 index 00000000..0af684d1 --- /dev/null +++ b/.github/workflows/ezsql-windows.yml @@ -0,0 +1,65 @@ +# GitHub Action for PHP with extensions +name: Windows + +on: + push: + branches: + - v4 + pull_request: + branches: + - v4 + +jobs: + windows: + name: Windows (PHP ${{ matrix.php-versions }} CI) + runs-on: windows-latest + strategy: + fail-fast: false + matrix: + operating-system: [windows-latest] + php-versions: ['7.1', '7.2'] + + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Setup PHP, with composer and extensions + uses: shivammathur/setup-php@v2 #https://github.com/shivammathur/setup-php + with: + php-version: ${{ matrix.php-versions }} + extensions: mbstring, fileinfo, mysqli, pdo_mysql, pgsql, pdo_pgsql, sqlite3, pdo_sqlite, sqlsrv, pdo_sqlsrv, xdebug + coverage: xdebug + - name: Chocolatey Install MySQL + run: choco install mysql --version=5.7.18 -y -f + - name: Setup MySQL Database + run: | + mysql -u root -e "CREATE DATABASE IF NOT EXISTS ez_test;" + mysql -u root -e "CREATE USER ez_test@localhost IDENTIFIED BY 'ezTest'; GRANT ALL ON ez_test.* TO ez_test@localhost; FLUSH PRIVILEGES;" + - name: Chocolatey Uninstall PostgreSql 13 + run: choco uninstall postgresql13 -y -f + - name: Chocolatey Install PostgreSql 9 + run: choco install postgresql9 --params '/Password:root' -y -f + - name: Setup PostgreSql Database + run: | + $env:Path += ";C:\Program Files\PostgreSQL\9.6\bin" + $env:PGPASSWORD = "root" + psql -U postgres --command="\conninfo" + psql -U postgres -c "CREATE USER ez_test WITH PASSWORD 'ezTest';" --command="\du" + createdb --owner=ez_test ez_test + [Environment]::SetEnvironmentVariable("Path", $env:Path, [EnvironmentVariableTarget]::Machine) + - name: Chocolatey Install SQLServer + run: choco install sql-server-express -ia "/IACCEPTSQLSERVERLICENSETERMS /Q /ACTION=install /INSTANCEID=MSSQLSERVER /INSTANCENAME=MSSQLSERVER /UPDATEENABLED=FALSE /TCPENABLED=1 /SECURITYMODE=SQL /SAPWD=Password12!" -o -y -f + - name: Setup SQLServer Database + run: | + sqlcmd -L + New-NetFirewallRule -DisplayName "SQLServer default instance" -Direction Inbound -LocalPort 1433 -Protocol TCP -Action Allow + New-NetFirewallRule -DisplayName "SQLServer Browser service" -Direction Inbound -LocalPort 1434 -Protocol UDP -Action Allow + sqlcmd -S localhost,1433 -U sa -P Password12! -Q "CREATE DATABASE ez_test" + sqlcmd -S localhost,1433 -U sa -P Password12! -d ez_test -Q "CREATE LOGIN ez_test WITH PASSWORD=N'ezTest', DEFAULT_DATABASE=ez_test, CHECK_EXPIRATION=OFF, CHECK_POLICY=OFF; ALTER SERVER ROLE [sysadmin] ADD MEMBER ez_test" + - name: Install dependencies + run: composer update + - name: Test with phpunit + run: vendor\bin\phpunit --coverage-clover=coverage.xml + - name: Submit code coverage + uses: codecov/codecov-action@v1 + with: + file: ./coverage.xml # optional diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 7bb41573..00000000 --- a/.travis.yml +++ /dev/null @@ -1,34 +0,0 @@ -language: php - -# Versions of PHP you want your project run with. -php: - - 7.1 - - 7.2 - - 7.4 - -env: - - MYSQL_HOST=127.0.0.1 MYSQL_USER=root - -services: - - mysql - - postgresql - -# Commands to be run before your environment runs. -before_script: - - composer self-update - - composer require phpstan/phpstan "0.11.3" - - mysql -e 'CREATE DATABASE IF NOT EXISTS ez_test;' - - mysql -e "CREATE USER ez_test@localhost IDENTIFIED BY 'ezTest'; GRANT ALL ON ez_test.* TO ez_test@localhost; FLUSH PRIVILEGES;" - - psql -c 'CREATE DATABASE ez_test;' -U postgres - - psql -c "CREATE USER ez_test WITH PASSWORD 'ezTest';" -U postgres -# - mysql -e 'GRANT ALL PRIVILEGES ON ez_test.* TO ez_test@localhost;' -# - mysql -e "SET PASSWORD FOR 'ez_test'@'localhost' = PASSWORD('ezTest')" - -after_success: - - bash <(curl -s https://codecov.io/bash) - - travis_retry php vendor/bin/php-coveralls - -# Commands you want to run that will verify your build. -script: - - vendor/bin/phpunit --coverage-clover=coverage.xml - - vendor/bin/phpstan analyse lib tests --level=1 diff --git a/README.md b/README.md index 526839bf..cb1b811b 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,12 @@ # **ezsql** -[![Build Status](https://travis-ci.org/ezSQL/ezsql.svg?branch=master)](https://travis-ci.org/ezSQL/ezsql) -[![Build status](https://ci.appveyor.com/api/projects/status/6s8oqnoxa2i5k04f?svg=true)](https://ci.appveyor.com/project/jv2222/ezsql) -[![codecov](https://codecov.io/gh/ezSQL/ezSQL/branch/master/graph/badge.svg)](https://codecov.io/gh/ezSQL/ezSQL) +[![Windows](https://github.com/ezSQL/ezsql/workflows/Windows/badge.svg?branch=v4)](https://github.com/ezSQL/ezsql/actions?query=workflow%3AWindows) +[![Linux](https://github.com/ezSQL/ezsql/workflows/Linux/badge.svg?branch=v4)](https://github.com/ezSQL/ezsql/actions?query=workflow%3ALinux) +[![macOS](https://github.com/ezSQL/ezsql/workflows/macOS/badge.svg?branch=v4)](https://github.com/ezSQL/ezsql/actions?query=workflow%3AmacOS) +[![codecov](https://codecov.io/gh/ezSQL/ezSQL/branch/v4/graph/badge.svg)](https://codecov.io/gh/ezSQL/ezSQL) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/aad1f6aaaaa14f60933e75615da900b8)](https://www.codacy.com/app/techno-express/ezsql?utm_source=github.com&utm_medium=referral&utm_content=ezSQL/ezsql&utm_campaign=Badge_Grade) [![Maintainability](https://api.codeclimate.com/v1/badges/6f6107f25e9de7bf4272/maintainability)](https://codeclimate.com/github/ezSQL/ezsql/maintainability) -[![Total Downloads](https://poser.pugx.org/jv2222/ezsql/downloads)](https://packagist.org/packages/jv2222/ezsql) +[![Total Downloads](https://poser.pugx.org/ezSQL/ezsql/downloads)](https://packagist.org/packages/ezSQL/ezsql) ***A class to make it very easy to deal with database connections.*** diff --git a/appveyor.yml b/appveyor.yml deleted file mode 100644 index 67245644..00000000 --- a/appveyor.yml +++ /dev/null @@ -1,114 +0,0 @@ -build: false -platform: - - x64 -clone_folder: c:\projects\php-project-workspace - -## Build matrix for lowest and highest possible targets -environment: - matrix: - - php_ver_target: 7.3.11 - MYSQL_DATABASE: ez_test - MYSQL_HOST: localhost - MYSQL_USER: root - MYSQL_PASSWORD: Password12! - MYSQL_PATH: C:\Program Files\MySQL\MySQL Server 5.7 - -services: - - mssql2014 - - mysql - - postgresql - -## Set up environment variables -init: - - SET COMPOSER_NO_INTERACTION=1 - - SET PHP=1 # This var is connected to PHP install cache - - SET ANSICON=121x90 (121x90) - -## Install PHP and composer, and run the appropriate composer command Get the MSSQL DLL's and XDEBUG -install: - # Enable Windows Update service, needed to install vcredist2015 (dependency of php) - - IF EXIST c:\tools\php73 (SET PHP=0) - - ps: Set-Service wuauserv -StartupType Manual - - choco config set cacheLocation %LOCALAPPDATA%\Temp\Chocolatey - - choco install -y php --version %php_ver_target% - - choco install -y sqlite - - choco install -y composer - - refreshenv - - composer install --no-interaction --no-progress --prefer-dist - - cd C:\tools\php73 - # Get the MSSQL DLL's - - ps: >- - If ($env:PHP -eq "1") { - $DLLVersion = "5.6.1" - cd C:\tools\php73\ext - $source = "http://windows.php.net/downloads/pecl/releases/sqlsrv/$($DLLVersion)/php_sqlsrv-$($DLLVersion)-7.3-nts-vc15-x64.zip" - $destination = "C:\tools\php73\ext\php_sqlsrv-$($DLLVersion)-7.3-nts-vc15-x64.zip" - Invoke-WebRequest $source -OutFile $destination - 7z x -y php_sqlsrv-$($DLLVersion)-7.3-nts-vc15-x64.zip > $null - $source = "http://windows.php.net/downloads/pecl/releases/pdo_sqlsrv/$($DLLVersion)/php_pdo_sqlsrv-$($DLLVersion)-7.3-nts-vc15-x64.zip" - $destination = "C:\tools\php73\ext\php_pdo_sqlsrv-$($DLLVersion)-7.3-nts-vc15-x64.zip" - Invoke-WebRequest $source -OutFile $destination - 7z x -y php_pdo_sqlsrv-$($DLLVersion)-7.3-nts-vc15-x64.zip > $null - Remove-Item C:\tools\php73\ext* -include .zip - Invoke-WebRequest "https://xdebug.org/files/php_xdebug-2.7.2-7.3-vc15-nts-x86_64.dll" -OutFile "C:\tools\php73\ext\php_xdebug-2.7.2-7.3-vc15-nts-x86_64.dll" - cd C:\tools\php73 - } - - IF %PHP%==1 echo date.timezone="UTC" >> php.ini - - IF %PHP%==1 echo extension_dir=ext >> php.ini - - IF %PHP%==1 echo extension=php_fileinfo.dll >> php.ini - - ps: >- - If ($env:php_ver_target -eq "5.6") { - Add-Content php.ini "`nextension=php_sqlsrv_nts.dll" - Add-Content php.ini "`nextension=php_pdo_sqlsrv_nts.dll" - Add-Content php.ini "`n" - } Else { - Add-Content php.ini "`nextension=php_sqlsrv.dll" - Add-Content php.ini "`nextension=php_pdo_sqlsrv.dll" - Add-Content php.ini "`n" - } - - IF %PHP%==1 echo extension=php_pgsql.dll >> php.ini - - IF %PHP%==1 echo extension=php_pdo_pgsql.dll >> php.ini - - IF %PHP%==1 echo extension=php_sqlite3.dll >> php.ini - - IF %PHP%==1 echo extension=php_pdo_sqlite.dll >> php.ini - - IF %PHP%==1 echo extension=php_mysqli.dll >> php.ini - - IF %PHP%==1 echo extension=php_pdo_mysql.dll >> php.ini - - IF %PHP%==1 echo [xdebug] >> php.ini - - IF %PHP%==1 echo zend_extension=php_xdebug-2.7.2-7.3-vc15-nts-x86_64.dll >> php.ini - - IF %PHP%==1 echo zend.assertions=1 >> php.ini - - IF %PHP%==1 echo assert.exception=On >> php.ini - - IF %PHP%==1 echo xdebug.remote_enable=1 >> php.ini - - IF %PHP%==1 echo xdebug.remote_autostart=1 >> php.ini - - IF %PHP%==1 echo xdebug.profiler_enable=off >> php.ini - - cd c:\projects\php-project-workspace - - composer self-update - - composer require phpstan/phpstan "0.11.3" - -build_script: - # postgres - - SET PGUSER=postgres - - SET PGPASSWORD=Password12! - - PATH=C:\Program Files\PostgreSQL\9.6\bin\;%PATH% - - createdb ez_test - - psql -c "CREATE USER ez_test WITH PASSWORD 'ezTest';" - # sqlserver - - sqlcmd -S localhost,1433 -U sa -P Password12! -Q "CREATE DATABASE ez_test" - - sqlcmd -S localhost,1433 -U sa -P Password12! -d ez_test -Q "CREATE LOGIN ez_test WITH PASSWORD=N'ezTest', DEFAULT_DATABASE=ez_test, CHECK_EXPIRATION=OFF, CHECK_POLICY=OFF; ALTER SERVER ROLE [sysadmin] ADD MEMBER ez_test" - -before_test: - - SET PATH=%MYSQL_PATH%\bin;%PATH% - - mysqladmin --host=%MYSQL_HOST% --user=%MYSQL_USER% --password=%MYSQL_PASSWORD% create %MYSQL_DATABASE% - # mysql - - mysql -u root -p"Password12!" -e "CREATE DATABASE IF NOT EXISTS ez_test;" - - mysql -u root -p"Password12!" -e "GRANT ALL PRIVILEGES ON ez_test.* TO ez_test@localhost IDENTIFIED BY 'ezTest'"; - - mysql -u root -p"Password12!" -e "FLUSH PRIVILEGES;" - -on_success: - - ps: | - $env:PATH = 'C:\msys64\usr\bin;' + $env:PATH - Invoke-WebRequest -Uri 'https://codecov.io/bash' -OutFile codecov.sh - bash codecov.sh -f "coverage.xml" - -## Run the actual test -test_script: - - cd c:\projects\php-project-workspace - - vendor\bin\phpunit --coverage-clover=coverage.xml diff --git a/composer.json b/composer.json index 97cd7f08..29f7ef48 100644 --- a/composer.json +++ b/composer.json @@ -1,8 +1,25 @@ { "name": "ezsql/ezsql", "description": "Advance database access library. Make interacting with a database ridiculously easy.", - "keywords": ["mysql", "mysqli", "postgresql", "mssql", "sqlsrv", "sqlserver", "pdo", "sqlite", "sqlite3", "database", "abstraction", "sql", "dba"], - "license": ["LGPL-3.0-or-later", "MIT"], + "keywords": [ + "mysql", + "mysqli", + "postgresql", + "mssql", + "sqlsrv", + "sqlserver", + "pdo", + "sqlite", + "sqlite3", + "database", + "abstraction", + "sql", + "dba" + ], + "license": [ + "LGPL-3.0-or-later", + "MIT" + ], "authors": [ { "name": "Justin Vincent", @@ -21,7 +38,7 @@ "issues": "https://github.com/ezSQL/ezSQL/issues" }, "require": { - "php": "^7.1", + "php": "^7.1 || ^8", "psr/container": "^1.0" }, "provide": { diff --git a/lib/ConfigAbstract.php b/lib/ConfigAbstract.php index ef660a40..0d93f6eb 100644 --- a/lib/ConfigAbstract.php +++ b/lib/ConfigAbstract.php @@ -25,6 +25,34 @@ /** * @method set/get{property} - a property that needs to be accessed + * + * @method void setDriver($args); + * @method void setDsn($args); + * @method void setUser($args); + * @method void setPassword($args); + * @method void setName($args); + * @method void setHost($args); + * @method void setPort($args); + * @method void setCharset($args); + * @method void setOptions($args); + * @method void setIsFile($args); + * @method void setToMssql($args); + * @method void setToMysql($args); + * @method void setPath($args); + * + * @method string getDriver(); + * @method string getDsn(); + * @method string getUser(); + * @method string getPassword() + * @method string getName(); + * @method string getHost(); + * @method string getPort(); + * @method string getCharset(); + * @method string getOptions(); + * @method string getToMysql(); + * @method bool getIsFile(); + * @method bool getToMssql(); + * @method string getPath(); */ abstract class ConfigAbstract { diff --git a/lib/Constants.php b/lib/Constants.php index 1b10d719..f485dc2c 100644 --- a/lib/Constants.php +++ b/lib/Constants.php @@ -5,7 +5,7 @@ /** * ezsqlModel Constants */ - \defined('EZSQL_VERSION') or \define('EZSQL_VERSION', '4.0.10'); + \defined('EZSQL_VERSION') or \define('EZSQL_VERSION', '4.1.0'); \defined('OBJECT') or \define('OBJECT', 'OBJECT'); \defined('ARRAY_A') or \define('ARRAY_A', 'ARRAY_A'); \defined('ARRAY_N') or \define('ARRAY_N', 'ARRAY_N'); diff --git a/lib/DInjector.php b/lib/DInjector.php index f24e8c13..b34bbb64 100644 --- a/lib/DInjector.php +++ b/lib/DInjector.php @@ -129,7 +129,9 @@ protected function getDependencies($parameters, $values = null) if (\is_array($parameters)) { foreach ($parameters as $parameter) { // get the type hinted class - $dependency = $parameter->getClass(); + $dependency = $parameter->getType() && !$parameter->getType()->isBuiltin() + ? new \ReflectionClass($parameter->getType()->getName()) + : NULL; if ($dependency === NULL) { // check if the constructor parameter name exists as a key in the values array if (\array_key_exists($parameter->getName(), $values)) { diff --git a/lib/Database.php b/lib/Database.php index b5126084..914d0687 100644 --- a/lib/Database.php +++ b/lib/Database.php @@ -18,11 +18,14 @@ class Database private static $instances = []; private function __construct() - { } + { + } private function __clone() - { } - private function __wakeup() - { } + { + } + public function __wakeup() + { + } /** * Initialize and connect a vendor database. @@ -30,6 +33,7 @@ private function __wakeup() * @param mixed $vendor - SQL driver * @param mixed $setting - SQL connection parameters * @param mixed $tag - Store the instance for later use + * @return Database\ez_pdo|Database\ez_pgsql|Database\ez_sqlsrv|Database\ez_sqlite3|Database\ez_mysqli */ public static function initialize(?string $vendor = null, ?array $setting = null, ?string $tag = null) { diff --git a/lib/Database/ez_mysqli.php b/lib/Database/ez_mysqli.php index 16b9326b..2ec89afb 100644 --- a/lib/Database/ez_mysqli.php +++ b/lib/Database/ez_mysqli.php @@ -18,7 +18,7 @@ class ez_mysqli extends ezsqlModel implements DatabaseInterface /** * Database connection handle - * @var resource + * @var \mysqli */ private $dbh; @@ -132,19 +132,13 @@ public function connect( */ public function select($name = '', $charset = '') { - $this->_connected = false; $name = empty($name) ? $this->database->getName() : $name; - if (!$this->dbh) { - // Must have an active database connection - $this->register_error(\FAILED_CONNECTION . ' in ' . __FILE__ . ' on line ' . __LINE__); - } elseif (!\mysqli_select_db($this->dbh, $name)) { + try { // Try to connect to the database - // Try to get error supplied by mysql if not use our own - if (!$str = \mysqli_error($this->dbh)) { - $str = 'Unexpected error while trying to select database'; + if (($this->dbh === null) || ($this->_connected === false) || !\mysqli_select_db($this->dbh, $name)) { + throw new Exception("Error Processing Request", 1); } - $this->register_error($str . ' in ' . __FILE__ . ' on line ' . __LINE__); - } else { + $this->database->setName($name); if ($charset == '') { $charset = $this->database->getCharset(); @@ -162,10 +156,21 @@ public function select($name = '', $charset = '') \mysqli_query($this->dbh, 'SET NAMES \'' . $encoding . '\''); } } - $this->_connected = true; - } - return $this->_connected; + return true; + } catch (\Throwable $e) { + $str = \FAILED_CONNECTION; + // Must have an active database connection + if ($this->dbh && $this->_connected) { + // Try to get error supplied by mysql if not use our own + if (!$str = \mysqli_error($this->dbh)) { + $str = 'Unexpected error while trying to select database'; + } + } + + $this->register_error($str . ' in ' . __FILE__ . ' on line ' . __LINE__); + return false; + } } // select /** @@ -225,7 +230,7 @@ private function fetch_prepared_result(&$stmt, $query) } // Binds variables to a prepared statement for result storage - \call_user_func_array([$stmt, 'bind_result'], $variables); + \call_user_func_array([$stmt, 'bind_result'], \array_values($variables)); $i = 0; // Store Query Results diff --git a/lib/Database/ez_pdo.php b/lib/Database/ez_pdo.php index 8b80dbb4..f736d691 100644 --- a/lib/Database/ez_pdo.php +++ b/lib/Database/ez_pdo.php @@ -19,22 +19,22 @@ class ez_pdo extends ezsqlModel implements DatabaseInterface /** * Database connection handle - * @var resource + * @var \PDO */ private $dbh; - /** - * Query result - * @var mixed - */ - private $result; - /** * Database configuration setting * @var ConfigInterface */ private $database; + /** + * Query result + * @var mixed + */ + protected $result; + public function __construct(ConfigInterface $settings = null) { if (empty($settings)) { @@ -239,14 +239,18 @@ public function query_prepared(string $query, array $param = null, $isSelect = f { $stmt = $this->dbh->prepare($query); $result = false; - if ($stmt && $stmt->execute($param)) { + if ($stmt && $stmt->execute(\array_values($param))) { $result = $stmt->rowCount(); // Store Query Results $num_rows = 0; - while ($row = @$stmt->fetch(\PDO::FETCH_ASSOC)) { - // Store results as an objects within main array - $this->last_result[$num_rows] = (object) $row; - $num_rows++; + try { + while ($row = @$stmt->fetch(\PDO::FETCH_ASSOC)) { + // Store results as an objects within main array + $this->last_result[$num_rows] = (object) $row; + $num_rows++; + } + } catch (\Throwable $ex) { + // } $this->num_rows = $num_rows; @@ -300,10 +304,14 @@ private function processResult(string $query, $result = null, bool $isSelect = f // Store Query Results $num_rows = 0; - while ($row = @$result->fetch(\PDO::FETCH_ASSOC)) { - // Store results as an objects within main array - $this->last_result[$num_rows] = (object) $row; - $num_rows++; + try { + while ($row = @$result->fetch(\PDO::FETCH_ASSOC)) { + // Store results as an objects within main array + $this->last_result[$num_rows] = (object) $row; + $num_rows++; + } + } catch (\Throwable $ex) { + // } // Log number of rows the query returned @@ -318,9 +326,13 @@ private function processResult(string $query, $result = null, bool $isSelect = f if (!empty($result)) $this->_affectedRows = $result; - // Take note of the insert_id - if (\preg_match("/^(insert|replace)\s+/i", $query)) { - $this->insert_id = @$this->dbh->lastInsertId(); + try { + // Take note of the insert_id + if (\preg_match("/^(insert|replace)\s+/i", $query)) { + $this->insert_id = @$this->dbh->lastInsertId(); + } + } catch (\Throwable $ex) { + // } // Return number of rows affected @@ -346,8 +358,13 @@ private function processQuery(string $query, array $param = null) if (!empty($param) && \is_array($param) && $this->isPrepareOn()) { $this->shortcutUsed = true; $this->_affectedRows = $this->query_prepared($query, $param, false); - } else - $this->_affectedRows = $this->dbh->exec($query); + } else { + try { + $this->_affectedRows = $this->dbh->exec($query); + } catch (\Throwable $ex) { + // + } + } if ($this->processResult($query) === false) return false; @@ -360,7 +377,11 @@ private function processQuery(string $query, array $param = null) $this->shortcutUsed = true; $sth = $this->query_prepared($query, $param, true); } else - $sth = $this->dbh->query($query); + try { + $sth = $this->dbh->query($query); + } catch (\Throwable $ex) { + // + } if ($this->processResult($query, $sth, true) === false) return false; diff --git a/lib/Database/ez_pgsql.php b/lib/Database/ez_pgsql.php index 34da6eb0..3d5eed8c 100644 --- a/lib/Database/ez_pgsql.php +++ b/lib/Database/ez_pgsql.php @@ -103,7 +103,7 @@ public function connect( $connect_string = "host=" . $host . " port=" . $port . " dbname=" . $name . " user=" . $user . " password=" . $password; // Try to establish the server database handle - if (!$this->dbh = \pg_connect($connect_string, true)) { + if (!$this->dbh = \pg_connect($connect_string, PGSQL_CONNECT_FORCE_NEW)) { $this->register_error(\FAILED_CONNECTION . ' in ' . __FILE__ . ' on line ' . __LINE__); } else { $this->_connected = true; @@ -162,9 +162,13 @@ private function processQueryResult(string $query, $result = null) if (!empty($result)) $this->result = $result; - // If there is an error then take note of it.. - if ($str = @\pg_last_error($this->dbh)) { - return $this->register_error($str); + try { + // If there is an error then take note of it.. + if ($str = @\pg_last_error($this->dbh)) { + return $this->register_error($str); + } + } catch (\Throwable $ex) { + return $this->register_error($ex->getMessage()); } // Query was an insert, delete, update, replace @@ -298,7 +302,11 @@ public function query(string $query, bool $use_prepare = false) $this->shortcutUsed = true; $this->result = $this->query_prepared($query, $param); } else { - $this->result = @\pg_query($this->dbh, $query); + try { + $this->result = @\pg_query($this->dbh, $query); + } catch (\Throwable $ex) { + // + } } if ($this->processQueryResult($query) === false) { diff --git a/lib/Database/ez_sqlite3.php b/lib/Database/ez_sqlite3.php index 8c9a7f37..b7dead0e 100644 --- a/lib/Database/ez_sqlite3.php +++ b/lib/Database/ez_sqlite3.php @@ -18,7 +18,7 @@ class ez_sqlite3 extends ezsqlModel implements DatabaseInterface /** * Database connection handle - * @var resource + * @var \SQLite3 */ private $dbh; diff --git a/lib/Database/ez_sqlsrv.php b/lib/Database/ez_sqlsrv.php index ccfe5806..154f260f 100644 --- a/lib/Database/ez_sqlsrv.php +++ b/lib/Database/ez_sqlsrv.php @@ -179,61 +179,65 @@ private function processQueryResult(string $query, $result = null) // Query was an insert, delete, update, replace $this->is_insert = false; - if (\preg_match("/^(insert|delete|update|replace)\s+/i", $query)) { - $this->is_insert = true; - $this->_affectedRows = @\sqlsrv_rows_affected($this->result); - - // Take note of the insert_id - if (\preg_match("/^(insert|replace)\s+/i", $query)) { - $identityResultset = @\sqlsrv_query($this->dbh, "select SCOPE_IDENTITY()"); - - if ($identityResultset != false) { - $identityRow = @\sqlsrv_fetch($identityResultset); - $this->insert_id = $identityRow[0]; + try { + if (\preg_match("/^(insert|delete|update|replace)\s+/i", $query)) { + $this->is_insert = true; + $this->_affectedRows = @\sqlsrv_rows_affected($this->result); + + // Take note of the insert_id + if (\preg_match("/^(insert|replace)\s+/i", $query)) { + $identityResultset = @\sqlsrv_query($this->dbh, "select SCOPE_IDENTITY()"); + + if ($identityResultset != false) { + $identityRow = @\sqlsrv_fetch($identityResultset); + $this->insert_id = $identityRow[0]; + } } - } - // Return number of rows affected - $this->return_val = $this->_affectedRows; - } else { // Query was a select - // Take note of column info - $i = 0; - foreach (@\sqlsrv_field_metadata($this->result) as $field) { - $col = []; - foreach ($field as $name => $value) { - $name = \strtolower($name); - if ($name == "size") { - $name = "max_length"; - } elseif ($name == "type") { - $name = "typeid"; + // Return number of rows affected + $this->return_val = $this->_affectedRows; + } else { // Query was a select + // Take note of column info + $i = 0; + foreach (@\sqlsrv_field_metadata($this->result) as $field) { + $col = []; + foreach ($field as $name => $value) { + $name = \strtolower($name); + if ($name == "size") { + $name = "max_length"; + } elseif ($name == "type") { + $name = "typeid"; + } + + //DEFINED FOR E_STRICT + $col = new \stdClass(); + $col->{$name} = $value; } - //DEFINED FOR E_STRICT - $col = new \stdClass(); - $col->{$name} = $value; + $col->type = $this->get_datatype($col); + $this->col_info[$i++] = $col; + unset($col); } - $col->type = $this->get_datatype($col); - $this->col_info[$i++] = $col; - unset($col); - } - - // Store Query Results - $num_rows = 0; + // Store Query Results + $num_rows = 0; - while ($row = @\sqlsrv_fetch_object($this->result)) { + while ($row = @\sqlsrv_fetch_object($this->result)) { - // Store results as an objects within main array - $this->last_result[$num_rows] = $row; - $num_rows++; - } + // Store results as an objects within main array + $this->last_result[$num_rows] = $row; + $num_rows++; + } - @\sqlsrv_free_stmt($this->result); + @\sqlsrv_free_stmt($this->result); - // Log number of rows the query returned - $this->num_rows = $num_rows; + // Log number of rows the query returned + $this->num_rows = $num_rows; - // Return number of rows selected - $this->return_val = $this->num_rows; + // Return number of rows selected + $this->return_val = $this->num_rows; + } + } catch (\Throwable $ex) { + return false; } return $this->return_val; @@ -300,7 +304,11 @@ public function query(string $query, bool $use_prepare = false) $this->shortcutUsed = true; $this->result = $this->query_prepared($query, $param); } else { - $this->result = @\sqlsrv_query($this->dbh, $query); + try { + $this->result = @\sqlsrv_query($this->dbh, $query); + } catch (\Throwable $ex) { + // + } } if ($this->processQueryResult($query) === false) { diff --git a/lib/DatabaseInterface.php b/lib/DatabaseInterface.php index 8e9040d8..ca5ae9d5 100644 --- a/lib/DatabaseInterface.php +++ b/lib/DatabaseInterface.php @@ -18,6 +18,7 @@ interface DatabaseInterface * - getOptions(); * - getIsFile(); * - getToMssql(); + * - getToMysql(); * - getPath(); *--- * - setDriver($args); @@ -31,9 +32,10 @@ interface DatabaseInterface * - setOptions($args); * - setIsFile($args); * - setToMssql($args); + * - setToMysql($args); * - setPath($args); * - * @return string|array|bool|void + * @return string|array|bool|object */ public function settings(); diff --git a/lib/ezFunctions.php b/lib/ezFunctions.php index b99fc9a7..6b420bd8 100644 --- a/lib/ezFunctions.php +++ b/lib/ezFunctions.php @@ -3,57 +3,135 @@ use ezsql\ezQuery; use ezsql\ezSchema; use ezsql\Database; +use ezsql\ezQueryInterface; use ezsql\DatabaseInterface; -use ezsql\Database\ez_pdo; -// Global class instances, will be used to call methods directly here. - -if (!function_exists('ezFunctions')) { +if (!\function_exists('ezFunctions')) { + /** + * Initialize and connect a vendor database. + * + * @param mixed $sqlDriver - SQL driver + * @param mixed $connectionSetting - SQL connection parameters + * @param mixed $instanceTag - Store the instance for later use + * @return ezsql\Database\ez_pdo|ezsql\Database\ez_pgsql|ezsql\Database\ez_sqlsrv|Database\ez_sqlite3|ezsql\Database\ez_mysqli + */ function database(string $sqlDriver = null, array $connectionSetting = null, string $instanceTag = null) { return Database::initialize($sqlDriver, $connectionSetting, $instanceTag); } + /** + * Returns an already initialized database instance that was created an tag. + * + * @param string $getTag - An stored tag instance + * @return ezsql\Database\ez_pdo|ezsql\Database\ez_pgsql|ezsql\Database\ez_sqlsrv|Database\ez_sqlite3|ezsql\Database\ez_mysqli + */ function tagInstance(string $getTag = null) { return \database($getTag); } + /** + * Initialize an mysqli database. + * + * @param array $databaseSetting - SQL connection parameters + * @param mixed $instanceTag - Store the instance for later use + * + * @return ezsql\Database\ez_mysqli + */ function mysqlInstance(array $databaseSetting = null, string $instanceTag = null) { return \database(\MYSQLI, $databaseSetting, $instanceTag); } + /** + * Initialize an pgsql database. + * + * @param mixed $databaseSetting - SQL connection parameters + * @param mixed $instanceTag - Store the instance for later use + * + * @return ezsql\Database\ez_pgsql + */ function pgsqlInstance(array $databaseSetting = null, string $instanceTag = null) { return \database(\PGSQL, $databaseSetting, $instanceTag); } + /** + * Initialize an mssql database. + * + * @param mixed $databaseSetting - SQL connection parameters + * @param mixed $instanceTag - Store the instance for later use + * + * @return ezsql\Database\ez_sqlsrv + */ function mssqlInstance(array $databaseSetting = null, string $instanceTag = null) { return \database(\MSSQL, $databaseSetting, $instanceTag); } + /** + * Initialize an pdo database. + * + * @param mixed $databaseSetting - SQL connection parameters + * @param mixed $instanceTag - Store the instance for later use + * + * @return ezsql\Database\ez_pdo + */ function pdoInstance(array $databaseSetting = null, string $instanceTag = null) { return \database(\Pdo, $databaseSetting, $instanceTag); } + /** + * Initialize an sqlite3 database. + * + * @param mixed $databaseSetting - SQL connection parameters + * @param mixed $instanceTag - Store the instance for later use + * + * @return ezsql\Database\ez_sqlite3 + */ function sqliteInstance(array $databaseSetting = null, string $instanceTag = null) { return \database(\SQLITE3, $databaseSetting, $instanceTag); } + /** + * Returns the current global database vendor being used. + * + * @return string|null `mysqli`|`pgsql`|`sqlite3`|`sqlsrv` + */ function getVendor() { return ezSchema::vendor(); } + /** + * Convert array to string, and attach '`, `' for separation, if none is provided. + * + * @return string + */ function to_string($arrays, $separation = ',') { return ezQuery::to_string($arrays, $separation); } + /** + * Creates an database column, + * - column, datatype, value/options with the given arguments. + * + * // datatype are global CONSTANTS and can be written out like: + * - VARCHAR, 32, notNULL, PRIMARY, SEQUENCE|AUTO, .... + * // SEQUENCE|AUTO constants will replaced with the proper auto sequence for the SQL driver + * + * @param string $column|CONSTRAINT, - column name/CONSTRAINT usage for PRIMARY|FOREIGN KEY + * @param string $type|$constraintName, - data type for column/primary|foreign constraint name + * @param mixed $size|...$primaryForeignKeys, + * @param mixed $value, - column should be NULL or NOT NULL. If omitted, assumes NULL + * @param mixed $default - Optional. It is the value to assign to the column + * + * @return string|bool - SQL schema string, or false for error + */ function column(string $column = null, string $type = null, ...$args) { return ezSchema::column($column, $type, ...$args); @@ -92,6 +170,29 @@ function dropColumn(string $columnName, ...$data) return \column(\DROP, $columnName, ...$data); } + /** + * Creates self signed certificate + * + * @param string $privatekeyFile + * @param string $certificateFile + * @param string $signingFile + * // param string $caCertificate + * @param string $ssl_path + * @param array $details - certificate details + * + * Example: + * array $details = [ + * "countryName" => '', + * "stateOrProvinceName" => '', + * "localityName" => '', + * "organizationName" => '', + * "organizationalUnitName" => '', + * "commonName" => '', + * "emailAddress" => '' + * ]; + * + * @return string certificate path + */ function createCertificate( string $privatekeyFile = 'certificate.key', string $certificateFile = 'certificate.crt', @@ -104,28 +205,15 @@ function createCertificate( } /** - * Creates an array from expressions in the following format + * Creates an equality comparison expression with the given arguments. * * @param strings $x, - The left expression. - * @param strings $operator, - One of - * '<', '>', '=', '!=', '>=', '<=', '<>', 'IN',, 'NOT IN', 'LIKE', - * 'NOT LIKE', 'BETWEEN', 'NOT BETWEEN', 'IS', 'IS NOT', or the constants above. - * * @param strings $y, - The right expression. * @param strings $and, - combine additional expressions with, 'AND','OR', 'NOT', 'AND NOT'. * @param strings $args - for any extras * - * function comparison($x, $operator, $y, $and=null, ...$args) - * { - * return array($x, $operator, $y, $and, ...$args); - * } - * * @return array */ - - /** - * Creates an equality comparison expression with the given arguments. - */ function eq($x, $y, $and = null, ...$args) { $expression = array(); @@ -135,6 +223,22 @@ function eq($x, $y, $and = null, ...$args) /** * Creates a non equality comparison expression with the given arguments. + * + * @param strings $x, - The left expression. + * @param strings $operator, - One of + * '<', '>', '=', '!=', '>=', '<=', '<>', 'IN',, 'NOT IN', 'LIKE', + * 'NOT LIKE', 'BETWEEN', 'NOT BETWEEN', 'IS', 'IS NOT', or the constants above. + * + * @param strings $y, - The right expression. + * @param strings $and, - combine additional expressions with, 'AND','OR', 'NOT', 'AND NOT'. + * @param strings $args - for any extras + * + * function comparison($x, $operator, $y, $and=null, ...$args) + * { + * return array($x, $operator, $y, $and, ...$args); + * } + * + * @return array */ function neq($x, $y, $and = null, ...$args) { @@ -145,6 +249,13 @@ function neq($x, $y, $and = null, ...$args) /** * Creates the other non equality comparison expression with the given arguments. + * + * @param strings $x, - The left expression. + * @param strings $y, - The right expression. + * @param strings $and, - combine additional expressions with, 'AND','OR', 'NOT', 'AND NOT'. + * @param strings $args - for any extras + * + * @return array */ function ne($x, $y, $and = null, ...$args) { @@ -155,6 +266,13 @@ function ne($x, $y, $and = null, ...$args) /** * Creates a lower-than comparison expression with the given arguments. + * + * @param strings $x, - The left expression. + * @param strings $y, - The right expression. + * @param strings $and, - combine additional expressions with, 'AND','OR', 'NOT', 'AND NOT'. + * @param strings $args - for any extras + * + * @return array */ function lt($x, $y, $and = null, ...$args) { @@ -165,6 +283,13 @@ function lt($x, $y, $and = null, ...$args) /** * Creates a lower-than-equal comparison expression with the given arguments. + * + * @param strings $x, - The left expression. + * @param strings $y, - The right expression. + * @param strings $and, - combine additional expressions with, 'AND','OR', 'NOT', 'AND NOT'. + * @param strings $args - for any extras + * + * @return array */ function lte($x, $y, $and = null, ...$args) { @@ -175,6 +300,13 @@ function lte($x, $y, $and = null, ...$args) /** * Creates a greater-than comparison expression with the given arguments. + * + * @param strings $x, - The left expression. + * @param strings $y, - The right expression. + * @param strings $and, - combine additional expressions with, 'AND','OR', 'NOT', 'AND NOT'. + * @param strings $args - for any extras + * + * @return array */ function gt($x, $y, $and = null, ...$args) { @@ -185,6 +317,13 @@ function gt($x, $y, $and = null, ...$args) /** * Creates a greater-than-equal comparison expression with the given arguments. + * + * @param strings $x, - The left expression. + * @param strings $y, - The right expression. + * @param strings $and, - combine additional expressions with, 'AND','OR', 'NOT', 'AND NOT'. + * @param strings $args - for any extras + * + * @return array */ function gte($x, $y, $and = null, ...$args) { @@ -195,6 +334,13 @@ function gte($x, $y, $and = null, ...$args) /** * Creates an IS NULL expression with the given arguments. + * + * @param strings $x, - The left expression. + * @param strings $y, - The right expression. + * @param strings $and, - combine additional expressions with, 'AND','OR', 'NOT', 'AND NOT'. + * @param strings $args - for any extras + * + * @return array */ function isNull($x, $y = 'null', $and = null, ...$args) { @@ -205,6 +351,13 @@ function isNull($x, $y = 'null', $and = null, ...$args) /** * Creates an IS NOT NULL expression with the given arguments. + * + * @param strings $x, - The left expression. + * @param strings $y, - The right expression. + * @param strings $and, - combine additional expressions with, 'AND','OR', 'NOT', 'AND NOT'. + * @param strings $args - for any extras + * + * @return array */ function isNotNull($x, $y = 'null', $and = null, ...$args) { @@ -215,6 +368,13 @@ function isNotNull($x, $y = 'null', $and = null, ...$args) /** * Creates a LIKE() comparison expression with the given arguments. + * + * @param strings $x, - The left expression. + * @param strings $y, - The right expression. + * @param strings $and, - combine additional expressions with, 'AND','OR', 'NOT', 'AND NOT'. + * @param strings $args - for any extras + * + * @return array */ function like($x, $y, $and = null, ...$args) { @@ -225,6 +385,13 @@ function like($x, $y, $and = null, ...$args) /** * Creates a NOT LIKE() comparison expression with the given arguments. + * + * @param strings $x, - The left expression. + * @param strings $y, - The right expression. + * @param strings $and, - combine additional expressions with, 'AND','OR', 'NOT', 'AND NOT'. + * @param strings $args - for any extras + * + * @return array */ function notLike($x, $y, $and = null, ...$args) { @@ -235,6 +402,13 @@ function notLike($x, $y, $and = null, ...$args) /** * Creates a IN () comparison expression with the given arguments. + * + * @param strings $x, - The left expression. + * @param strings $y, - The right expression. + * @param strings $and, - combine additional expressions with, 'AND','OR', 'NOT', 'AND NOT'. + * @param strings $args - for any extras + * + * @return array */ function in($x, $y, ...$args) { @@ -245,6 +419,13 @@ function in($x, $y, ...$args) /** * Creates a NOT IN () comparison expression with the given arguments. + * + * @param strings $x, - The left expression. + * @param strings $y, - The right expression. + * @param strings $and, - combine additional expressions with, 'AND','OR', 'NOT', 'AND NOT'. + * @param strings $args - for any extras + * + * @return array */ function notIn($x, $y, ...$args) { @@ -255,6 +436,13 @@ function notIn($x, $y, ...$args) /** * Creates a BETWEEN () comparison expression with the given arguments. + * + * @param strings $x, - The left expression. + * @param strings $y, - The right expression. + * @param strings $and, - combine additional expressions with, 'AND','OR', 'NOT', 'AND NOT'. + * @param strings $args - for any extras + * + * @return array */ function between($x, $y, $y2, ...$args) { @@ -265,6 +453,13 @@ function between($x, $y, $y2, ...$args) /** * Creates a NOT BETWEEN () comparison expression with the given arguments. + * + * @param strings $x, - The left expression. + * @param strings $y, - The right expression. + * @param strings $and, - combine additional expressions with, 'AND','OR', 'NOT', 'AND NOT'. + * @param strings $args - for any extras + * + * @return array */ function notBetween($x, $y, $y2, ...$args) { @@ -274,16 +469,18 @@ function notBetween($x, $y, $y2, ...$args) } /** - * Using global class instances, setup functions to call class methods directly. + * Sets the global class instance for functions to call class methods directly. + * + * @param ezQueryInterface|null $ezSQL * - * @return boolean - true, or false for error + * @return boolean - `true`, or `false` for error */ - function setInstance($ezSQL = '') + function setInstance(ezQueryInterface $ezSQL = null) { global $ezInstance; $status = false; - if ($ezSQL instanceof DatabaseInterface) { + if ($ezSQL instanceof ezQueryInterface) { $ezInstance = $ezSQL; $status = true; } @@ -291,24 +488,73 @@ function setInstance($ezSQL = '') return $status; } + /** + * Returns the global database class, last created instance or the one set with `setInstance()`. + * + * @return ezQueryInterface|null + */ function getInstance() { global $ezInstance; - return ($ezInstance instanceof DatabaseInterface) ? $ezInstance : null; + return ($ezInstance instanceof ezQueryInterface) ? $ezInstance : null; } + /** + * Clear/unset the global database class instance. + */ function clearInstance() { + global $ezInstance; $GLOBALS['ezInstance'] = null; + $ezInstance = null; unset($GLOBALS['ezInstance']); } + /** + * Clean input of XSS, html, javascript, etc... + * @param string $string + * + * @return string cleaned string + */ function cleanInput($string) { return ezQuery::clean($string); } + /** + * Returns an SQL string or result set, given the + * - table, column fields, conditions or conditional array. + * + * In the following format: + * ```js + * select( + * table, + * columns, + * (innerJoin(), leftJoin(), rightJoin(), fullJoin()), // alias of joining(inner|left|right|full, leftTable, rightTable, leftColumn, rightColumn, equal condition), + * where( eq( columns, values, _AND ), like( columns, _d ) ), + * groupBy( columns ), + * having( between( columns, values1, values2 ) ), + * orderBy( columns, desc ), + * limit( numberOfRecords, offset ), + * union(table, columnFields, conditions), // Returns an select SQL string with `UNION` + * unionAll(table, columnFields, conditions) // Returns an select SQL string with `UNION ALL` + *); + * ``` + * @param $table, - database table to access + * @param $columnFields, - table columns, string or array + * @param mixed ...$conditions - of the following parameters: + * + * @param $joins, - join clause (type, left table, right table, left column, right column, condition = EQ) + * @param $whereKey, - where clause ( comparison(x, y, and) ) + * @param $groupBy, - grouping over clause the results + * @param $having, - having clause ( comparison(x, y, and) ) + * @param $orderby, - ordering by clause for the query + * @param $limit, - limit clause the number of records + * @param $union/$unionAll - union clause combine the result sets and removes duplicate rows/does not remove + * + * @return mixed result set - see docs for more details, or false for error + */ function select($table = '', $columns = '*', ...$args) { $ezQuery = \getInstance(); @@ -317,6 +563,15 @@ function select($table = '', $columns = '*', ...$args) : false; } + /** + * Does an select into statement by calling selecting method + * @param $newTable, - new database table to be created + * @param $fromColumns - the columns from old database table + * @param $oldTable - old database table + * @param $fromWhere, - where clause ( array(x, =, y, and, extra) ) or ( "x = y and extra" ) + * + * @return mixed bool/result - false for error + */ function select_into($table, $columns = '*', $old = null, ...$args) { $ezQuery = \getInstance(); @@ -325,7 +580,15 @@ function select_into($table, $columns = '*', $old = null, ...$args) : false; } - function insert_select($totable = '', $columns = '*', $fromTable, $from = '*', ...$args) + /** + * Does an insert into select statement by calling insert method helper then selecting method + * @param $toTable, - database table to insert table into + * @param $toColumns - the receiving columns from other table columns, leave blank for all or array of column fields + * @param $WhereKey, - where clause ( array(x, =, y, and, extra) ) or ( "x = y and extra" ) + * + * @return mixed bool/id of inserted record, or false for error + */ + function insert_select($totable = '', $columns = '*', $fromTable = null, $from = '*', ...$args) { $ezQuery = \getInstance(); return ($ezQuery instanceof DatabaseInterface) @@ -333,6 +596,16 @@ function insert_select($totable = '', $columns = '*', $fromTable, $from = '*', . : false; } + /** + * Does an create select statement by calling selecting method + * + * @param $newTable, - new database table to be created + * @param $fromColumns - the columns from old database table + * @param $oldTable - old database table + * @param $fromWhere, - where clause ( array(x, =, y, and, extra) ) or ( "x = y and extra" ) + * + * @return mixed bool/result - false for error + */ function create_select($table, $from, $old = null, ...$args) { $ezQuery = \getInstance(); @@ -341,14 +614,68 @@ function create_select($table, $from, $old = null, ...$args) : false; } - function where(...$args) + /** + * Returns an `WHERE` **sql clause** string. + * + * format: + * `where( comparison(x, y, and) )` + * + * example: + * `where( eq(key, value ), like('key', '_%?');` + * + * @param array $whereConditions - In the following format: + *```js + * eq('key/Field/Column', $value, _AND), // combine next expression + * neq('key/Field/Column', $value, _OR), // will combine next expression if + * ne('key/Field/Column', $value), // the default is _AND so will combine next expression + * lt('key/Field/Column', $value) + * lte('key/Field/Column', $value) + * gt('key/Field/Column', $value) + * gte('key/Field/Column', $value) + * isNull('key/Field/Column') + * isNotNull('key/Field/Column') + * like('key/Field/Column', '_%') + * notLike('key/Field/Column', '_%') + * in('key/Field/Column', $values) + * notIn('key/Field/Column', $values) + * between('key/Field/Column', $value, $value2) + * notBetween('key/Field/Column', $value, $value2) + *``` + * @return mixed bool/string - WHERE sql statement, or false on error + */ + function where(...$whereConditions) { $ezQuery = \getInstance(); return ($ezQuery instanceof DatabaseInterface) - ? $ezQuery->where(...$args) + ? $ezQuery->where(...$whereConditions) : false; } + /** + * Adds WHERE grouping to the conditions + * + * format: + * `grouping( comparison(x, y, and) )` + * + * example: + * `grouping( eq(key, value, combiner ), eq(key, value, combiner ) );` + * + * @param array $whereConditions - In the following format: + *```js + * eq('key/Field/Column', $value, _AND), // combine next expression + * neq('key/Field/Column', $value, _OR), // will combine next expression again + * ne('key/Field/Column', $value), // the default is _AND so will combine next expression + * lt('key/Field/Column', $value) + * lte('key/Field/Column', $value) + * gt('key/Field/Column', $value) + * gte('key/Field/Column', $value) + * isNull('key/Field/Column') + * isNotNull('key/Field/Column') + * like('key/Field/Column', '_%') + * notLike('key/Field/Column', '_%') + *``` + * @return array modified conditions + */ function grouping(...$args) { $ezQuery = \getInstance(); @@ -357,6 +684,20 @@ function grouping(...$args) : false; } + /** + * Specifies a grouping over the results of the query. + * + * selecting('table', + * 'columns', + * where( eq( 'columns', values, _AND ), like( 'columns', _d ) ), + * groupBy( 'columns' ), + * having( between( 'columns', values1, values2 ) ), + * orderBy( 'columns', 'desc' ); + * + * @param mixed $groupBy The grouping expression. + * + * @return string - GROUP BY SQL statement, or false on error + */ function groupBy($groupBy) { $ezQuery = \getInstance(); @@ -365,6 +706,29 @@ function groupBy($groupBy) : false; } + /** + * Specifies a restriction over the groups of the query. + * + * format + * `having( array(x, =, y, and, extra) );` or + * `having( "x = y and extra" );` + * + * example: + * `having( array(key, operator, value, combine, extra) );`or + * `having( "key operator value combine extra" );` + * + * @param array $having + * @param string $key, - table column + * @param string $operator, - set the operator condition, + * either '<','>', '=', '!=', '>=', '<=', '<>', 'in', + * 'like', 'between', 'not between', 'is null', 'is not null' + * @param mixed $value, - will be escaped + * @param string $combine, - combine additional where clauses with, + * either 'AND','OR', 'NOT', 'AND NOT' + * or carry over of @value in the case the @operator is 'between' or 'not between' + * @param string $extra - carry over of @combine in the case the operator is 'between' or 'not between' + * @return bool/string - HAVING SQL statement, or false on error + */ function having(...$args) { $ezQuery = \getInstance(); @@ -373,6 +737,29 @@ function having(...$args) : false; } + /** + * Return all rows from multiple tables where the join condition is met. + * + * - Will perform an equal on tables by left column key, + * left column key and left table, left column key and right table, + * if `rightColumn` is null. + * + * - Will perform an equal on tables by, + * left column key and left table, right column key and right table, + * if `rightColumn` not null, and `$condition` not changed. + * + * - Will perform the `condition` on passed in arguments, for left column, and right column. + * if `$condition`, is in the array + * + * @param string $leftTable - + * @param string $rightTable - + * @param string $leftColumn - + * @param string $rightColumn - + * @param string $tableAs - + * @param string $condition - + * + * @return bool|string JOIN sql statement, false for error + */ function innerJoin( $leftTable = '', $rightTable = '', @@ -387,6 +774,31 @@ function innerJoin( : false; } + /** + * This type of join returns all rows from the LEFT-hand table + * specified in the ON condition and only those rows from the other table + * where the joined fields are equal (join condition is met). + * + * - Will perform an equal on tables by left column key, + * left column key and left table, left column key and right table, + * if `rightColumn` is null. + * + * - Will perform an equal on tables by, + * left column key and left table, right column key and right table, + * if `rightColumn` not null, and `$condition` not changed. + * + * - Will perform the `condition` on passed in arguments, for left column, and right column. + * if `$condition`, is in the array + * + * @param string $leftTable - + * @param string $rightTable - + * @param string $leftColumn - + * @param string $rightColumn - + * @param string $tableAs - + * @param string $condition - + * + * @return bool|string JOIN sql statement, false for error + */ function leftJoin( $leftTable = '', $rightTable = '', @@ -401,6 +813,31 @@ function leftJoin( : false; } + /** + * This type of join returns all rows from the RIGHT-hand table + * specified in the ON condition and only those rows from the other table + * where the joined fields are equal (join condition is met). + * + * - Will perform an equal on tables by left column key, + * left column key and left table, left column key and right table, + * if `rightColumn` is null. + * + * - Will perform an equal on tables by, + * left column key and left table, right column key and right table, + * if `rightColumn` not null, and `$condition` not changed. + * + * - Will perform the `condition` on passed in arguments, for left column, and right column. + * if `$condition`, is in the array + * + * @param string $leftTable - + * @param string $rightTable - + * @param string $leftColumn - + * @param string $rightColumn - + * @param string $tableAs - + * @param string $condition - + * + * @return bool|string JOIN sql statement, false for error + */ function rightJoin( $leftTable = '', $rightTable = '', @@ -415,6 +852,30 @@ function rightJoin( : false; } + /** + * This type of join returns all rows from the LEFT-hand table and RIGHT-hand table + * with NULL values in place where the join condition is not met. + * + * - Will perform an equal on tables by left column key, + * left column key and left table, left column key and right table, + * if `rightColumn` is null. + * + * - Will perform an equal on tables by, + * left column key and left table, right column key and right table, + * if `rightColumn` not null, and `$condition` not changed. + * + * - Will perform the `condition` on passed in arguments, for left column, and right column. + * if `$condition`, is in the array + * + * @param string $leftTable - + * @param string $rightTable - + * @param string $leftColumn - + * @param string $rightColumn - + * @param string $tableAs - + * @param string $condition - + * + * @return bool|string JOIN sql statement, false for error + */ function fullJoin( $leftTable = '', $rightTable = '', @@ -429,6 +890,30 @@ function fullJoin( : false; } + /** + * Returns an `UNION` SELECT SQL string, given the + * - table, column fields, conditions or conditional array. + * + * In the following format: + * ``` + * union( + * table, + * columns, + * // innerJoin(), leftJoin(), rightJoin(), fullJoin() alias of + * joining(inner|left|right|full, leftTable, rightTable, leftColumn, rightColumn, equal condition), + * where( eq( columns, values, _AND ), like( columns, _d ) ), + * groupBy( columns ), + * having( between( columns, values1, values2 ) ), + * orderBy( columns, desc ), + * limit( numberOfRecords, offset ) + *); + * ``` + * @param $table, - database table to access + * @param $columnFields, - table columns, string or array + * @param mixed $conditions - same as selecting method. + * + * @return bool|string - false for error + */ function union($table = '', $columnFields = '*', ...$conditions) { $ezQuery = \getInstance(); @@ -437,6 +922,30 @@ function union($table = '', $columnFields = '*', ...$conditions) : false; } + /** + * Returns an `UNION ALL` SELECT SQL string, given the + * - table, column fields, conditions or conditional array. + * + * In the following format: + * ``` + * unionAll( + * table, + * columns, + * // innerJoin(), leftJoin(), rightJoin(), fullJoin() alias of + * joining(inner|left|right|full, leftTable, rightTable, leftColumn, rightColumn, equal condition), + * where( eq( columns, values, _AND ), like( columns, _d ) ), + * groupBy( columns ), + * having( between( columns, values1, values2 ) ), + * orderBy( columns, desc ), + * limit( numberOfRecords, offset ) + *); + * ``` + * @param $table, - database table to access + * @param $columnFields, - table columns, string or array + * @param mixed $conditions - same as selecting method. + * + * @return bool|string - false for error + */ function unionAll($table = '', $columnFields = '*', ...$conditions) { $ezQuery = \getInstance(); @@ -445,6 +954,13 @@ function unionAll($table = '', $columnFields = '*', ...$conditions) : false; } + /** + * Specifies an ordering for the query results. + * @param string $orderBy - The column. + * @param string $order - The ordering direction. + * + * @return string - ORDER BY SQL statement, or false on error + */ function orderBy($orderBy, $order) { $ezQuery = \getInstance(); @@ -453,6 +969,15 @@ function orderBy($orderBy, $order) : false; } + /** + * Specifies records from one or more tables in a database and + * limit the number of records returned. + * + * @param int $numberOf - set limit number of records to be returned. + * @param int $offset - Optional. The first row returned by LIMIT will be determined by offset value. + * + * @return string - LIMIT and/or OFFSET SQL statement, or false on error + */ function limit($numberOf, $offset = null) { $ezQuery = \getInstance(); @@ -461,7 +986,13 @@ function limit($numberOf, $offset = null) : false; } - function insert($table = '', $keyValue) + /** + * Does an insert query with an array + * @param $table, - database table to access + * @param $keyAndValue - table fields, assoc array with key = value (doesn't need escaped) + * @return mixed bool/id of inserted record, or false for error + */ + function insert($table = '', $keyValue = null) { $ezQuery = \getInstance(); return ($ezQuery instanceof DatabaseInterface) @@ -469,7 +1000,15 @@ function insert($table = '', $keyValue) : false; } - function update($table = '', $keyValue, ...$args) + /** + * Does an update query with an array, by conditional operator array + * @param $table, - database table to access + * @param $keyAndValue, - table fields, assoc array with key = value (doesn't need escaped) + * @param $WhereKey, - where clause ( array(x, =, y, and, extra) ) or ( "x = y and extra" ) + * + * @return mixed bool/results - false for error + */ + function update($table = '', $keyValue = null, ...$args) { $ezQuery = \getInstance(); return ($ezQuery instanceof DatabaseInterface) @@ -477,6 +1016,10 @@ function update($table = '', $keyValue, ...$args) : false; } + /** + * Does the delete query with an array + * @return mixed bool/results - false for error + */ function deleting($table = '', ...$args) { $ezQuery = \getInstance(); @@ -485,7 +1028,13 @@ function deleting($table = '', ...$args) : false; } - function replace($table = '', $keyValue) + /** + * Does an replace query with an array + * @param $table, - database table to access + * @param $keyAndValue - table fields, assoc array with key = value (doesn't need escaped) + * @return mixed bool/id of replaced record, or false for error + */ + function replace($table = '', $keyValue = null) { $ezQuery = \getInstance(); return ($ezQuery instanceof DatabaseInterface) diff --git a/lib/ezQuery.php b/lib/ezQuery.php index 7c02ac73..88a76f5d 100644 --- a/lib/ezQuery.php +++ b/lib/ezQuery.php @@ -723,7 +723,7 @@ public function delete(string $table = null, ...$whereConditions) * Helper does the actual insert or replace query with an array * @return mixed bool/results - false for error */ - private function _query_insert_replace($table = '', $keyAndValue, $type = '', $execute = true) + private function _query_insert_replace($table = '', $keyAndValue = null, $type = '', $execute = true) { if ((!\is_array($keyAndValue) && ($execute)) || empty($table)) { return $this->clearPrepare(); @@ -812,7 +812,15 @@ public function get_results( return array(); } - // query call template + // + + /** + * query call template + * + * @param string $query + * @param bool $use_prepare + * @return bool|mixed + */ public function query(string $query, bool $use_prepare = false) { return false; @@ -965,6 +973,12 @@ public function alter(string $table = null, ...$schemas) return false; } + /** + * Does an drop table query if table exists. + * @param $table - database table to erase + * + * @return bool + */ public function drop(string $table = null) { if (empty($table)) diff --git a/lib/ezQueryInterface.php b/lib/ezQueryInterface.php index 5007d1d2..6ce44b58 100644 --- a/lib/ezQueryInterface.php +++ b/lib/ezQueryInterface.php @@ -304,7 +304,7 @@ public function limit($numberOf, $offset = null); * `grouping( eq(key, value, combiner ), eq(key, value, combiner ) );` * * @param array $whereConditions - In the following format: - * + *```js * eq('key/Field/Column', $value, _AND), // combine next expression * neq('key/Field/Column', $value, _OR), // will combine next expression again * ne('key/Field/Column', $value), // the default is _AND so will combine next expression @@ -316,7 +316,7 @@ public function limit($numberOf, $offset = null); * isNotNull('key/Field/Column') * like('key/Field/Column', '_%') * notLike('key/Field/Column', '_%') - * + *``` * @return array modified conditions */ public function grouping(...$whereConditions); @@ -331,9 +331,9 @@ public function grouping(...$whereConditions); * `where( eq(key, value ), like('key', '_%?');` * * @param array $whereConditions - In the following format: - * + *```js * eq('key/Field/Column', $value, _AND), // combine next expression - * neq('key/Field/Column', $value, _OR), // will combine next expression again + * neq('key/Field/Column', $value, _OR), // will combine next expression if * ne('key/Field/Column', $value), // the default is _AND so will combine next expression * lt('key/Field/Column', $value) * lte('key/Field/Column', $value) @@ -347,22 +347,22 @@ public function grouping(...$whereConditions); * notIn('key/Field/Column', $values) * between('key/Field/Column', $value, $value2) * notBetween('key/Field/Column', $value, $value2) - * + *``` * @return mixed bool/string - WHERE SQL statement, or false on error */ public function where(...$whereConditions); + /** * Returns an SQL string or result set, given the * - table, column fields, conditions or conditional array. * * In the following format: - * ``` - * selecting( + * ```js + * select( * table, * columns, - * // innerJoin(), leftJoin(), rightJoin(), fullJoin() alias of - * joining(inner|left|right|full, leftTable, rightTable, leftColumn, rightColumn, equal condition), + * (innerJoin(), leftJoin(), rightJoin(), fullJoin()), // alias of joining(inner|left|right|full, leftTable, rightTable, leftColumn, rightColumn, equal condition), * where( eq( columns, values, _AND ), like( columns, _d ) ), * groupBy( columns ), * having( between( columns, values1, values2 ) ), @@ -374,7 +374,7 @@ public function where(...$whereConditions); * ``` * @param $table, - database table to access * @param $columnFields, - table columns, string or array - * @param mixed $conditions - of the following parameters: + * @param mixed ...$conditions - of the following parameters: * * @param $joins, - join clause (type, left table, right table, left column, right column, condition = EQ) * @param $whereKey, - where clause ( comparison(x, y, and) ) diff --git a/lib/ezSchema.php b/lib/ezSchema.php index 8c0c75a0..e73f7d73 100644 --- a/lib/ezSchema.php +++ b/lib/ezSchema.php @@ -153,6 +153,11 @@ public function __call($type, $args) return $data; } + /** + * Returns the current global database vendor being used. + * + * @return string|null `mysqli`|`pgsql`|`sqlite3`|`sqlsrv` + */ public static function vendor() { $type = null; diff --git a/lib/ezsqlModel.php b/lib/ezsqlModel.php index 93710198..6de9efc3 100644 --- a/lib/ezsqlModel.php +++ b/lib/ezsqlModel.php @@ -174,9 +174,73 @@ public function __construct() } /** - * Use for Calling Non-Existent Functions, handling Getters and Setters + * Magic methods for Calling Non-Existent Functions, handling Getters and Setters. * @method set/get{property} - a property that needs to be accessed * + * @method void setDebug_All($args); + * @method void setTrace($args); + * @method void setDebug_Called($args); + * @method void setVarDump_Called($args); + * @method void setShow_Errors($args); + * @method void setNum_Queries($args); + * @method void setConn_Queries($args); + * @method void setCaptured_Errors($args); + * @method void setCache_Dir($args); + * @method void setUse_Disk_Cache($args); + * @method void setCache_Timeout($args); + * @method void setCache_Queries($args); + * @method void setCache_Inserts($args); + * @method void setNum_Rows($args); + * @method void setDb_Connect_Time($args); + * @method void setSql_Log_File($args); + * @method void setProfile_Times($args); + * @method void setInsert_Id($args); + * @method void setLast_Query($args); + * @method void setLast_Error($args); + * @method void setCol_Info($args); + * @method void setTimers($args); + * @method void setTotal_Query_Time($args); + * @method void setTrace_Log($args); + * @method void setUse_Trace_Log($args); + * @method void setDo_Profile($args); + * @method void setLast_Result($args); + * @method void setFrom_Disk_Cache($args); + * @method void setDebug_Echo_Is_On($args); + * @method void setFunc_Call($args); + * @method void setAll_Func_Calls($args); + * + * @method string getDebug_All(); + * @method string getTrace(); + * @method string getDebug_Called(); + * @method string getVarDump_Called(); + * @method string getShow_Errors(); + * @method string getNum_Queries(); + * @method string getConn_Queries(); + * @method string getCaptured_Errors(); + * @method string getCache_Dir(); + * @method string getUse_Disk_Cache(); + * @method string getCache_Timeout(); + * @method string getCache_Queries(); + * @method string getCache_Inserts(); + * @method string getNum_Rows(); + * @method string getDb_Connect_Time(); + * @method string getSql_Log_File(); + * @method string getProfile_Times(); + * @method string getInsert_Id(); + * @method string getLast_Query(); + * @method string getLast_Error(); + * @method string getCol_Info(); + * @method string getTimers(); + * @method string getTotal_Query_Time(); + * @method string getTrace_Log(); + * @method string getUse_Trace_Log(); + * @method string getDo_Profile(); + * @method string getLast_Result(); + * @method string getFrom_Disk_Cache(); + * @method string getDebug_Echo_Is_On(); + * @method string getFunc_Call(); + * @method string getAll_Func_Calls(); + * * @property-read function * @property-write args * @@ -258,8 +322,8 @@ public function flush() // Get rid of these $this->last_result = null; $this->col_info = array(); - $this->last_query = null; - $this->all_func_calls = array(); + $this->last_query = null; + $this->all_func_calls = array(); $this->from_disk_cache = false; $this->clearPrepare(); } @@ -337,7 +401,7 @@ public function get_col(string $query = null, int $x = 0, bool $use_prepare = fa return $new_array; } - public function get_results(string $query = null, $output = \OBJECT, bool $use_prepare = false) + public function get_results(string $query = null, $output = \OBJECT, bool $use_prepare = false) { // Log how the function was called $this->log_query("\$db->get_results(\"$query\", $output, $use_prepare)"); @@ -664,16 +728,31 @@ public function secureReset() $this->secureOptions = null; } + /** + * Returns `true` if the database connection is established. + * + * @return bool + */ public function isConnected() { return $this->_connected; } // isConnected + /** + * Returns the `number` of affected rows of a query. + * + * @return int + */ public function affectedRows() { return $this->_affectedRows; } // affectedRows + /** + * Returns the last query `result`. + * + * @return object + */ public function queryResult() { return $this->last_result; diff --git a/lib/ezsqlModelInterface.php b/lib/ezsqlModelInterface.php index 74b8be79..171e5f26 100644 --- a/lib/ezsqlModelInterface.php +++ b/lib/ezsqlModelInterface.php @@ -2,71 +2,6 @@ namespace ezsql; -/** - * @method void setDebug_All($args); - * @method void setTrace($args); - * @method void setDebug_Called($args); - * @method void setVarDump_Called($args); - * @method void setShow_Errors($args); - * @method void setNum_Queries($args); - * @method void setConn_Queries($args); - * @method void setCaptured_Errors($args); - * @method void setCache_Dir($args); - * @method void setUse_Disk_Cache($args); - * @method void setCache_Timeout($args); - * @method void setCache_Queries($args); - * @method void setCache_Inserts($args); - * @method void setNum_Rows($args); - * @method void setDb_Connect_Time($args); - * @method void setSql_Log_File($args); - * @method void setProfile_Times($args); - * @method void setInsert_Id($args); - * @method void setLast_Query($args); - * @method void setLast_Error($args); - * @method void setCol_Info($args); - * @method void setTimers($args); - * @method void setTotal_Query_Time($args); - * @method void setTrace_Log($args); - * @method void setUse_Trace_Log($args); - * @method void setDo_Profile($args); - * @method void setLast_Result($args); - * @method void setFrom_Disk_Cache($args); - * @method void setDebug_Echo_Is_On($args); - * @method void setFunc_Call($args); - * @method void setAll_Func_Calls($args); - * - * @method string getDebug_All(); - * @method string getTrace(); - * @method string getDebug_Called(); - * @method string getVarDump_Called(); - * @method string getShow_Errors(); - * @method string getNum_Queries(); - * @method string getConn_Queries(); - * @method string getCaptured_Errors(); - * @method string getCache_Dir(); - * @method string getUse_Disk_Cache(); - * @method string getCache_Timeout(); - * @method string getCache_Queries(); - * @method string getCache_Inserts(); - * @method string getNum_Rows(); - * @method string getDb_Connect_Time(); - * @method string getSql_Log_File(); - * @method string getProfile_Times(); - * @method string getInsert_Id(); - * @method string getLast_Query(); - * @method string getLast_Error(); - * @method string getCol_Info(); - * @method string getTimers(); - * @method string getTotal_Query_Time(); - * @method string getTrace_Log(); - * @method string getUse_Trace_Log(); - * @method string getDo_Profile(); - * @method string getLast_Result(); - * @method string getFrom_Disk_Cache(); - * @method string getDebug_Echo_Is_On(); - * @method string getFunc_Call(); - * @method string getAll_Func_Calls(); - */ interface ezsqlModelInterface { /** diff --git a/tests/EZTestCase.php b/tests/EZTestCase.php index d0e81728..3600f46c 100644 --- a/tests/EZTestCase.php +++ b/tests/EZTestCase.php @@ -42,7 +42,7 @@ abstract class EZTestCase extends \PHPUnit\Framework\TestCase protected $errors; - public function errorHandler($errno, $errstr, $errfile, $errline, $errcontext) + public function errorHandler($errno, $errstr, $errfile, $errline, $errcontext = null) { $this->errors[] = compact("errno", "errstr", "errfile", "errline", "errcontext"); } diff --git a/tests/ezFunctionsTest.php b/tests/ezFunctionsTest.php index e080bb21..197acba9 100644 --- a/tests/ezFunctionsTest.php +++ b/tests/ezFunctionsTest.php @@ -149,7 +149,6 @@ public function testNotBetween() public function testSetInstance() { $this->assertFalse(\setInstance()); - $this->assertFalse(\setInstance($this)); } public function testSelect() diff --git a/tests/mysqli/mysqliTest.php b/tests/mysqli/mysqliTest.php index 87618173..40d2f367 100644 --- a/tests/mysqli/mysqliTest.php +++ b/tests/mysqli/mysqliTest.php @@ -90,7 +90,7 @@ public function testSelect() $this->assertTrue($result); $this->errors = array(); - set_error_handler(array($this, 'errorHandler')); + //set_error_handler(array($this, 'errorHandler')); $this->assertTrue($this->object->select('')); $this->object->disconnect(); $this->assertFalse($this->object->select('notest')); diff --git a/tests/pdo/pdo_mysqlTest.php b/tests/pdo/pdo_mysqlTest.php index a46f2a2a..a6c1c7d5 100644 --- a/tests/pdo/pdo_mysqlTest.php +++ b/tests/pdo/pdo_mysqlTest.php @@ -16,7 +16,7 @@ class pdo_mysqlTest extends EZTestCase const TEST_DB_PORT = '3306'; /** - * @var resource + * @var \ezsql\Database\ez_pdo */ protected $object; @@ -288,23 +288,24 @@ public function testWhereGrouping() public function testJoins() { $this->assertTrue($this->object->connect('mysql:host=' . self::TEST_DB_HOST . ';dbname=' . self::TEST_DB_NAME . ';port=' . self::TEST_DB_PORT, self::TEST_DB_USER, self::TEST_DB_PASSWORD)); + $this->object->query('DROP TABLE unit_test'); $this->object->query('CREATE TABLE unit_test(id integer, test_key varchar(50), PRIMARY KEY (ID))'); $this->object->insert('unit_test', array('id' => '1', 'test_key' => 'testing 1')); $this->object->insert('unit_test', array('id' => '2', 'test_key' => 'testing 2')); $this->object->insert('unit_test', array('id' => '3', 'test_key' => 'testing 3')); $this->object->query('CREATE TABLE unit_test_child(child_id integer, child_test_key varchar(50), parent_id integer, PRIMARY KEY (child_id))'); - $this->object->insert('unit_test', array('child_id' => '1', 'child_test_key' => 'testing child 1', 'parent_id' => '3')); - $this->object->insert('unit_test', array('child_id' => '2', 'child_test_key' => 'testing child 2', 'parent_id' => '2')); - $this->object->insert('unit_test', array('child_id' => '3', 'child_test_key' => 'testing child 3', 'parent_id' => '1')); + $this->object->insert('unit_test_child', array('child_id' => '1', 'child_test_key' => 'testing child 1', 'parent_id' => '3')); + $this->object->insert('unit_test_child', array('child_id' => '2', 'child_test_key' => 'testing child 2', 'parent_id' => '2')); + $this->object->insert('unit_test_child', array('child_id' => '3', 'child_test_key' => 'testing child 3', 'parent_id' => '1')); $result = $this->object->selecting('unit_test_child', '*', leftJoin('unit_test_child', 'unit_test', 'parent_id', 'id')); $i = 1; $o = 3; foreach ($result as $row) { - $this->assertEquals($i, $row->child_id); - $this->assertEquals('testing child ' . $i, $row->child_test_key); - $this->assertEquals($o, $row->id); - $this->assertEquals('testing ' . $o, $row->test_key); + $this->assertEquals($o, $row->child_id); + $this->assertEquals('testing child ' . $o, $row->child_test_key); + $this->assertEquals($i, $row->id); + $this->assertEquals('testing ' . $i, $row->test_key); ++$i; --$o; } @@ -323,6 +324,7 @@ public function testJoins() public function testBeginTransactionCommit() { $this->object->connect(); + $this->object->query('DROP TABLE unit_test'); $this->object->query('CREATE TABLE unit_test(id integer, test_key varchar(50), PRIMARY KEY (ID))'); $commit = null; @@ -355,6 +357,7 @@ public function testBeginTransactionCommit() public function testBeginTransactionRollback() { $this->object->connect(); + $this->object->query('DROP TABLE unit_test'); $this->object->query('CREATE TABLE unit_test(id integer, test_key varchar(50), PRIMARY KEY (ID))'); $commit = null; diff --git a/tests/pdo/pdo_pgsqlTest.php b/tests/pdo/pdo_pgsqlTest.php index 58a91eb1..ea6f314c 100644 --- a/tests/pdo/pdo_pgsqlTest.php +++ b/tests/pdo/pdo_pgsqlTest.php @@ -18,7 +18,7 @@ class pdo_pgsqlTest extends EZTestCase const TEST_SQLITE_DB = 'ez_test.sqlite'; /** - * @var resource + * @var \ezsql\Database\ez_pdo */ protected $object; @@ -102,6 +102,7 @@ public function testInsert() public function testUpdate() { $this->assertTrue($this->object->connect('pgsql:host=' . self::TEST_DB_HOST . ';dbname=' . self::TEST_DB_NAME . ';port=' . self::TEST_DB_PORT, self::TEST_DB_USER, self::TEST_DB_PASSWORD)); + $this->object->drop('unit_test'); $this->object->query('CREATE TABLE unit_test(id serial, test_key varchar(50), test_value varchar(50), PRIMARY KEY (ID))'); $this->object->insert('unit_test', array('test_key' => 'test 1', 'test_value' => 'testing string 1')); @@ -134,6 +135,7 @@ public function testUpdate() public function testDelete() { $this->assertTrue($this->object->connect('pgsql:host=' . self::TEST_DB_HOST . ';dbname=' . self::TEST_DB_NAME . ';port=' . self::TEST_DB_PORT, self::TEST_DB_USER, self::TEST_DB_PASSWORD)); + $this->object->drop('unit_test'); $this->object->query('CREATE TABLE unit_test(id serial, test_key varchar(50), test_value varchar(50), PRIMARY KEY (ID))'); $this->object->insert('unit_test', array('test_key' => 'test 1', 'test_value' => 'testing string 1')); $this->object->insert('unit_test', array('test_key' => 'test 2', 'test_value' => 'testing string 2')); @@ -157,6 +159,7 @@ public function testDelete() public function testSelecting() { $this->assertTrue($this->object->connect('pgsql:host=' . self::TEST_DB_HOST . ';dbname=' . self::TEST_DB_NAME . ';port=' . self::TEST_DB_PORT, self::TEST_DB_USER, self::TEST_DB_PASSWORD)); + $this->object->drop('unit_test'); $this->object->query('CREATE TABLE unit_test(id serial, test_key varchar(50), test_value varchar(50), PRIMARY KEY (ID))'); $this->object->insert('unit_test', array('test_key' => 'test 1', 'test_value' => 'testing string 1')); $this->object->insert('unit_test', array('test_key' => 'test 2', 'test_value' => 'testing string 2')); @@ -187,37 +190,43 @@ public function testSelecting() foreach ($result as $row) { $this->assertEquals('testing string 1', $row->test_value); } + + $this->object->drop('unit_test'); } public function testWhereGrouping() { $this->assertTrue($this->object->connect('pgsql:host=' . self::TEST_DB_HOST . ';dbname=' . self::TEST_DB_NAME . ';port=' . self::TEST_DB_PORT, self::TEST_DB_USER, self::TEST_DB_PASSWORD)); - $this->object->query('CREATE TABLE unit_test(id integer, test_key varchar(50), active tinyint(1), PRIMARY KEY (ID))'); - $this->object->insert('unit_test', array('id' => '1', 'test_key' => 'testing 1', 'active' => 1)); - $this->object->insert('unit_test', array('id' => '2', 'test_key' => 'testing 2', 'active' => 0)); - $this->object->insert('unit_test', array('id' => '3', 'test_key' => 'testing 3', 'active' => 1)); - $this->object->insert('unit_test', array('id' => '4', 'test_key' => 'testing 4', 'active' => 1)); - - $result = $this->object->selecting('unit_test', '*', where(eq('active', '1'), grouping(like('test_key', '%1%', _OR), like('test_key', '%3%')))); + $this->object->drop('unit_test_more'); + $this->object->query('CREATE TABLE unit_test_more(id serial, test_key varchar(50), active_data integer, PRIMARY KEY (ID))'); + $this->object->insert('unit_test_more', array('test_key' => 'testing 1', 'active_data' => 1)); + $this->object->insert('unit_test_more', array('test_key' => 'testing 2', 'active_data' => 0)); + $this->object->insert('unit_test_more', array('test_key' => 'testing 3', 'active_data' => 1)); + $this->object->insert('unit_test_more', array('test_key' => 'testing 4', 'active_data' => 1)); + + $result = $this->object->selecting('unit_test_more', '*', where(eq('active_data', 1), grouping(like('test_key', '%1%', _OR), like('test_key', '%3%')))); $i = 1; foreach ($result as $row) { $this->assertEquals($i, $row->id); $this->assertEquals('testing ' . $i, $row->test_key); $i = $i + 2; } + + $this->object->drop('unit_test_more'); } public function testJoins() { $this->assertTrue($this->object->connect('pgsql:host=' . self::TEST_DB_HOST . ';dbname=' . self::TEST_DB_NAME . ';port=' . self::TEST_DB_PORT, self::TEST_DB_USER, self::TEST_DB_PASSWORD)); + $this->object->drop('unit_test'); $this->object->query('CREATE TABLE unit_test(id integer, test_key varchar(50), PRIMARY KEY (ID))'); $this->object->insert('unit_test', array('id' => '1', 'test_key' => 'testing 1')); $this->object->insert('unit_test', array('id' => '2', 'test_key' => 'testing 2')); $this->object->insert('unit_test', array('id' => '3', 'test_key' => 'testing 3')); $this->object->query('CREATE TABLE unit_test_child(child_id integer, child_test_key varchar(50), parent_id integer, PRIMARY KEY (child_id))'); - $this->object->insert('unit_test', array('child_id' => '1', 'child_test_key' => 'testing child 1', 'parent_id' => '3')); - $this->object->insert('unit_test', array('child_id' => '2', 'child_test_key' => 'testing child 2', 'parent_id' => '2')); - $this->object->insert('unit_test', array('child_id' => '3', 'child_test_key' => 'testing child 3', 'parent_id' => '1')); + $this->object->insert('unit_test_child', array('child_id' => '1', 'child_test_key' => 'testing child 1', 'parent_id' => '3')); + $this->object->insert('unit_test_child', array('child_id' => '2', 'child_test_key' => 'testing child 2', 'parent_id' => '2')); + $this->object->insert('unit_test_child', array('child_id' => '3', 'child_test_key' => 'testing child 3', 'parent_id' => '1')); $result = $this->object->selecting('unit_test_child', '*', leftJoin('unit_test_child', 'unit_test', 'parent_id', 'id')); $i = 1; @@ -237,6 +246,9 @@ public function testJoins() $this->assertEquals($o, $row->parent_id); --$o; } + + $this->object->drop('unit_test'); + $this->object->drop('unit_test_child'); } public function testPosgreSQLDisconnect() diff --git a/tests/pdo/pdo_sqliteTest.php b/tests/pdo/pdo_sqliteTest.php index 2cc13485..d9644c73 100644 --- a/tests/pdo/pdo_sqliteTest.php +++ b/tests/pdo/pdo_sqliteTest.php @@ -17,7 +17,7 @@ class pdo_sqliteTest extends EZTestCase const TEST_SQLITE_DB = './tests/pdo/ez_test.sqlite'; /** - * @var resource + * @var \ezsql\Database\ez_pdo */ protected $object; @@ -219,6 +219,7 @@ public function testSelecting() public function testWhereGrouping() { $this->assertTrue($this->object->connect('sqlite:' . self::TEST_SQLITE_DB, '', '', array(), true)); + $this->object->drop('unit_test'); $this->object->query('CREATE TABLE unit_test(id integer, test_key varchar(50), active tinyint(1), PRIMARY KEY (ID))'); $this->object->insert('unit_test', array('id' => '1', 'test_key' => 'testing 1', 'active' => 1)); $this->object->insert('unit_test', array('id' => '2', 'test_key' => 'testing 2', 'active' => 0)); @@ -239,14 +240,15 @@ public function testWhereGrouping() public function testJoins() { $this->assertTrue($this->object->connect('sqlite:' . self::TEST_SQLITE_DB, '', '', array(), true)); + $this->object->drop('unit_test'); $this->object->query('CREATE TABLE unit_test(id integer, test_key varchar(50), PRIMARY KEY (ID))'); $this->object->insert('unit_test', array('id' => '1', 'test_key' => 'testing 1')); $this->object->insert('unit_test', array('id' => '2', 'test_key' => 'testing 2')); $this->object->insert('unit_test', array('id' => '3', 'test_key' => 'testing 3')); $this->object->query('CREATE TABLE unit_test_child(child_id integer, child_test_key varchar(50), parent_id integer, PRIMARY KEY (child_id))'); - $this->object->insert('unit_test', array('child_id' => '1', 'child_test_key' => 'testing child 1', 'parent_id' => '3')); - $this->object->insert('unit_test', array('child_id' => '2', 'child_test_key' => 'testing child 2', 'parent_id' => '2')); - $this->object->insert('unit_test', array('child_id' => '3', 'child_test_key' => 'testing child 3', 'parent_id' => '1')); + $this->object->insert('unit_test_child', array('child_id' => '1', 'child_test_key' => 'testing child 1', 'parent_id' => '3')); + $this->object->insert('unit_test_child', array('child_id' => '2', 'child_test_key' => 'testing child 2', 'parent_id' => '2')); + $this->object->insert('unit_test_child', array('child_id' => '3', 'child_test_key' => 'testing child 3', 'parent_id' => '1')); $result = $this->object->selecting('unit_test_child', '*', leftJoin('unit_test_child', 'unit_test', 'parent_id', 'id')); $i = 1; diff --git a/tests/pdo/pdo_sqlsrvTest.php b/tests/pdo/pdo_sqlsrvTest.php index de8e82bd..58619195 100644 --- a/tests/pdo/pdo_sqlsrvTest.php +++ b/tests/pdo/pdo_sqlsrvTest.php @@ -8,7 +8,7 @@ class pdo_sqlsrvTest extends EZTestCase { /** - * @var resource + * @var \ezsql\Database\ez_pdo */ protected $object; @@ -89,8 +89,8 @@ public function testInsert() public function testUpdate() { $this->assertTrue($this->object->connect('sqlsrv:Server=' . self::TEST_DB_HOST . ';Database=' . self::TEST_DB_NAME, self::TEST_DB_USER, self::TEST_DB_PASSWORD)); + $this->object->drop('unit_test'); $this->object->query('CREATE TABLE unit_test(id integer, test_key varchar(50), PRIMARY KEY (ID))'); - $this->assertNotFalse($this->object->insert('unit_test', array('id' => 1, 'test_key' => 'testUpdate() 1'))); $this->object->insert('unit_test', array('id' => 2, 'test_key' => 'testUpdate() 2')); $this->object->insert('unit_test', array('id' => 3, 'test_key' => 'testUpdate() 3')); @@ -163,6 +163,7 @@ public function testDelete() public function testSelecting() { $this->assertTrue($this->object->connect('sqlsrv:Server=' . self::TEST_DB_HOST . ';Database=' . self::TEST_DB_NAME, self::TEST_DB_USER, self::TEST_DB_PASSWORD)); + $this->object->drop('unit_test'); $this->object->query('CREATE TABLE unit_test(id integer, test_key varchar(50), PRIMARY KEY (ID))'); $this->object->insert('unit_test', array('id' => 8, 'test_key' => 'testing 8')); $this->object->insert('unit_test', array('id' => 9, 'test_key' => 'testing 9')); @@ -191,37 +192,42 @@ public function testSelecting() foreach ($result as $row) { $this->assertEquals('testing 8', $row->test_key); } + + $this->object->drop('unit_test'); } public function testWhereGrouping() { $this->assertTrue($this->object->connect('sqlsrv:Server=' . self::TEST_DB_HOST . ';Database=' . self::TEST_DB_NAME, self::TEST_DB_USER, self::TEST_DB_PASSWORD)); - $this->object->query('CREATE TABLE unit_test(id integer, test_key varchar(50), active tinyint(1), PRIMARY KEY (ID))'); - $this->object->insert('unit_test', array('id' => '1', 'test_key' => 'testing 1', 'active' => 1)); - $this->object->insert('unit_test', array('id' => '2', 'test_key' => 'testing 2', 'active' => 0)); - $this->object->insert('unit_test', array('id' => '3', 'test_key' => 'testing 3', 'active' => 1)); - $this->object->insert('unit_test', array('id' => '4', 'test_key' => 'testing 4', 'active' => 1)); + $this->object->query('CREATE TABLE unit_test_other(id integer, test_key varchar(50), active_data integer, PRIMARY KEY (ID))'); + $this->object->insert('unit_test_other', array('id' => 1, 'test_key' => 'testing 1', 'active_data' => 1)); + $this->object->insert('unit_test_other', array('id' => 2, 'test_key' => 'testing 2', 'active_data' => 0)); + $this->object->insert('unit_test_other', array('id' => 3, 'test_key' => 'testing 3', 'active_data' => 1)); + $this->object->insert('unit_test_other', array('id' => 4, 'test_key' => 'testing 4', 'active_data' => 1)); - $result = $this->object->selecting('unit_test', '*', where(eq('active', '1'), grouping(like('test_key', '%1%', _OR), like('test_key', '%3%')))); + $result = $this->object->selecting('unit_test_other', '*', where(eq('active_data', '1'), grouping(like('test_key', '%1%', _OR), like('test_key', '%3%')))); $i = 1; foreach ($result as $row) { $this->assertEquals($i, $row->id); $this->assertEquals('testing ' . $i, $row->test_key); $i = $i + 2; } + + $this->object->drop('unit_test_other'); } public function testJoins() { $this->assertTrue($this->object->connect('sqlsrv:Server=' . self::TEST_DB_HOST . ';Database=' . self::TEST_DB_NAME, self::TEST_DB_USER, self::TEST_DB_PASSWORD)); + $this->object->drop('unit_test'); $this->object->query('CREATE TABLE unit_test(id integer, test_key varchar(50), PRIMARY KEY (ID))'); $this->object->insert('unit_test', array('id' => '1', 'test_key' => 'testing 1')); $this->object->insert('unit_test', array('id' => '2', 'test_key' => 'testing 2')); $this->object->insert('unit_test', array('id' => '3', 'test_key' => 'testing 3')); $this->object->query('CREATE TABLE unit_test_child(child_id integer, child_test_key varchar(50), parent_id integer, PRIMARY KEY (child_id))'); - $this->object->insert('unit_test', array('child_id' => '1', 'child_test_key' => 'testing child 1', 'parent_id' => '3')); - $this->object->insert('unit_test', array('child_id' => '2', 'child_test_key' => 'testing child 2', 'parent_id' => '2')); - $this->object->insert('unit_test', array('child_id' => '3', 'child_test_key' => 'testing child 3', 'parent_id' => '1')); + $this->object->insert('unit_test_child', array('child_id' => '1', 'child_test_key' => 'testing child 1', 'parent_id' => '3')); + $this->object->insert('unit_test_child', array('child_id' => '2', 'child_test_key' => 'testing child 2', 'parent_id' => '2')); + $this->object->insert('unit_test_child', array('child_id' => '3', 'child_test_key' => 'testing child 3', 'parent_id' => '1')); $result = $this->object->selecting('unit_test_child', '*', leftJoin('unit_test_child', 'unit_test', 'parent_id', 'id')); $i = 1; @@ -241,6 +247,9 @@ public function testJoins() $this->assertEquals($o, $row->parent_id); --$o; } + + $this->object->drop('unit_test'); + $this->object->drop('unit_test_child'); } public function testSQLsrvDisconnect() diff --git a/tests/sqlsrv/sqlsrvTest.php b/tests/sqlsrv/sqlsrvTest.php index 21d1f682..04df061f 100644 --- a/tests/sqlsrv/sqlsrvTest.php +++ b/tests/sqlsrv/sqlsrvTest.php @@ -37,7 +37,7 @@ protected function setUp(): void */ protected function tearDown(): void { - $this->object->query('DROP TABLE unit_test'); + $this->object->drop('unit_test'); $this->object = null; } @@ -363,9 +363,9 @@ public function testQuery_prepared() column('prepare_key', VARCHAR, 50) ); - $this->object->insert('prepare_test', ['id' => 1, 'prepare_key' => 'test 2']); - $this->object->query_prepared('INSERT INTO prepare_test( id, prepare_key ) VALUES( ?, ? )', [4, 'test 10']); - $this->object->query_prepared('INSERT INTO prepare_test( id, prepare_key ) VALUES( ?, ? )', [9, 'test 3']); + $this->object->query_prepared('INSERT INTO prepare_test(id, prepare_key ) VALUES( ?, ? )', [1, 'test 2']); + $this->object->query_prepared('INSERT INTO prepare_test(id, prepare_key ) VALUES( ?, ? )', [4, 'test 10']); + $this->object->query_prepared('INSERT INTO prepare_test(id, prepare_key ) VALUES( ?, ? )', [9, 'test 3']); $this->object->query_prepared('SELECT id, prepare_key FROM prepare_test WHERE id = ?', [9]); $query = $this->object->queryResult(); diff --git a/unsupported/install_sql.sh b/unsupported/install_sql.sh deleted file mode 100644 index e2ad2acb..00000000 --- a/unsupported/install_sql.sh +++ /dev/null @@ -1,122 +0,0 @@ -#!/bin/bash -e - -# Use the following variables to control your install: - -# Password for the SA user (required) -MSSQL_SA_PASSWORD='MasterTest' - -# Product ID of the version of SQL server you're installing -# Must be evaluation, developer, express, web, standard, enterprise, or your 25 digit product key -# Defaults to developer -MSSQL_PID='evaluation' - -# Install SQL Server Agent (recommended) -SQL_INSTALL_AGENT='y' - -# Install SQL Server Full Text Search (optional) -# SQL_INSTALL_FULLTEXT='y' - -# Create an additional user with sysadmin privileges (optional) -SQL_INSTALL_USER='ez_test' -SQL_INSTALL_USER_PASSWORD='ezTest' - -if [ -z $MSSQL_SA_PASSWORD ] -then - echo Environment variable MSSQL_SA_PASSWORD must be set for unattended install - exit 1 -fi - -echo Adding Microsoft repositories... -sudo curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add - -repoargs="$(curl https://packages.microsoft.com/config/ubuntu/16.04/mssql-server-2017.list)" -sudo add-apt-repository "${repoargs}" -repoargs="$(curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list)" -sudo add-apt-repository "${repoargs}" - -echo Running apt-get update -y... -sudo apt-get update -y - -echo Installing SQL Server... -sudo apt-get install -y mssql-server - -echo Running mssql-conf setup... -sudo MSSQL_SA_PASSWORD=$MSSQL_SA_PASSWORD \ - MSSQL_PID=$MSSQL_PID \ - /opt/mssql/bin/mssql-conf -n setup accept-eula - -echo Installing mssql-tools and unixODBC developer... -sudo ACCEPT_EULA=Y apt-get install -y mssql-tools unixodbc-dev - -# Add SQL Server tools to the path by default: -echo Adding SQL Server tools to your path... -echo PATH="$PATH:/opt/mssql-tools/bin" >> ~/.bash_profile -echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc - -# Optional SQL Server Agent installation: -if [ ! -z $SQL_INSTALL_AGENT ] -then - echo Installing SQL Server Agent... - sudo apt-get install -y mssql-server-agent -fi - -# Optional SQL Server Full Text Search installation: -if [ ! -z $SQL_INSTALL_FULLTEXT ] -then - echo Installing SQL Server Full-Text Search... - sudo apt-get install -y mssql-server-fts -fi - -# Configure firewall to allow TCP port 1433: -echo Configuring UFW to allow traffic on port 1433... -sudo ufw allow 1433/tcp -sudo ufw reload - -# Optional example of post-installation configuration. -# Trace flags 1204 and 1222 are for deadlock tracing. -# echo Setting trace flags... -# sudo /opt/mssql/bin/mssql-conf traceflag 1204 1222 on - -# Restart SQL Server after installing: -echo Restarting SQL Server... -sudo systemctl restart mssql-server - -# Connect to server and get the version: -counter=1 -errstatus=1 -while [ $counter -le 5 ] && [ $errstatus = 1 ] -do - echo Waiting for SQL Server to start... - sleep 3s - /opt/mssql-tools/bin/sqlcmd \ - -S localhost \ - -U SA \ - -P $MSSQL_SA_PASSWORD \ - -Q "SELECT @@VERSION" 2>/dev/null - errstatus=$? - ((counter++)) -done - -# Display error if connection failed: -if [ $errstatus = 1 ] -then - echo Cannot connect to SQL Server, installation aborted - exit $errstatus -fi - -# Optional new user creation: -if [ ! -z $SQL_INSTALL_USER ] && [ ! -z $SQL_INSTALL_USER_PASSWORD ] -then - echo Creating user $SQL_INSTALL_USER - /opt/mssql-tools/bin/sqlcmd \ - -S localhost \ - -U SA \ - -P $MSSQL_SA_PASSWORD \ - -Q "CREATE LOGIN [$SQL_INSTALL_USER] WITH PASSWORD=N'$SQL_INSTALL_USER_PASSWORD', DEFAULT_DATABASE=[master], CHECK_EXPIRATION=ON, CHECK_POLICY=ON; ALTER SERVER ROLE [sysadmin] ADD MEMBER [$SQL_INSTALL_USER]" - /opt/mssql-tools/bin/sqlcmd \ - -S localhost \ - -U SA \ - -P $MSSQL_SA_PASSWORD \ - -Q "CREATE DATABASE ez_test" -fi - -echo Done!