$add = $expression ? '... [OK]' : '... [FAILDED]'; echo $comment . $add . "\t\r\n"; } define('DEBUG', 2); define('TEST_PATH', str_replace('\\', '/', getcwd()) . '/'); define('FRAMEWORK_PATH', TEST_PATH . '../'); $conf = (include TEST_PATH . 'conf.php'); include FRAMEWORK_PATH . 'core.php'; core::init($conf); echo "Test db_mysql.class.php \r\n\r\n"; $db = new db_pdo_mysql($conf['db']['mysql']); $db->query("DROP TABLE IF EXISTS `bbs_user`"); $db->query("CREATE TABLE `bbs_user` (\n `uid` int(11) unsigned NOT NULL auto_increment,\t\t# 用户id\n `regip` int(11) NOT NULL default '0',\t\t\t\t# 注册ip\n `regdate` int(11) unsigned NOT NULL default '0',\t\t# 注册日期\n `username` char(16) NOT NULL default '',\t\t\t# 用户名\n `password` char(32) NOT NULL default '',\t\t\t# 密码 md5()\n `salt` char(8) NOT NULL default '',\t\t\t\t# 随机干扰字符,用来混淆密码\n `email` char(40) NOT NULL default '',\t\t\t\t# EMAIL\n `groupid` tinyint(3) unsigned NOT NULL default '0',\t\t# 用户组 id\n `threads` mediumint(8) unsigned NOT NULL default '0',\t\t# 主题数\n `posts` mediumint(8) unsigned NOT NULL default '0',\t\t# 回帖数\n `avatar` int(11) unsigned NOT NULL default '0',\t\t# 头像最后更新的时间,0为默认头像\n KEY username(`username`),\n PRIMARY KEY (`uid`)\n) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;"); $db->truncate('user'); $db->maxid('user-uid', 0); $db->count('user', 0); $db->count('user-abc-123', 100); // 增加一条记录: $uid = $db->maxid('user-uid', '+1'); bbs_assert("maxid('user-uid', '+1')", $uid == 1); $r = $db->set("user-uid-{$uid}", array('username' => 'admin1', 'email' => '*****@*****.**')); bbs_assert("set()", $r == TRUE); // 增加一条记录: $uid = $db->maxid('user-uid', '+1'); bbs_assert("maxid('user-uid', '+1')", $uid == 2); $r = $db->set("user-uid-{$uid}", array('username' => 'admin2', 'email' => '*****@*****.**')); // 增加一条记录: $uid = $db->maxid('user-uid', '+1'); bbs_assert("maxid('user-uid', '+1')", $uid == 3); $r = $db->set("user-uid-{$uid}", array('username' => 'admin3', 'email' => '*****@*****.**')); $n = $db->count('user', '+3');
$add = $expression ? '... [OK]' : '... [FAILDED]'; echo $comment . $add . "\t\r\n"; } echo "Test db_pdo.class.php \r\n\r\n"; define('DEBUG', 2); define('TEST_PATH', str_replace('\\', '/', getcwd()) . '/'); define('FRAMEWORK_PATH', TEST_PATH . '../'); $conf = (include TEST_PATH . 'conf.php'); include FRAMEWORK_PATH . 'core.php'; core::init($conf); $db = new db_pdo_mysql($conf['db']['pdo_mysql']); $db->query("DROP TABLE IF EXISTS `bbs_user`"); $db->query("CREATE TABLE `bbs_user` (\n `uid` int(11) unsigned NOT NULL auto_increment,\t\t# 用户id\n `regip` int(11) NOT NULL default '0',\t\t\t\t# 注册ip\n `regdate` int(11) unsigned NOT NULL default '0',\t\t# 注册日期\n `username` char(16) NOT NULL default '',\t\t\t# 用户名\n `password` char(32) NOT NULL default '',\t\t\t# 密码 md5()\n `salt` char(8) NOT NULL default '',\t\t\t\t# 随机干扰字符,用来混淆密码\n `email` char(40) NOT NULL default '',\t\t\t\t# EMAIL\n `groupid` tinyint(3) unsigned NOT NULL default '0',\t\t# 用户组 id\n `threads` mediumint(8) unsigned NOT NULL default '0',\t\t# 主题数\n `posts` mediumint(8) unsigned NOT NULL default '0',\t\t# 回帖数\n `avatar` int(11) unsigned NOT NULL default '0',\t\t# 头像最后更新的时间,0为默认头像\n KEY username(`username`),\n PRIMARY KEY (`uid`)\n) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;"); $db->truncate('user'); $db->maxid('user-uid', 0); $db->count('user', 0); // 增加一条记录: $uid = $db->maxid('user-uid', '+1'); bbs_assert("maxid('user', '+1')", $uid == 1); $r = $db->set("user-uid-{$uid}", array('username' => 'admin1', 'email' => '*****@*****.**')); bbs_assert("set()", $r == TRUE); // 增加一条记录: $uid = $db->maxid('user-uid', '+1'); bbs_assert("maxid('user', '+1')", $uid == 2); $r = $db->set("user-uid-{$uid}", array('username' => 'admin2', 'email' => '*****@*****.**')); // 增加一条记录: $uid = $db->maxid('user-uid', '+1'); bbs_assert("maxid('user', '+1')", $uid == 3); $r = $db->set("user-uid-{$uid}", array('username' => 'admin3', 'email' => '*****@*****.**')); $n = $db->count('user', '+3'); bbs_assert("count('user', '+3')", $n == 3);