note 81560 added to function.mysql-set-charset

From: Date: Tue, 04 Mar 2008 08:22:25 +0000
Subject: note 81560 added to function.mysql-set-charset
Groups: php.notes 
Request: Send a blank email to php-notes+get-136720@lists.php.net to get a copy of this message
Using the function provided by Janez and nag worked fine for SELECTs, but with INSERT and UPDATE the non-ascii characters got converted into question marks. To fix this, I replaced SET CHARACTER SET with SET NAMES (ref: http://dev.mysql.com/doc/refman/5.0/en/charset-connection.html). So the function becomes: <?php if (function_exists('mysql_set_charset') === false) { /** * Sets the client character set. * * Note: This function requires MySQL 5.0.7 or later. * * @see http://www.php.net/mysql-set-charset * @param string $charset A valid character set name * @param resource $link_identifier The MySQL connection * @return TRUE on success or FALSE on failure */ function mysql_set_charset($charset, $link_identifier = null) { if ($link_identifier == null) { return mysql_query('SET NAMES "'.$charset.'"'); } else { return mysql_query('SET NAMES "'.$charset.'"', $link_identifier); } } } ?> ---- Server IP: 69.147.83.197 Probable Submitter: 80.65.65.67 ---- Manual Page -- http://www.php.net/manual/en/function.mysql-set-charset.php Edit -- https://master.php.net/note/edit/81560 Del: integrated -- https://master.php.net/note/delete/81560/integrated Del: useless -- https://master.php.net/note/delete/81560/useless Del: bad code -- https://master.php.net/note/delete/81560/bad+code Del: spam -- https://master.php.net/note/delete/81560/spam Del: non-english -- https://master.php.net/note/delete/81560/non-english Del: in docs -- https://master.php.net/note/delete/81560/in+docs Del: other reasons-- https://master.php.net/note/delete/81560 Reject -- https://master.php.net/note/reject/81560 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#136720) next »