this is the code I’m using:
self::$DB->prepare($query, $types);
when the $query and types are:
//$query
UPDATE Permisos
SET
empleado_id = ?,
agregar_mensaje = ?,
borrar_mensaje = ?,
agregar_noticia = ?,
borrar_noticia = ?,
agregar_documento = ?,
borrar_documento = ?,
agregar_usuario = ?,
borrar_usuario = ?,
agregar_empresa = ?,
borrar_empresa = ?,
agregar_tarea = ?
WHERE
id = ?
//$types
Array(
[0] => integer
[1] => boolean
[2] => boolean
[3] => boolean
[4] => boolean
[5] => boolean
[6] => boolean
[7] => boolean
[8] => boolean
[9] => boolean
[10] => boolean
[11] => boolean
[12] => integer
)
Everything works great, but when they are:
//$query
UPDATE Permisos SET
empleado_id = ?,
agregar_mensaje = ?,
borrar_mensaje = ?,
agregar_noticia = ?,
borrar_noticia = ?,
agregar_documento = ?,
borrar_documento = ?,
agregar_usuario = ?,
borrar_usuario = ?,
agregar_empresa = ?,
borrar_empresa = ?,
agregar_tarea = ?,
borrar_tarea = ?
WHERE
id = ?
//$types
Array(
[0] => integer
[1] => boolean
[2] => boolean
[3] => boolean
[4] => boolean
[5] => boolean
[6] => boolean
[7] => boolean
[8] => boolean
[9] => boolean
[10] => boolean
[11] => boolean
[12] => boolean
[13] => integer
)
It fails with the following message:
<b>Warning</b>: PDO::prepare() [<a href='pdo.prepare'>pdo.prepare</a>]: SQLSTATE[HY000]: General error: PDO::ATTR_STATEMENT_CLASS requires format array(classname, array(ctor_args)); the classname must be a string specifying an existing class in <b>C:\wamp\www\intratin\JP\includes\empleado\mapper\Permiso.php</b> on line <b>137</b><br />
Doesn’t matter which field I add or remove, it fails every time with more than 13 placeholders.
If you
self::$DB->preparemethod is actually callingPDO::prepare, make sure that you don’t pass that$typesargument as a second parameter toPDO::prepareJudging from the documentation, the second parameter that
PDO::prepareexpects is an array of options — not an array describing the type of data for each placeholder.And you try to execute this portion of code :
You’ll get this output :
Which kind of explains the error :
PDO::prepareand array as second parameterPDO::prepareexpects that array to contain a list of options13in your array13isPDO::ATTR_STATEMENT_CLASSPDO::preapreexpects something specific for thePDO::ATTR_STATEMENT_CLASSoptionarray(classname, array(ctor_args));, judging from your error messageintegerinstead of thatNot sure how you can specify the types of each bound parameters with the class you are using — but it seems it’s not as a second parameter to `prepare` 😉
And, if your
self::$DBis indeed an instance of PDO, I don’t find a method that would allow you to specify the types of all parameters at once — it seems you have to specify the type for each parameter, each time you call eitherbindParamorbindValue.