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.
-
Try using `pgsql` for your connection type for Vertica. – woot Jun 18 '15 at 14:57
-
Already tried and the problem stays the same. I also opened a bug on PHP detailing this problem, though I'm not exactly hopeful it'll get fixed any time soon. – Osuwariboy Jun 18 '15 at 15:18
-
Leaving a comment because interested, did you fix it up ? – Alucard Nov 12 '15 at 20:32
-
@Alucard I posted a detailed step-by-step detailing what we did to get things up and running. Check it out and tell me if I missed anything – Osuwariboy Nov 12 '15 at 21:17
3 Answers
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:
vendor/laravel/framework/src/Illuminate/Database/Connectors
2) Next, you need to modify a couple of files:
vendor\laravel\framework\src\Illuminate\Database\Connection.php
namespace Illuminate\Database;
use PDO;
use PDOVertica; //Add this line
use Closure;
use DateTime;
...
//Change the type of the first parameter to PDOVertica as follow
public function __construct(PDOVertica $pdo, $database = '', $tablePrefix = '', array $config = [])
vendor\laravel\framework\src\Illuminate\Database\Connectors\Connector.php
namespace Illuminate\Database\Connectors;
include 'clsPDOVertica.php'; //Add this line
use PDO;
use PDOVertica; //Add this line
...
public function createConnection($dsn, array $config, array $options)
{
$username = array_get($config, 'username');
$password = array_get($config, 'password');
//Modify the return value to return your wrapper
return new PDOVertica($dsn, $username, $password, $options);
}
vendor\laravel\framework\src\Illuminate\Database\Connectors\PostgresConnector.php
protected function getDsn(array $config)
{
extract($config);
$host = isset($host) ? "Server={$host};" : '';
// Modify this line so that it creates the Vertica DSN.
// It should look something like this.
$dsn = "Driver=/opt/vertica/lib64/libverticaodbc.so;{$host}Database={$database}";
if (isset($config['port'])) {
$dsn .= ";port={$port}";
}
if (isset($config['sslmode'])) {
$dsn .= ";sslmode={$sslmode}";
}
return $dsn;
}
vendor\laravel\framework\src\Illuminate\Database\Connectors\ConnectionFactory.php
namespace Illuminate\Database\Connectors;
use PDO;
use PDOVertica; //Add this line
use InvalidArgumentException;
...
// Modify the header of this function so that the $connection parameter
// is of type PDOVertica
protected function createConnection($driver, PDOVertica $connection, $database, $prefix = '', array $config = [])
{
if ($this->container->bound($key = "db.connection.{$driver}")) {
return $this->container->make($key, [$connection, $database, $prefix, $config]);
}
switch ($driver) {
case 'mysql':
return new MySqlConnection($connection, $database, $prefix, $config);
case 'pgsql':
return new PostgresConnection($connection, $database, $prefix, $config);
case 'sqlite':
return new SQLiteConnection($connection, $database, $prefix, $config);
case 'sqlsrv':
return new SqlServerConnection($connection, $database, $prefix, $config);
}
throw new InvalidArgumentException("Unsupported driver [$driver]");
}
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
/* |--------------------------------------------------------------------------
| Default Database Connection Name
|--------------------------------------------------------------------------
|
| Here you may specify which of the database connections below you wish
| to use as your default connection for all database work. Of course
| you may use many connections at once using the Database library.
|
*/
'default' => 'vertica',
...
'connections' => [
'sqlite' => [
'driver' => 'sqlite',
'database' => storage_path('database.sqlite'),
'prefix' => '',
],
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', ''),
'database' => env('DB_DATABASE', ''),
'username' => env('DB_USERNAME', ''),
'password' => env('DB_PASSWORD', ''),
'port' => '5433h',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
],
//This is our custom connection
'vertica' => [
'driver' => 'pgsql',
'host' => env('DB_HOST', '192.168.1.1'),
'database' => env('DB_DATABASE', 'mydb'),
'username' => env('DB_USERNAME', 'myuser'),
'password' => env('DB_PASSWORD', 'mypassword'),
'port' => '5433',
'charset' => 'utf8',
'schema' => 'myschema',
],
'pgsql' => [
'driver' => 'pgsql',
'host' => env('DB_HOST', 'localhost'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'port' => '5433',
'charset' => 'utf8',
'prefix' => '',
'schema' => 'public',
],
'sqlsrv' => [
'driver' => 'sqlsrv',
'host' => env('DB_HOST', 'localhost'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'prefix' => '',
],
],
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.

- 1,335
- 1
- 14
- 29
-
2This does not seem to be a good answer, on the next composer update you will loose all your changes. – Joeri Apr 20 '18 at 11:03
-
1I agree. Which is why we came up with an alternate solution. You might want to check [this post](https://stackoverflow.com/questions/42583366/using-laravel-service-provider-to-override-connector-classes) for the details. – Osuwariboy Apr 20 '18 at 14:08
-
@Osuwariboy could you post your final integration of laravel with vertical db – Hemerson Varela May 21 '18 at 20:21
-
1@HemersonVarela check my comment right above yours, there's a link to another post of mine with a much better implementation using service providers. If you decide to go with Vertica, I highly recommend this other post – Osuwariboy May 22 '18 at 12:55
-
1@Osuwariboy, your (work, experience, facts, general opinion) about Laravel+Vertical db deserve a full post. ;-) – Hemerson Varela May 25 '18 at 16:30
-
@HemersonVarela Your comment made my day :). I'm really glad my experience helped someone in the end :). – Osuwariboy May 25 '18 at 20:07
-
This is a bad answer containing bad advice, and it should be removed. **Never** modify library files; it is both dangerous and unmaintainable. – miken32 Jan 04 '22 at 19:14
You can use a Laravel-ready PDO connector that I wrote:
composer require mixartemev/dbal-vertica-driver

- 42,008
- 16
- 111
- 154

- 28
- 1
- 6
@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

- 1
- 2