我正在编写 PDO 准备,但我想知道是否有另一种编写它的好方法,以便它运行得更快。这是代码:
function comp_post_code($cat, $comp_post_code){
global $DBH;
$STH = $DBH->prepare("SELECT * from uk_data where
cat10 like :comp_post_code AND (
cat1 like :cat OR
cat2 like :cat OR
cat3 like :cat OR
cat4 like :cat OR
cat5 like :cat OR
cat6 like :cat OR
cat7 like :cat
)") ;
$STH->bindValue(':cat', "%$cat%", PDO::PARAM_STR);
$STH->bindValue(':comp_post_code', "$comp_post_code%", PDO::PARAM_STR);
$STH->execute();
$STH->setFetchMode(PDO::FETCH_ASSOC);
return $STH;
$DBH = Null;
}
我想要表中的完整数据,所以我正在使用 Select。* ....谢谢
编辑:- cat10 是邮政编码,cat 1 到 cat7 是类别。我需要搜索给定邮政编码中的类别。
这是表格格式:
CREATE TABLE IF NOT EXISTS `uk_data` (
`slno` int(10) NOT NULL AUTO_INCREMENT,
`comp_name` varchar(150) DEFAULT NULL,
`comp_no` varchar(50) DEFAULT NULL,
`comp_street` varchar(100) DEFAULT NULL,
`comp_area` varchar(100) DEFAULT NULL,
`comp_post_code` varchar(15) DEFAULT NULL,
`comp_phone` varchar(100) DEFAULT NULL,
`comp_phone1` varchar(100) DEFAULT NULL,
`cat1` varchar(100) DEFAULT NULL,
`cat2` varchar(100) DEFAULT NULL,
`cat3` varchar(100) DEFAULT NULL,
`cat4` varchar(100) DEFAULT NULL,
`cat5` varchar(100) DEFAULT NULL,
`cat6` varchar(100) DEFAULT NULL,
`cat7` varchar(100) DEFAULT NULL,
`cat8` decimal(9,6) DEFAULT NULL,
`cat9` decimal(9,6) DEFAULT NULL,
`cat10` varchar(15) DEFAULT NULL,
PRIMARY KEY (`slno`),
UNIQUE KEY `Phone` (`comp_phone`),
KEY `cat10` (`cat10`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=74504 ;
我正在使用的输出:
$uk_data_radious = comp_post_code($q,$pc_o);
while (($row = $uk_data_radious->fetch()) !== false) {
$comp_name[] = $row['comp_name'];
$comp_phone[] = $row['comp_phone'];
$comp_phone1[] = $row['comp_phone1'];
$post_code[] = $row['cat10'];
$post_code1[] = $row['comp_post_code'];
$comp_no[] = $row['comp_no'];
$comp_street[] = $row['comp_street'];
$comp_area[] = $row['comp_area'];
$cat1[] = $row['cat1'];
$cat2[] = $row['cat2'];
$cat3[] = $row['cat3'];
$cat4[] = $row['cat4'];
$cat5[] = $row['cat5'];
$cat6[] = $row['cat6'];
$cat7[] = $row['cat7'];
$distance_m[] = distance($Latitude[0],$Longitude[0],$row['cat8'],$row['cat9'],"M");
}