Pregunta

Sí, tengo un problema cuando intento usar valores de enlace en las variables que se veían así antes:

users.firstname LIKE '$firstname%'

Ahora se ve así:

users.firstname LIKE ':firstname%'

Pero no funciona, también probé esto:

users.firstname LIKE :firstname%

Y obtuve algún error de sintaxis.

¿Cuál es la solución correcta para esto?También pensé en agregar % en bindValue(:firstname, $firstname%) pero también necesito usar :firstname en otros lugares que no deberían tener %.

ayuda gracias

¿Fue útil?

Solución

Ok, agregue el % al valor unido:

users.firstname LIKE :firstname

Y entonces

$stmt->bindValue(':firstname', $firstname . '%');

Pero, ya que estás diciendo que necesitas usar :firstname En otros lugares, solo nombra esta instancia algo diferente:

users.firstname LIKE :firstnamewild

Y entonces

$stmt->bindValue(':firstnamewild', $firstname . '%');
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top