Json + 玛丽亚数据库?
Json + mariaDB?
我正在使用 jstree 和 mysql 以及 json,它工作正常。
-但是当将数据库更改为 mariaDB 时它不会工作。
我正在使用 mysqli。和相同的 php-version.
示例代码:
$sth = mysqli_query("SELECT ...");
$rows = array();
while($r = mysqli_fetch_assoc($sth)) {
$rows[] = $r;
}
print json_encode($rows);
有什么想法吗?
我这样做是为了在 jstree 中使用,例如:
$('#using_json_2').jstree({ 'core' : {
'data' : [
{ "id" : "ajson1", "parent" : "#", "text" : "Simple root node" },
{ "id" : "ajson2", "parent" : "#", "text" : "Root node 2" },
{ "id" : "ajson3", "parent" : "ajson2", "text" : "Child 1" },
{ "id" : "ajson4", "parent" : "ajson2", "text" : "Child 2" },
]
} });
我也认为 "won't work" 的描述太宽泛,但是如果提问者的话 "and json" 意味着 SELECT 正在选择数据类型定义的列 = json: 这是MySQL 5.7的新特性,MariaDB暂时没有模仿。
错误与不同的编码有关,已通过添加解决:
while($row =mysqli_fetch_assoc($result))
{
$rows[] = array_map('utf8_encode', $row);
}
print json_encode($rows);
我正在使用 jstree 和 mysql 以及 json,它工作正常。
-但是当将数据库更改为 mariaDB 时它不会工作。
我正在使用 mysqli。和相同的 php-version.
示例代码:
$sth = mysqli_query("SELECT ...");
$rows = array();
while($r = mysqli_fetch_assoc($sth)) {
$rows[] = $r;
}
print json_encode($rows);
有什么想法吗?
我这样做是为了在 jstree 中使用,例如:
$('#using_json_2').jstree({ 'core' : {
'data' : [
{ "id" : "ajson1", "parent" : "#", "text" : "Simple root node" },
{ "id" : "ajson2", "parent" : "#", "text" : "Root node 2" },
{ "id" : "ajson3", "parent" : "ajson2", "text" : "Child 1" },
{ "id" : "ajson4", "parent" : "ajson2", "text" : "Child 2" },
]
} });
我也认为 "won't work" 的描述太宽泛,但是如果提问者的话 "and json" 意味着 SELECT 正在选择数据类型定义的列 = json: 这是MySQL 5.7的新特性,MariaDB暂时没有模仿。
错误与不同的编码有关,已通过添加解决:
while($row =mysqli_fetch_assoc($result))
{
$rows[] = array_map('utf8_encode', $row);
}
print json_encode($rows);