note 49852 added to function.mysql-connect
| From: | k dot gornik at xds dot pl | Date: | Thu, 10 Feb 2005 14:06:56 +0000 |
| Subject: | note 49852 added to function.mysql-connect | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-84791@lists.php.net to get a copy of this message | ||
To avoid something like this:
Database error: Invalid SQL: SELECT * FROM alias WHERE path='1108043672' AND
fk_client_id=2
MySQL Error: 1267 (Illegal mix of collations (latin2_general_ci,IMPLICIT) and
(latin1_swedish_ci,COERCIBLE) for operation '=')
Session halted.
PHP >=4.3.10
MySQL >=4.1.0
simply write:
<?php
class MySQL {
//[...]
function connect($host, $user, $pass) {
$this->Link_DB = @mysql_connect($host, $user, $pass);
if($this->Link_DB) {
if(version_compare(phpversion(), "4.3.10", ">=")>0) {
$result = @mysql_query("SHOW VARIABLES LIKE 'version'", $this->Link_ID);
$row = mysql_fetch_row($result);
$mysql_ver = $row[1];
if(version_compare($mysql_ver, '4.2.0', '>=')>0) {
$i = 1;
while(defined('DB_INIT_CODE_'.$i)) {
$sQuery = constant('DB_INIT_CODE_'.$i);
mysql_query($sQuery, $this->Link_ID);
$i++;
}
}
}
}
else {
return false;
}
return true;
}
}
?>
and
<?php
define('DB_INIT_CODE_1', "SET NAMES latin2");
define('DB_INIT_CODE_2', "SET CHARACTER SET latin2");
define('DB_INIT_CODE_3', "SET
COLLATION_CONNECTION='latin2_general_ci'");
// and so on...
?>
elsewhere (like I put it down in MySQL.config.inc.php)
The only important thing is You MUST include definitions before including object MySQL :)
Spent lot of time looking for prettier solution but there seems not to be any...
----
Manual Page -- http://www.php.net/manual/en/function.mysql-connect.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+49852
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+49852&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+49852&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+49852&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+49852&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+49852&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+49852&report=yes
Search -- http://master.php.net/manage/user-notes.php