note 68690 added to function.mysql-pconnect

From: Date: Mon, 07 Aug 2006 13:03:52 +0000
Subject: note 68690 added to function.mysql-pconnect
Groups: php.notes 
Request: Send a blank email to php-notes+get-115610@lists.php.net to get a copy of this message
Be careful when setting variables on a persistent mysql connection. Example: // Set result charset to UTF8 mysql_query("SET SESSION character_set_results = 'UTF8'"); If another script reuses your persistent connection, it will also use the UTF-8 charset. This created a problem with typo3 and TemplaVoila, which reads serialized data from the database. The data is returned as UTF8, but the script expects latin1 and dies with a serialize error ("Template Object could not be unserialized successfully."). This problem is especially tricky because it works on some requests and crashes on others - because the variable is not set on all connections in the persistent connection pool. A possible solution is to reset variables to their default value afterwards: $ret = mysql_query("SHOW VARIABLES LIKE 'character_set_results'"); list($foo, $old_charset) = mysql_fetch_assoc($ret); mysql_query("SET SESSION character_set_results = 'UTF8'"); // do some fancy utf8 stuff // .. // revert to old encoding mysql_query("SET SESSION character_set_results = '$old_charset'"); or simply use mysql_connect(), as previously stated it makes more sense in most enviroments and there are less things to bother with (like variables, transactions, temporary tables). ---- Server IP: 212.124.37.9 Probable Submitter: 213.39.144.78 ---- X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/function.mysql-pconnect.php Edit -- https://master.php.net/note/edit/68690 Del: integrated -- https://master.php.net/note/delete/68690/integrated Del: useless -- https://master.php.net/note/delete/68690/useless Del: bad code -- https://master.php.net/note/delete/68690/bad+code Del: spam -- https://master.php.net/note/delete/68690/spam Del: non-english -- https://master.php.net/note/delete/68690/non-english Del: in docs -- https://master.php.net/note/delete/68690/in+docs Del: other reasons-- https://master.php.net/note/delete/68690 Reject -- https://master.php.net/note/reject/68690 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#115610) next »