0

Backend is not my strongest background and I'm having troubles executing my php scripts while migrating from MySQL to MariaDB (a must for our server provider). Here is the function I have in my php script that is working with MySQL 5.6 and it's not working with 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;
}

I have already try most of the options out there but none of them worked (one example: php mysqli prepared statement LIKE). Any suggestion?

mmsarquis
  • 170
  • 3
  • 16

1 Answers1

0

Solved:

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;
}
mmsarquis
  • 170
  • 3
  • 16