CodeIgniter Forums
SQLSTATE[08006] [7] invalid connection option "charset" - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: Installation & Setup (https://forum.codeigniter.com/forumdisplay.php?fid=9)
+--- Thread: SQLSTATE[08006] [7] invalid connection option "charset" (/showthread.php?tid=66623)



SQLSTATE[08006] [7] invalid connection option "charset" - martin88 - 11-13-2016

Hello 

I'm trying to connect with PDO to my database. 

Here is the error message : 
A Database Error Occurred
SQLSTATE[08006] [7] invalid connection option "charset"
Filename: controllers/HomeController.php
Line Number: 10

The HomeController : 

PHP Code:
<?php
defined
('BASEPATH') OR exit('No direct script access allowed');

class 
HomeController extends CI_Controller {

 
 

    public 
function __construct()
 
   {
 
       parent::__construct(); 

And the data base : 

PHP Code:
$active_group 'default';
$query_builder TRUE;

$db['default'] = array(
    
'dsn'    => 'pgsql:host=localhost; dbname=xxx; charset=utf8;',
    
'hostname' => 'localhost',
    
'username' => 'root',
    
'password' => 'root',
    
'database' => '',
    
'dbdriver' => 'pdo'
    
'dbprefix' => '',
    
'pconnect' => FALSE,
    
'db_debug' => (ENVIRONMENT !== 'production'),
    
'cache_on' => FALSE,
    
'cachedir' => '',
    
'char_set' => 'utf8',
    
'dbcollat' => 'utf8_general_ci',
    
'swap_pre' => '',
    
'encrypt' => FALSE,
    
'compress' => FALSE,
    
'stricton' => FALSE,
    
'failover' => array(),
    
'save_queries' => TRUE
); 

It worked with mysql but I'd like to be able to use PDO. 

Any help ? 

Thank you, 
Martin. 


RE: SQLSTATE[08006] [7] invalid connection option &quot;charset&quot; - InsiteFX - 11-13-2016

Read the first NOTE here in the CodeIgniter Users Guide:

Connecting to your Database


RE: SQLSTATE[08006] [7] invalid connection option &quot;charset&quot; - martin88 - 11-14-2016

EDIT : Found the solution :

$db['default'] = array(
'dsn' => 'mysql:host=localhost; dbname=xxx',
'hostname' => '',
'username' => 'root',
'password' => 'root',
'database' => '',
'dbdriver' => 'pdo',
'dbprefix' => '',
'pconnect' => FALSE,
'db_debug' => (ENVIRONMENT !== 'production'),
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'stricton' => FALSE,
'failover' => array(),
'save_queries' => TRUE
);[/php]