Re: MySQLi connection character set problem

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Thanks, this is exactly what I needed. It seems I got tricked by what I expected the mysqli_character_set_name function to do.

It seems this function only "returns the DEFAULT character set for the database connection" (quoted from manual) and not the actual character set defined. For example, if you run the code below:

	// bla bla bla
	$mysqli->options(MYSQLI_INIT_COMMAND, "SET NAMES 'UTF8'");
	print mysqli_character_set_name();

it will still output (in my case) "latin1_swedish_ci" although the connection, at this stage, is set to UTF-8.

If the mysqli developers are reading this, it could be useful to have a function to fetch the currently defined connection character set (mysqli_current_character_set_name perhaps ?).

Thanks again.


On 05-01-11, at 03:45, Unreal HSHH wrote:

I have to use this
$mysqli = mysqli_init();
$mysqli->options(MYSQLI_INIT_COMMAND, "SET NAMES 'UTF8'");
$mysqli->real_connect($mysqli_addr, $mysqli_user, $mysqli_pass, $mysqli_db);
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}

-- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux