Elxis CMS Forum

Support => Technical support => Topic started by: xmanhattan on April 14, 2013, 11:26:03

Title: question regarding mysql and mysqli
Post by: xmanhattan on April 14, 2013, 11:26:03
Hello all,

I recently put a question at sitepoint regarding the use of:
Code: [Select]
mysql_query("SET
                    character_set_results = 'utf8',
                    character_set_client = 'utf8',
                    character_set_connection = 'utf8',
                    character_set_database = 'utf8',
                    character_set_server = 'utf8'", $link);
                    mysql_set_charset('utf8',$link);

I was informed that as of mysql 5.5 that these are deprecated and that I should switch to mysqli syntax.

Does that mean that utf8 is standardized for queries after 5.5 or are there different parameters for the above?


Title: PDO and mysql
Post by: datahell on April 15, 2013, 20:45:27
You only need to execute this command on connection: SET NAMES utf8 and, for PDO, pass "charset=utf8" on DSN connection string.

Elxis 4.x sets:
PDO::MYSQL_ATTR_INIT_COMMAND = 'SET NAMES utf8'; //this command is executed automatically after the open of the database connection

$dsn = 'mysql:host=xxx;port=yyy;dbname=zzz;charset=utf8';
$pdo = new PDO($dsn, $user, $pass, $options);

//execute a SELECT command:
$stmt = $pdo->prepare('SELECT * FROM mytable);
if ($stmt->execute()) {
     $rows = $stmt->fetchAll(PDO::FETCH_OBJ);
}
         
To disconnect from the database under PDO just set the connection object to null:
$pdo = null; //that's all folks!

My advise is to use PDO!