1

Hi i need to do a simple query but something is wrong. I have $name and $surname and i need to search the (possible multiple) id that rappresent that name and surname and put all the id, name and surname in a array I do this query:

$result=$this->_db_table->select()->where('name=?',$name)
    ->where('surname=?', $surname)->query()
    ->fetchAll();

$array=$result->toArray();
return $array;

If i use

$result=$this->_db_table->fetchAll();
$array=$result->toArray();
return $array

it work correctly and i have an array whith all the value in the database in that table. What is wrong in my first code???

1 Answer 1

1

After doing this

$result=$this->_db_table->select()->where('name=?',$name)
    ->where('surname=?', $surname)->query()
    ->fetchAll();

$result is already an array its not an object . So simply use it instead of calling toArray on it.

Correct code wd be

$result=$this->_db_table->select()->where('name=?',$name)
    ->where('surname=?', $surname)->query()
    ->fetchAll();

return $result;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.