My fellows at work and I are trying to develop a web application using Laravel with a Vertica database. The only problem is that as soon as you use bindValue or bindParam with this specific database, PHP crashes with a segmentation fault. So I've written a PDO wrapper class that redirects calls to the PHP_ODBC module and that actually works. I was now wondering how to integrate it in Laravel if such a thing is even possible.
Can I integrate a custom PDO wrapper in Laravel
5k views Asked by Osuwariboy AtThere are 3 answers
@Osuwariboy thanks in my case for resolve my error for requirement of platform specific https://neon.tech/ for connect BD postgress to Laravel:
Error:
PDOException::("SQLSTATE[08006] [7] ERROR: Endpoint ID is not specified. Either please upgrade the postgres client library (libpq) for SNI support or pass the endpoint ID (first part of the domain name) as a parameter: '?options=project%3D'
In my case see how you write an conditional for $config['sslmode'] in file vendor\laravel\framework\src\Illuminate\Database\Connectors\PostgresConnector.php and you help me thanks.
then in my case i am needed specific an parameter "options" with character required for an platform of BD https://neon.tech/ for set param 'options='project='
example:
protected function getDsn(array $config)
{
// First we will create the basic DSN setup as well as the port if it is in
// in the configuration options. This will give us the basic DSN we will
// need to establish the PDO connections and return them back for use.
extract($config, EXTR_SKIP);
$host = isset($host) ? "host={$host};" : '';
$dsn = "pgsql:{$host}dbname='{$database}'";
// If a port was specified, we will add it to this Postgres DSN connections
// format. Once we have done that we are ready to return this connection
// string back out for usage, as this has been fully constructed here.
if (isset($config['port'])) {
$dsn .= ";port={$port}";
}
//$config['options_extra'] is an parametter custom in config/database.php with value true only for set this code with a custom flag
if (isset($config['options_extra'])) {
$dsn .= ";options='project=<endpoint-id>'";
}
return $this->addSslOptions($dsn, $config);
}
Conclusion in my case:
the conection succefully, if have this error remember replace for you data
Okay so after a lot of trial and error, my co-workers and I managed to get things up and running. The most time-consuming part turned out to build the wrapper. Assuming you have that, here's what you need to do to integrate it in Laravel (these steps are for Laravel 5.1 by the way). Also, my wrapper's called PDOVertica so whenever you see this term, you have to substitute it for the name of your own wrapper.
1) Copy your wrapper file to the following folder:
2) Next, you need to modify a couple of files:
vendor\laravel\framework\src\Illuminate\Database\Connection.php
vendor\laravel\framework\src\Illuminate\Database\Connectors\Connector.php
vendor\laravel\framework\src\Illuminate\Database\Connectors\PostgresConnector.php
vendor\laravel\framework\src\Illuminate\Database\Connectors\ConnectionFactory.php
3) Once the files have been properly modified, all you have to do is properly configure Laravel to use your custom connection by modifying the following file:
config/database.php
So far as I could tell, this was all the steps needed to get Laravel to connect to a Vertica database without crashing. I hope this helps.