Error: deleting an array of id's

4 views
Skip to first unread message

Cristian

unread,
Oct 17, 2009, 12:10:30 PM10/17/09
to Outlet ORM
Hello!
I have a typical list of records with checkboxes to select and delete.
These checkboxes will generate an array of id's and I want to do
something like this:

if(!empty($_POST['id'])){
$id = $_POST['id'];
$outlet->delete("Pais", $id);
}

Well, if I select only one checkbox, the structure of the array is
like this:
Array
(
[0] => 12
)
In this case, the record with id = 12 is successfully deleted.

But if I select more than one checkbox:
Array
(
[0] => 12
[1] => 13
)
In this case I get this errors:
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE
[HY093]: Invalid parameter number: number of bound variables does not
match number of tokens' in C:\xampp\htdocs\estrenos\cls\outlet\classes
\outlet\Outlet.php:75
Stack trace:
#0 C:\xampp\htdocs\estrenos\cls\outlet\classes\outlet\Outlet.php(75):
PDOStatement->execute(Array)
#1 C:\xampp\htdocs\estrenos\panel\pais_borrar.php(11): Outlet->delete
('Pais', Array)
#2 {main}
thrown in C:\xampp\htdocs\estrenos\cls\outlet\classes\outlet
\Outlet.php on line 75


Any ideas?

Jonathan Ariel

unread,
Oct 17, 2009, 12:23:00 PM10/17/09
to outle...@googlegroups.com
This is not really a problem with Outlet but the way you use it.
In the case of an array of parameters what you should do is iterate over it and send single ids to the delete method.

So for example you can do something like this:
if(!empty($_POST['id'])){
  if(is_array($_POST['id'])) {
    foreach($_POST['id'] as $id) {
      $outlet->delete("Pais", $id);  
    }
  } else {

Cristian

unread,
Oct 17, 2009, 1:16:20 PM10/17/09
to Outlet ORM
You're right, I think what confused me is the first line in the delete
() method:
public function delete ($clazz, $id) {
if (!is_array($id)) $id = array($id);
...
}
I understood that this function always expects an array as second
argument.
Oooops, sorry, my mistake.

On 17 oct, 13:23, Jonathan Ariel <ionat...@gmail.com> wrote:
> This is not really a problem with Outlet but the way you use it.In the case

Jonathan Leibiusky

unread,
Oct 17, 2009, 1:27:04 PM10/17/09
to outle...@googlegroups.com
Don't worry. It always happens to me :)
In the 2.0 version (not sure about 1.0) you'll have to give the delete
the instance so there won't be confusions anymore.
What we probably want to add is some kind of bulk update and deletes.
Reply all
Reply to author
Forward
0 new messages