PHP讀取sphinx例項

2022-03-15 21:34:04 字數 1699 閱讀 4450

閱讀原文:

1.未採用mysql二進位制網路協議的**:

//檢查sphinx是否能連線,不能重試兩次,能則連線,不用mysql協議,僅供參考

function checksphinxnomysql() else

}return $s;

if ($retries >= 2) }

$order_column = 'id desc,time desc';//排序規則

//$s = checksphinx ();

$s = new sphinxclient ();

$s->setserver ( 'sphinx_host', 'sphinx_port');

//以上兩句**亦可使用$s = checksphinx ();來代替

$indexname = "page_keyword";//索引名字

$s->setmatchmode ( sph_match_phrase );

$s->setsortmode ( sph_sort_extended, $order_column );

$s->setmaxquerytime ( 100000 );

$s->setlimits ( 0, $limit_total, $limit_total );

$keyword_sphinx = iconv ( "gbk", "utf-8", $keyword );

$result = $s->query ( $keyword_sphinx, $indexname );

$s->close ();

if ($result ['total'] > 0)

2.採用mysql二進位制網路協議的**:

//檢查sphinx是否能連線,不能重試兩次,能則連線,用mysql14協議

protected function checksphinx() :" );

if (! $conn) else

}if ($retries >= 2)

return $conn;}

$order_column = 'id desc,time desc';//排序規則

$conn = mysql_connect ( "sphinx_host:sphinx_port" );

//以上**亦可使用$conn = checksphinx ();來代替

if (! $conn)

$keyword_sphinx = iconv ( "gbk", "utf-8", $keyword );

//keyword為索引名字

$sql = "select * from keyword where match('') order by limit option max_matches=";

$result = @mysql_query ( $sql, $conn );

$i = 0;

while ( ($row = mysql_fetch_array ( $result )) !== false )

$totals = $this->gettotalfound ($conn);//獲取總記錄個數

如何獲取總記錄個數參考:sphinxql如何得到結果數?show meta的詳細說明?

關於開啟mysql二進位制網路協議參考:sphinx/mysql 協議支援與sphinxql

PHP操作Sphinx例項。

header content type text html charset utf 8 keyword get word 例項化sphinx物件 sphinx new sphinxclient 連線sphinx伺服器 sphinx setserver localhost 9312 拆詞 sph ma...

安裝php擴充套件sphinx

1 安裝 1 先安裝sphinxclient cd usr local src wget tar xzvf sphinx 0.9.9.tar.gz cd sphinx 0.9.9 api libsphinxclient vim sphinxclient.c 找到void sock close int...

php讀取mysql的簡單例項

複製 如下 php link mysql connect localhost root 之前的管理員密碼 if link echo 沒有連線成功 mysql select db infosystem link 選擇資料庫 q select from info sql查詢語句 nbs程式設計客棧p m...