我尝试运行以下代码,它应该从数据库中拾取值,但不拾取。
$val = doautocomp('Brisbane');
HTTP::redirect($url_address.'/hotel-search/go/' . $val);
exit;
}
else {
HTTP::redirect($url_address.'/hotel-search/error');
exit;
}
}
function seoUrl($string) {
$string = strtolower($string);
$string = preg_replace("/[^a-z0-9_'s-]/", "", $string);
$string = preg_replace("/['s-]+/", " ", $string);
$string = preg_replace("/['s_]/", "-", $string);
return $string;
}
function doautocomp($mval) {
$linker = mysql_connect('localhost', 'root', 'pass');
$result3 = mysql_query("SELECT name FROM the.autocompletes where name LIKE '".$mval."%' LIMIT 0,1");
while($row = mysql_fetch_array($result3))
{
$val1 = $row['name'];
$mval = seoUrl($val1);
}
return $mval;
mysql_close($linker);
}
我也试过了,但还是没用返回测试
$val = doautocomp('Brisbane');
HTTP::redirect($url_address.'/hotel-search/go/' . $val);
exit;
}
else {
HTTP::redirect($url_address.'/hotel-search/error');
exit;
}
}
function seoUrl($string) {
$string = strtolower($string);
$string = preg_replace("/[^a-z0-9_'s-]/", "", $string);
$string = preg_replace("/['s-]+/", " ", $string);
$string = preg_replace("/['s_]/", "-", $string);
return $string;
}
function doautocomp($mval) {
$linker = mysql_connect('localhost', 'root', 'pass');
$result3 = mysql_query("SELECT name FROM the.autocompletes where name LIKE '".$mval."%' LIMIT 0,1");
while($row = mysql_fetch_array($result3))
{
$val1 = $row['name'];
$mval = seoUrl($val1);
}
return "test"; //$mval;
mysql_close($linker);
}
我在正确理解您的代码方面遇到了一些问题。您正在使用一个具有良好数据库类的框架。为什么要使用"mysql_connect"。您的"mysql_close()"位于"return"语句下面。所以,也许你的最后一次连接没有关闭。在使用mysql之前,您是否尝试过返回"TEST"?
你应该把你的代码写得更像这样:
function doautocomp($mval) {
$row = Database::instance()->query(Database::SELECT,
DB::select('name')
->from('autocompletes')
->where('name','LIKE',$mval.'%')
->limit(1)
)->current();
if ($row === FALSE)
{
return "";
}
$val1 = $row['name'];
$mval = seoUrl($val1);
return $mval;
}