gpt4 book ai didi

php - 使用 Idiorm/Paris 查询 MySQL 表

转载 作者:可可西里 更新时间:2023-10-31 23:53:25 25 4
gpt4 key购买 nike

我有一个基于 Paris 的模型及其相关的“帖子”表:

class Post extends Model { 
public static $_table = 'posts';
public static $_id_column = 'id';
}

当我进行简单查询以获取所有帖子时:

$posts = Model::factory('Post')->find_many();
var_dump($posts);

这是我得到的回应:

array(13) {
[0]=>
object(Post)#34 (1) {
["orm"]=>
object(ORM)#21 (19) {
["_table_name":protected]=>
string(5) "posts"
["_table_alias":protected]=>
NULL
["_values":protected]=>
array(0) {
}
["_result_columns":protected]=>
array(1) {
[0]=>
string(1) "*"
}
["_using_default_result_columns":protected]=>
bool(true)
["_join_sources":protected]=>
array(0) {
}
["_distinct":protected]=>
bool(false)
["_is_raw_query":protected]=>
bool(false)
["_raw_query":protected]=>
string(0) ""
["_raw_parameters":protected]=>
array(0) {
}
["_where_conditions":protected]=>
array(0) {
}
["_limit":protected]=>
NULL
["_offset":protected]=>
NULL
["_order_by":protected]=>
array(0) {
}
["_group_by":protected]=>
array(0) {
}
["_data":protected]=>
array(4) {
["id"]=>
string(1) "1"
["title"]=>
string(10) "Primo post"
["content"]=>
string(11) "prova prova"
["published"]=>
string(1) "0"
}
["_dirty_fields":protected]=>
array(0) {
}
["_is_new":protected]=>
bool(false)
["_instance_id_column":protected]=>
string(2) "id"
}
}
etc...

现在的问题是:如何访问数据?因为我无法访问它。我做错了什么吗?

最佳答案

更多关于将 Paris 模型编码为 JSON 的信息。这会将数组中的所有 _data 作为 JSON 字符串返回:

echo json_encode(array_map(function ($post) {
return $post->as_array();
}, $posts))

关于php - 使用 Idiorm/Paris 查询 MySQL 表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8758708/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com