Alexey Tyapkin Sat Mar 17 12:07:59 -0400 2012

Subject: encode_json

Hello. Function encode_json ignores the strings in Russian language, obtained by the AR model's class. I am using an encoding utf-8 and I have no problems with the use of latin simbols. This is not the only problem.
For example, as can be converted to json this array:
$arr = array('simple'=>'simpleval', 'simple2'=>'simple2val', 'arr2' => array('simple3'=>'simpleval3', arrayOfARModelObjects'=>array(obj1, obj2,obj3, obj4)));
I apologize for my bad English, and I ask you to answer both questions in detail. thanks.
This is the only thing that prevents me from using your AR library.


Max Schwanekamp Mon Mar 19 16:51:37 -0400 2012

I don't have the answer, but I'm thinking the problem is with php's json_encode() rather than PHP-AR. cf this stackoverflow thread. You can look at JsonSerializer::to_s() in Serialization.php which has the call to native php fn json_encode().

Maybe that'll get you on the right track, or maybe someone else has a better answer!

Alexey Tyapkin Wed Mar 21 12:20:52 -0400 2012

I added one line of code in your library. This is rough solve of problem in my situation:
file "php-activerecord/lib/Connection.php", function __construct (look comment):

try {
// unix sockets start with a /
if ($info->host[0] != '/') {
$host = "host=$info->host";
if (isset($info->port))
$host .= ";port=$info->port";
}
else
$host = "unix_socket=$info->host";
$this->connection = new PDO("$info->protocol:$host;dbname=$info->db", $info->user, $info->pass, static::$PDO_OPTIONS);
$this->query("set character_set_results='utf8'"); // this is my change
} catch (PDOException $e) {
throw new DatabaseException($e);
}

result:
before: {"id":3,"title":null,"date":"1"}
after: {"id":3,"title":"\u0420\u043e\u044f\u043b\u044c","date":"1"}

This will help you. Can I count on a speedy removal of the bug and release a new version of the library?
I do not have permission to use crutches in my project.

Alexey Tyapkin Thu Mar 22 13:25:43 -0400 2012

This for select only. For insert and update add string too:
$this->query("set character_set_client='utf8'");

(1-3/3)