gpt4 book ai didi

php - MariaDB 语句与 MySQL 不兼容

转载 作者:行者123 更新时间:2023-11-29 18:40:41 27 4
gpt4 key购买 nike

后端不是我最强大的背景,我在从 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 )。有什么建议吗?

最佳答案

已解决:

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;
}

关于php - MariaDB 语句与 MySQL 不兼容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44963762/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com