我正在尝试对列执行 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;