sphinx自动完成调用片段摘录不返回结果集
我可以从print_r($stmt->fetchAll())获取结果集;但是,我无法从print_r($r)获得结果集;下面是来自的确切代码。唯一的更改是sphinx.conf文件中的sql_查询 ajax_suggest_extracts.phpsphinx自动完成调用片段摘录不返回结果集,sphinx,Sphinx,我可以从print_r($stmt->fetchAll())获取结果集;但是,我无法从print_r($r)获得结果集;下面是来自的确切代码。唯一的更改是sphinx.conf文件中的sql_查询 ajax_suggest_extracts.php require_once 'common.php'; require_once 'functions.php'; $indexes = 'simplecomplete'; $arr =array(); $q = trim($_GET['term'])
require_once 'common.php';
require_once 'functions.php';
$indexes = 'simplecomplete';
$arr =array();
$q = trim($_GET['term']);
$stmt = $ln_sph->prepare("SELECT * FROM $indexes WHERE MATCH(:match) LIMIT 0,10 OPTION ranker=sph04");
$aq = explode(' ',$q);
if(strlen($aq[count($aq)-1])<3){
$query = $q;
}else{
$query = $q.'*';
}
$stmt->bindValue(':match', $query,PDO::PARAM_STR);
$stmt->execute();
$docs = array();
$title = "";
$stmsnp = $ln_sph->prepare("CALL SNIPPETS(:doc,'simplecomplete',:query)");
$stmsnp->bindValue(':query',$query,PDO::PARAM_STR);
$stmsnp->bindParam(':doc',$title,PDO::PARAM_STR);
print_r($stmt->fetchAll()); //THIS RETURNS RESULT SET
foreach($stmt->fetchAll() as $r){
$title = $r['city'];
$stmsnp->execute();
$r = $stmsnp->fetch();
print_r($r); //THIS DOES NOT.
$arr[] = array('id' => utf8_encode($r['city']),'label' =>utf8_encode( $r['city']));
}
echo json_encode($arr);
exit();
从fetchAll的文档中 返回包含结果集中所有剩余行的数组 因此print_r()中的fetchAll从数据库中获取所有行。foreach()中的fetchAll就没有要提取的行了 看起来像是对PHP/pdo的误解
source simplecomplete
{
type = mysql
sql_host = localhost
sql_user = swflorib
sql_pass = cii65419
sql_db = swflorib_db
sql_port = 3306 # optional, default is 3306
sql_query = SELECT id, Sic_Code_description, Sic_Code6_Description, City, hidden_keywords FROM no_admin_emails GROUP BY Company_Name
sql_field_string = Sic_Code_description
sql_field_string = Sic_Code6_Description
sql_field_string = City
sql_field_string = hidden_keywords
}
index simplecomplete
{
source = simplecomplete
path = /usr/local/sphinx/var/data/simplecomplete
docinfo = extern
charset_type = utf-8
min_word_len = 3
enable_star = 1
min_prefix_len = 3
}