Enable ATTR_EMULATE_PREPARES for MariaDB specifically #132
This commit is contained in:
@@ -2,12 +2,11 @@
|
||||
|
||||
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 PDO;
|
||||
|
||||
use App\Models\Airline;
|
||||
use App\Models\User;
|
||||
|
||||
use App\Console\BaseCommand;
|
||||
use App\Models\Acars;
|
||||
@@ -34,6 +33,7 @@ class DevCommands extends BaseCommand
|
||||
'clear-acars' => 'clearAcars',
|
||||
'clear-users' => 'clearUsers',
|
||||
'compile-assets' => 'compileAssets',
|
||||
'db-attrs' => 'dbAttrs',
|
||||
];
|
||||
|
||||
if(!array_key_exists($command, $commands)) {
|
||||
@@ -92,4 +92,20 @@ class DevCommands extends BaseCommand
|
||||
$this->runCommand('npm update');
|
||||
$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,
|
||||
'engine' => null,
|
||||
'options' => [
|
||||
PDO::ATTR_EMULATE_PREPARES => false,
|
||||
PDO::ATTR_EMULATE_PREPARES => env('DB_EMULATE_PREPARES', false),
|
||||
#PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
|
||||
],
|
||||
],
|
||||
|
||||
@@ -25,6 +25,7 @@ DB_PORT={!! $DB_PORT !!}
|
||||
DB_DATABASE={!! $DB_NAME !!}
|
||||
DB_USERNAME={!! $DB_USER !!}
|
||||
DB_PASSWORD={!! $DB_PASS !!}
|
||||
DB_EMULATE_PREPARES={!! $DB_EMULATE_PREPARES !!}
|
||||
DB_PREFIX=
|
||||
|
||||
MAIL_DRIVER=smtp
|
||||
|
||||
@@ -2,18 +2,21 @@
|
||||
|
||||
namespace Modules\Installer\Services;
|
||||
|
||||
use Illuminate\Encryption\Encrypter;
|
||||
use Log;
|
||||
use Symfony\Component\Filesystem\Exception\IOException;
|
||||
use PDO;
|
||||
use Illuminate\Encryption\Encrypter;
|
||||
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
|
||||
{
|
||||
/**
|
||||
* Create the .env file
|
||||
* @return boolean
|
||||
* @throws \Symfony\Component\HttpFoundation\File\Exception\FileException
|
||||
*/
|
||||
public function createEnvFile($driver, $host, $port, $name, $user, $pass)
|
||||
{
|
||||
@@ -26,6 +29,7 @@ class EnvironmentService
|
||||
'DB_NAME' => $name,
|
||||
'DB_USER' => $user,
|
||||
'DB_PASS' => $pass,
|
||||
'DB_EMULATE_PREPARES' => false,
|
||||
];
|
||||
|
||||
$opts = $this->getCacheDriver($opts);
|
||||
@@ -45,6 +49,28 @@ class EnvironmentService
|
||||
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
|
||||
* @param $opts
|
||||
|
||||
Reference in New Issue
Block a user