我使用以下查询从MySQL数据库中获取序列化数组:
$sql = "SELECT own_addressbooks
FROM users_modules
WHERE user = ?
AND own_addressbooks <> ?";
//result : a:2:{i:0;s:1:"1";i:1;s:1:"2";}
来自下表:
CREATE TABLE IF NOT EXISTS `users_modules` (
`user` int(11) NOT NULL AUTO_INCREMENT,
`own_groups` text NOT NULL,
`read_groups` text NOT NULL,
`modify_groups` text NOT NULL,
`own_mails` text NOT NULL,
`read_mails` text NOT NULL,
`own_calendars` text NOT NULL,
`modify_calendars` text NOT NULL,
`read_calendars` text NOT NULL,
`own_addressbooks` text,
`modify_addressbook` text NOT NULL,
`read_addressbooks` text NOT NULL,
PRIMARY KEY (`user`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;
反序列化数组我得到:
array(2) { [0]=> string(1) "1" [1]=> string(1) "2" }
数组的每个字段都是下表中的一行:
CREATE TABLE IF NOT EXISTS `addressbooks` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`title` varchar(100) COLLATE utf8_bin NOT NULL,
`entries` text COLLATE utf8_bin NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin AUTO_INCREMENT=2 ;
通过连接查询是否有获取每个地址簿标题的方法?或者顺便说一下,最好的方法是什么?