$wpdb->get\u col返回重复的数组

vq8itlhq  于 2021-06-17  发布在  Mysql
关注(0)|答案(0)|浏览(238)

我正在尝试获取“wp\u\u sessions”db表中“session\u value”列下所有会话的所有值。
下面的代码完成了这项工作,但由于某种原因,它将结果复制了6次,从而得到了6个具有完全相同内容的数组。

global $wpdb;
$wooSessions = $wpdb->get_col( "SELECT session_value FROM {$wpdb->prefix}woocommerce_sessions" );
$wooCookies = implode(" ", $wooSessions);

我正在阅读文档中关于object_k的内容,理论上它会丢弃重复的键,但我不知道如何应用它。如果我在getcol括号中添加object,代码将停止工作。
这是输出变量转储($woosessions);给了我:

array(1) { [0]=> string(4366) "a:12:{s:4:"cart";s:2084:"a:2:{s:32:"1b4cfd194c804d1ad422a350aa2a0145…"}

array(1) { [0]=> string(4366) "a:12:{s:4:"cart";s:2084:"a:2:{s:32:"1b4cfd194c804d1ad422a350aa2a0145…"}

array(1) { [0]=> string(4366) "a:12:{s:4:"cart";s:2084:"a:2:{s:32:"1b4cfd194c804d1ad422a350aa2a0145…"}

array(1) { [0]=> string(4366) "a:12:{s:4:"cart";s:2084:"a:2:{s:32:"1b4cfd194c804d1ad422a350aa2a0145…"}

array(1) { [0]=> string(4366) "a:12:{s:4:"cart";s:2084:"a:2:{s:32:"1b4cfd194c804d1ad422a350aa2a0145…"}

array(1) { [0]=> string(4366) "a:12:{s:4:"cart";s:2084:"a:2:{s:32:"1b4cfd194c804d1ad422a350aa2a0145…"}

下面是使用session\u id和session\u key的另一个示例:

global $wpdb;
$wooSessions = $wpdb->get_results( "SELECT DISTINCT session_id, session_key FROM {$wpdb->prefix}woocommerce_sessions GROUP BY session_key" );

返回以下内容:

Array ( [0] => stdClass Object ( [session_id] => 2149 [session_key] => 76f0552cff4af84e1963815c1fc4a14d ) ) 
Array ( [0] => stdClass Object ( [session_id] => 2149 [session_key] => 76f0552cff4af84e1963815c1fc4a14d ) ) 
Array ( [0] => stdClass Object ( [session_id] => 2149 [session_key] => 76f0552cff4af84e1963815c1fc4a14d ) ) 
Array ( [0] => stdClass Object ( [session_id] => 2149 [session_key] => 76f0552cff4af84e1963815c1fc4a14d ) ) 
Array ( [0] => stdClass Object ( [session_id] => 2149 [session_key] => 76f0552cff4af84e1963815c1fc4a14d ) ) 
Array ( [0] => stdClass Object ( [session_id] => 2149 [session_key] => 76f0552cff4af84e1963815c1fc4a14d ) )

下面是选择session\u id和group by session\u id的另一个示例:

global $wpdb;
$wooSessions = $wpdb->get_results( "SELECT session_id FROM {$wpdb->prefix}woocommerce_sessions GROUP BY session_id" );

结果如下:

Array ( [0] => stdClass Object ( [session_id] => 2149 ) )
Array ( [0] => stdClass Object ( [session_id] => 2149 ) )
Array ( [0] => stdClass Object ( [session_id] => 2149 ) )
Array ( [0] => stdClass Object ( [session_id] => 2149 ) )
Array ( [0] => stdClass Object ( [session_id] => 2149 ) )
Array ( [0] => stdClass Object ( [session_id] => 2149 ) )

有什么想法能给我指明正确的方向吗?提前谢谢。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题