note 86455 added to function.mysql-set-charset

From: Date: Mon, 20 Oct 2008 09:56:19 +0000
Subject: note 86455 added to function.mysql-set-charset
Groups: php.notes 
Request: Send a blank email to php-notes+get-145502@lists.php.net to get a copy of this message
I needed to access the database from within one particular webhosting service. Pages are UTF-8 encoded and data received by forms should be inserted into database without changing the encoding. The database is also in UTF-8. Neither SET character set 'utf8' or SET names 'utf8' worked properly here, so this workaround made sure all variables are set to utf-8. <?php // ... (creating a connection to mysql) ... mysql_query("SET character_set_results = 'utf8', character_set_client = 'utf8', character_set_connection = 'utf8', character_set_database = 'utf8', character_set_server = 'utf8'", $conn); $re = mysql_query('SHOW VARIABLES LIKE "%character_set%";')or die(mysql_error()); while ($r = mysql_fetch_assoc($re)) {var_dump ($r); echo "<br />";} exit; ?> All important variables are now utf-8 and we can safely use INSERTs or SELECTs with mysql_escape_string($var) without any encoding functions. ---- Server IP: 147.32.160.17 Probable Submitter: 85.135.75.196 ---- Manual Page -- http://www.php.net/manual/en/function.mysql-set-charset.php Edit -- https://master.php.net/note/edit/86455 Del: integrated -- https://master.php.net/note/delete/86455/integrated Del: useless -- https://master.php.net/note/delete/86455/useless Del: bad code -- https://master.php.net/note/delete/86455/bad+code Del: spam -- https://master.php.net/note/delete/86455/spam Del: non-english -- https://master.php.net/note/delete/86455/non-english Del: in docs -- https://master.php.net/note/delete/86455/in+docs Del: other reasons-- https://master.php.net/note/delete/86455 Reject -- https://master.php.net/note/reject/86455 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#145502) next »