Enable ATTR_EMULATE_PREPARES for MariaDB specifically #132
This commit is contained in:
@@ -2,12 +2,11 @@
|
|||||||
|
|
||||||
namespace App\Console\Commands;
|
namespace App\Console\Commands;
|
||||||
|
|
||||||
use App\Models\Airline;
|
|
||||||
use App\Models\Permission;
|
|
||||||
use App\Models\Role;
|
|
||||||
use App\Models\User;
|
|
||||||
use App\Services\DatabaseService;
|
|
||||||
use DB;
|
use DB;
|
||||||
|
use PDO;
|
||||||
|
|
||||||
|
use App\Models\Airline;
|
||||||
|
use App\Models\User;
|
||||||
|
|
||||||
use App\Console\BaseCommand;
|
use App\Console\BaseCommand;
|
||||||
use App\Models\Acars;
|
use App\Models\Acars;
|
||||||
@@ -34,6 +33,7 @@ class DevCommands extends BaseCommand
|
|||||||
'clear-acars' => 'clearAcars',
|
'clear-acars' => 'clearAcars',
|
||||||
'clear-users' => 'clearUsers',
|
'clear-users' => 'clearUsers',
|
||||||
'compile-assets' => 'compileAssets',
|
'compile-assets' => 'compileAssets',
|
||||||
|
'db-attrs' => 'dbAttrs',
|
||||||
];
|
];
|
||||||
|
|
||||||
if(!array_key_exists($command, $commands)) {
|
if(!array_key_exists($command, $commands)) {
|
||||||
@@ -92,4 +92,20 @@ class DevCommands extends BaseCommand
|
|||||||
$this->runCommand('npm update');
|
$this->runCommand('npm update');
|
||||||
$this->runCommand('npm run dev');
|
$this->runCommand('npm run dev');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Output DB prepares versions
|
||||||
|
*/
|
||||||
|
protected function dbAttrs()
|
||||||
|
{
|
||||||
|
$pdo = DB::connection()->getPdo();
|
||||||
|
$emulate_prepares_below_version = '5.1.17';
|
||||||
|
$server_version = $pdo->getAttribute(PDO::ATTR_SERVER_VERSION);
|
||||||
|
$emulate_prepares = version_compare($server_version, $emulate_prepares_below_version, '<');
|
||||||
|
|
||||||
|
$this->info('Server Version: '. $server_version);
|
||||||
|
$this->info('Emulate Prepares: '.$emulate_prepares);
|
||||||
|
|
||||||
|
$pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, $emulate_prepares);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ return [
|
|||||||
'strict' => false,
|
'strict' => false,
|
||||||
'engine' => null,
|
'engine' => null,
|
||||||
'options' => [
|
'options' => [
|
||||||
PDO::ATTR_EMULATE_PREPARES => false,
|
PDO::ATTR_EMULATE_PREPARES => env('DB_EMULATE_PREPARES', false),
|
||||||
#PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
|
#PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ DB_PORT={!! $DB_PORT !!}
|
|||||||
DB_DATABASE={!! $DB_NAME !!}
|
DB_DATABASE={!! $DB_NAME !!}
|
||||||
DB_USERNAME={!! $DB_USER !!}
|
DB_USERNAME={!! $DB_USER !!}
|
||||||
DB_PASSWORD={!! $DB_PASS !!}
|
DB_PASSWORD={!! $DB_PASS !!}
|
||||||
|
DB_EMULATE_PREPARES={!! $DB_EMULATE_PREPARES !!}
|
||||||
DB_PREFIX=
|
DB_PREFIX=
|
||||||
|
|
||||||
MAIL_DRIVER=smtp
|
MAIL_DRIVER=smtp
|
||||||
|
|||||||
@@ -2,18 +2,21 @@
|
|||||||
|
|
||||||
namespace Modules\Installer\Services;
|
namespace Modules\Installer\Services;
|
||||||
|
|
||||||
use Illuminate\Encryption\Encrypter;
|
|
||||||
use Log;
|
use Log;
|
||||||
use Symfony\Component\Filesystem\Exception\IOException;
|
use PDO;
|
||||||
|
use Illuminate\Encryption\Encrypter;
|
||||||
use Symfony\Component\HttpFoundation\File\Exception\FileException;
|
use Symfony\Component\HttpFoundation\File\Exception\FileException;
|
||||||
use Symfony\Component\Filesystem\Filesystem;
|
|
||||||
use Symfony\Component\Filesystem\Exception\IOExceptionInterface;
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class EnvironmentService
|
||||||
|
* @package Modules\Installer\Services
|
||||||
|
*/
|
||||||
class EnvironmentService
|
class EnvironmentService
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Create the .env file
|
* Create the .env file
|
||||||
* @return boolean
|
* @return boolean
|
||||||
|
* @throws \Symfony\Component\HttpFoundation\File\Exception\FileException
|
||||||
*/
|
*/
|
||||||
public function createEnvFile($driver, $host, $port, $name, $user, $pass)
|
public function createEnvFile($driver, $host, $port, $name, $user, $pass)
|
||||||
{
|
{
|
||||||
@@ -26,6 +29,7 @@ class EnvironmentService
|
|||||||
'DB_NAME' => $name,
|
'DB_NAME' => $name,
|
||||||
'DB_USER' => $user,
|
'DB_USER' => $user,
|
||||||
'DB_PASS' => $pass,
|
'DB_PASS' => $pass,
|
||||||
|
'DB_EMULATE_PREPARES' => false,
|
||||||
];
|
];
|
||||||
|
|
||||||
$opts = $this->getCacheDriver($opts);
|
$opts = $this->getCacheDriver($opts);
|
||||||
@@ -45,6 +49,28 @@ class EnvironmentService
|
|||||||
return base64_encode(Encrypter::generateKey(config('app.cipher')));
|
return base64_encode(Encrypter::generateKey(config('app.cipher')));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $opts
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
protected function determinePdoOptions($opts)
|
||||||
|
{
|
||||||
|
$dsn = "mysql:host=$opts[DB_HOST];port=$opts[DB_PORT];";
|
||||||
|
Log::info('Connection string: ' . $dsn);
|
||||||
|
|
||||||
|
$conn = new PDO($dsn, $opts['DB_USER'], $opts['DB_PASS']);
|
||||||
|
$version = strtolower($conn->getAttribute(PDO::ATTR_SERVER_VERSION));
|
||||||
|
|
||||||
|
# If it's mariadb, enable the emulation for prepared statements
|
||||||
|
# seems to be throwing a problem on 000webhost
|
||||||
|
# https://github.com/nabeelio/phpvms/issues/132
|
||||||
|
if(strpos($version, 'mariadb') !== false) {
|
||||||
|
$opts['DB_EMULATE_PREPARES'] = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $opts;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determine is APC is installed, if so, then use it as a cache driver
|
* Determine is APC is installed, if so, then use it as a cache driver
|
||||||
* @param $opts
|
* @param $opts
|
||||||
|
|||||||
Reference in New Issue
Block a user