I am unable to create a query with custom defined reg-ex using LIKE operator while using bindParam.
Here is my code:
public function findAllByTag($tag)
{
$expressionOne = $tag.",%";
$expressionTwo = "%,".$tag;
$expressionThree = "%,".$tag.",%";
$expressionFour = $tag;
$query = "SELECT * FROM Conditions WHERE ";/*'CONCAT(:tag, ',%')*/
$clause = "(tag LIKE :expressionOne || tag LIKE :expressionTwo || tag LIKE :expressionThree|| tag LIKE :expressionFour)";
$query .= $clause;
$boundParams[0] = $query;
$stmt = $this->getPreparedStatement($query);
$stmt->bindParam(':expressionOne', $expressionOne, \PDO::PARAM_STR);
$stmt->bindParam(':expressionTwo', $expressionTwo, \PDO::PARAM_STR);
$stmt->bindParam(':expressionThree', $expressionThree, \PDO::PARAM_STR);
$stmt->bindParam(':expressionFour', $expressionFour, \PDO::PARAM_STR);
$boundParams[0] = $query;
$stmt->execute($boundParams);
$collection = new Collection();
while ($data = $stmt->fetch(\PDO::FETCH_ASSOC)) {
$collection->add($this->createObject($data));
}
$collection->resetChanges();
return $collection;
}
It throws an error: unexpected ':' expecting ']' in the code below:
class ExceptionResponse extends Response
{
/**
* It prepares response message from message and code of exception, statusCode is initialized to exception code and
* message is an array of code and message of format {_errors: [ {'code' : int, 'message': string }, .. ]}
*
* @param Exception $e exception from which return response will be created
*/
public function __construct(\Exception $e)
{
if (!($e instanceof GenericException)) {
$e = new GenericException($e->getMessage());
}
$data = [
'error' => true,
'failure' => [
[
'code' => $e->getCode(),
'message' => $e->getMessage(),
],
],
'success': null
];
$this->setHeader('Content-Type', 'application/json');
$this->setMessage(json_encode($data));
$this->setStatusCode($e->getCode());
}
}
Line #39: 'success': null
How can I remove this error and make my query work? Note: I am using a framework of my firm, griffin and writing code over it. All is working fine but bindParam.