我正在尝试对列执行FULLTEXT搜索,如果第一个返回零行,则进一步在布尔模式下搜索FULLTEXT。如果我在命令行手动输入SQL查询到MySQL,我得到了我期望的结果,但这段代码返回一个空数组到我的JS。 我要去的任何想法?
$con = mysqli_connect( $db_url, $db_user, $db_pwd, $db );
if( !$con ) {
error_log("Connection failed!");
die();
}
$sql = "SELECT problem, note_text, doctor, entry_date FROM notes WHERE mrn=? AND MATCH(note_text) AGAINST(?)";
$stmt = mysqli_prepare( $con, $sql );
mysqli_stmt_bind_param( $stmt, 'is', $_POST['mrn'], $_POST['search_text'] );
$success = mysqli_stmt_execute( $stmt );
if( mysqli_stmt_num_rows($stmt) == 0 ) { // Then try fulltext search in boolean mode
$sql = "SELECT problem, note_text, doctor, entry_date FROM notes WHERE mrn=? AND MATCH(note_text) AGAINST(? IN BOOLEAN MODE)";
$stmt = mysqli_prepare( $con, $sql );
mysqli_stmt_bind_param( $stmt, 'is', $_POST['mrn'], $_POST['search_text'] );
$success = mysqli_stmt_execute( $stmt );
}
mysqli_bind_result( $stmt, $problem, $note_text, $doctor, $date );
$notes = array();
for( $i = 0; mysqli_stmt_fetch($stmt) == TRUE; ++$i ) {
$notes[$i] = array( 'problem' => $problem, 'note' => $note_text, 'doctor' => $doctor, 'date' => $date );
}
$json = json_encode($notes);
echo $json;
答案 0 :(得分:0)
好的,我想我找到了答案。在使用第二个调用
之前,我需要关闭第一个STATEMENT $ stmtmysqli_stmt_close($stmt)
之后
if( mysqli_stmt_num_rows($stmt) == 0 )
简单地做
$stmt = mysqli_prepare( $con, $sql );
没有给你一个新的陈述并覆盖上一个变量!