Backend不是我最强大的背景,我在从MySQL迁移到MariaDB(我们的服务器提供商必须)时执行我的php脚本时遇到了麻烦。 这是我在php脚本中使用的函数,它与MySQL 5.6一起使用,而且它不能与MariaDB一起使用(10.1.22-MariaDB-cll-lve-MariaDB Server):
public function getPostByName($postName) {
$returnValue = array();
$sql = "SELECT * FROM posts WHERE post_description LIKE ?";
$statement = $this->conn->prepare($sql);
if (!$statement)
throw new Exception($statement->error);
$postName = "%".$postName."%";
$statement->bind_param("s", $postName);
$statement->execute();
$result = $statement->get_result();
while($row = $result->fetch_array(MYSQLI_ASSOC)) {
array_push($returnValue, $row);
}
return $returnValue;
}
我已经尝试了大部分选项,但没有一个可行(例如:php mysqli prepared statement LIKE)。有什么建议吗?
答案 0 :(得分:0)
解决:
public function getPostByName($postName){
$returnValue = array();
$sql = "SELECT * FROM posts WHERE post_description LIKE '%".$postName."%'";
$result = $this->conn->query($sql);
if($result != nill && (mysqli_num_rows($result) >= 1)){
while($row = $result->fetch_array(MYSQLI_ASSOC)){
array_push($returnValue, $row);
}
}
return $returnValue;
}