1

Here's my code:

$terminosBuscados = 'Vender la porteria'

$x = $conectarDB->prepare(" 
    SELECT DISTINCT 
    titulo,
    FROM_UNIXTIME(fecha, '%d-%m-%Y') AS fecha,
    cuerpo,
    tipoContenido,
    autor
    FROM searchIndex 
    WHERE match(titulo) 
    AGAINST (' ? ' IN BOOLEAN MODE)
    ORDER BY contenidoID DESC
    ");
$x->bindParam(1, $terminosBuscados);
$x->execute();
$y = $x->fetchAll(PDO::FETCH_ASSOC);

This is showing no results at all ($y returns null), when trying the query itself in phpMyAdmin does work and show results.

I've just added a FULLTEXT index into the table and adapted my working code to use that index.

Dharman
  • 30,962
  • 25
  • 85
  • 135
Rosamunda
  • 14,620
  • 10
  • 40
  • 70

1 Answers1

1

For mysql ' ? ' is a string, and will not be used as palce holfer.

If you need the spaces use CONCAT(' ',?,' ')

$x = $conectarDB->prepare(" 
    SELECT DISTINCT 
    titulo,
    FROM_UNIXTIME(fecha, '%d-%m-%Y') AS fecha,
    cuerpo,
    tipoContenido,
    autor
    FROM searchIndex 
    WHERE match(titulo) 
    AGAINST (CONCAT(' ',?,' ') IN BOOLEAN MODE)
    ORDER BY contenidoID DESC
    ");
$x->bindParam(1, $terminosBuscados);
$x->execute();
$y = $x->fetchAll(PDO::FETCH_ASSOC);
nbk
  • 45,398
  • 8
  • 30
  • 47