Welcome Guest, Not a member yet? Register   Sign In
Set charset in mysqli driver
#1

[eluser]Unknown[/eluser]
I noticed that when using the mysqli driver, the db_set_charset() function located in mysqli_driver.php simply returns true instead of using set names. Should support be added to this, or is it planned?
#2

[eluser]Derek Allard[/eluser]
Yes its planned, but you can help out. If you simply take the implementation in mysql and move it into mysqli... does it impact anything?
#3

[eluser]Derek Jones[/eluser]
Yes, quite frankly I wasn't sure if it should use the MySQL method or if the mysqli_set_charset() would suffice. My concern is that the collation might not be set with the native PHP function, and as collation trumps the client communication character set in MySQL, it is desirable to set it. I did not have time prior to 1.6.0's release to test this on a server with MySQL Improved installed.
#4

[eluser]zwippie[/eluser]
Copying the db_set_charset function from the mysql_driver class did not work here. (Only changing the query call to mysqli_query)

I tried Derek's suggestion, changed the code in db_set_charset() to:

return @mysqli_set_charset($this->conn_id, $this->escape_str($charset));

Seems to work here.
#5

[eluser]Derek Jones[/eluser]
Did you receive a MySQL error when you copied the function and switched to mysqli_query()? Use mysqli_error() if necessary, please. I do not really understand why using MySQLi would prevent that query from working. What version is your MySQL server, too, please?
#6

[eluser]zwippie[/eluser]
I cannot test it at the same machine as before (ubuntu 6.06), but get the same error here at home (windows).

MySql server version: 5.0.41-community-nt
MySQL client version: 5.0.41
Code:
Severity: Warning
Message: mysqli_query() expects parameter 1 to be mysqli, string given
Filename: mysqli/mysqli_driver.php
Line Number: 100

After looking into the rest of msqli_driver.php, the solution is obvious:
mysqli_query expects the conn_id as the first parameter, not the last... Smile

So the correct code should be:
Code:
function db_set_charset($charset, $collation)
{
    return @mysqli_query($this->conn_id, "SET NAMES '".$this->escape_str($charset)."' COLLATE '".$this->escape_str($collation)."'");
}
#7

[eluser]Derek Jones[/eluser]
Yes, I think I prefer that just to be sure that the collation is set as well. Thanks for giving that a go, zwippie!




Theme © iAndrew 2016 - Forum software by © MyBB