PDO DBLIB AND UTF-8 ENCODING

Asked

Viewed 1,439 times

1

I am in a project using UBUNTU-SERVER 64bits as WEBSERVER. In the project I chose the Microsoft Sql Server 2012 database which I have a short-term license to use.

With a lot of effort I got the connection using some libs as freetds Sybase... for PHP-7. However I have character encoding error. I already set the UTF-8 parameter in the connection string and I did not succeed! Someone has already been through the same problem and managed to solve it?

inserir a descrição da imagem aqui

$db['default'] = array(
    'dsn'      => 'dblib:host=192.168.1.1:1433;dbname=TOESTE;charset=UTF-8',
    'hostname' => 'dblib:host=192.168.1.1:1433;dbname=TOESTE;charset=UTF-8',
    'port'     => '1433',
    'username' => 'sa',
    'password' => 'xxxxxx',
    'database' => 'TOESTE',
    '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
);
  • The driver sqlsrv does not work? only the dblib?

  • sqlsrv is not supported by what I’ve searched for. http://stackoverflow.com/questions/10903148/ubuntu-php-and-sqlsrv-connect

  • Changes the string dblib:host .... for sqlsrv:host .... http://php.net/manual/en/ref.pdo-sqlsrv.connection.php and http://php.net/manualen/ref.pdo-dblib.php. In the worst case you can use ODBC.

  • Message: Undefined class Constant 'SQLSRV_ENCODING_UTF8' Filename: /webserver/Development/system/database/drivers/Pdo/subdrivers/pdo_sqlsrv_driver.php<br /> Removing char-set A Database Error Occurred

  • Did you change the dns? how did you do?

  • $db['default'] = array( 'dsn' = > 'sqlsrv:host=192.168.1.1:1433;dbname=TRANSOESTE', 'hostname' => 'sqlsrv:host=192.168.1.1:1433;dbname=TRANSOESTE', 'port' = > '1433', 'username' => 'sa', 'password' => '354263', 'database' => 'TRANSOESTE', 'dbdriver' => 'Pdo', 'dbprefix' => ', 'pconnect' => FALSE, 'db_debug' => (ENVIRONMENT !== 'Production'), 'cache_on' => FALSE, 'cachedir' => ', 'char_set' => ', 'dbcollat' => ', swap_pre' => ', 'Encrypt' => FALSE, 'compress' => FALSE, 'stricton' => FALSE, 'failover' => array(), 'save_queries' => TRUE );

  • The base is utf-8 ? the php file too?

  • 1

    the database is like Latin1_general_ci_as <meta charset="utf-8"> php I’ll confirm but when I use mysql I don’t have this problem.

  • I believe this is the problem, you can do a test, create a new database with Encode utf-8 and create a table and add some records and list in php and see if the problem with encoding continues.

  • Not the problem is really in the connected lib. I’m using the same database on another web server that runs the mssql lib and I don’t have this problem. php is ok too. was viewing on a website and it seems that this lib does not support utf-8 http://www.synet.sk/php/en/230-php-drivers-for-microsoft-sql-server-mssql-sqlsrv-utf8

  • This is ajax Rafael?

  • No. This is the framework connection configuration array.

Show 7 more comments

1 answer

3

I do not know if you have solved this problem, but I will leave here a possible solution:

The default freetds installation uses version 4.2 of TDS which should work for all versions of SQL Server. The problem here is that this version does not support UTF-8 characters or accents of any kind. To fix this you can inform the TDS version on the connection DSN:

dblib:version=7.0;charset=UTF-8;host=domain.example.com;dbname=example;

Or change the file freetds.conf, in configuration [global] in tds version, put the correct version according to the version of SQL you are using. To know the correct version, take a look here:

http://www.freetds.org/userguide/choosingtdsprotocol.htm

Browser other questions tagged

You are not signed in. Login or sign up in order to post.