Pergunta

When I remove the firstcomm Like %?%, it works. When I leave it in, it fails to bring back a result (although no actual errors from the script). And yes, firstcomm is apart of my database. So why is this? Am I doing %?% wrong?

$dbh = new PDO(...);
   $sql = 'SELECT ... FROM ... WHERE firstcomm LIKE %?% AND ...';
$params = array( $qu, ... );

$q = $dbh->prepare( $sql );
$q->execute( $params );
$doc = new DOMDocument();

Update: This also fails...

$dbh = new PDO(...);
   $sql = 'SELECT ... FROM ... WHERE firstcomm LIKE ? AND ...';
$params = array( $qu, ... );

$q = $dbh->prepare( $sql );
$q->execute( $params );
$doc = new DOMDocument();
Foi útil?

Solução

Try this

$sql = "SELECT ... FROM ... WHERE firstcomm LIKE '%?%' AND ...";

Outras dicas

$sql = 'SELECT ... FROM ... WHERE firstcomm LIKE ? AND ...';
$like = '%?%';
$stmt = $connection->prepare($sql);
$stmt->bind_param('s', $like);
$stmt->execute();
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top