Welcome Guest, Not a member yet? Register   Sign In
SQLSTATE[08006] [7] invalid connection option "charset"
#1

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. 
Reply
#2

(This post was last modified: 11-13-2016, 03:54 PM by InsiteFX.)

Read the first NOTE here in the CodeIgniter Users Guide:

Connecting to your Database
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#3

(This post was last modified: 11-14-2016, 02:26 PM by martin88.)

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]
Reply




Theme © iAndrew 2016 - Forum software by © MyBB