后端不是我最强的背景,我在从MySQL迁移到MariaDB时遇到了执行php脚本的问题(对于我们的服务器提供商来说这是必须的)。以下是我的php脚本中的函数,它在MySQL 5.6中工作,但在MariaDB (10.1.22- MariaDB -cll-lve -MariaDB服务器)中不工作:
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)。有什么建议吗?
发布于 2017-07-08 00:12:40
已解决:
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;
}https://stackoverflow.com/questions/44963762
复制相似问题