Ad

Why This Code $results = \Db::select('select * From Engegraph_forms_membros Where Id = ?', [1]); Dont Work?

- 1 answer

I have this code on my component.

$results = \Db::select('select * from engegraph_forms_membros where id = ?', [1]);
echo $results; 

but i have this error "Array to string conversion"

Someone can help a newbie ??

Ad

Answer

The problem is you are printing array as as string.

returning result of \Db::select is an array so to print array you can use print_r()

$results = \Db::select('select * from engegraph_forms_membros where id = ?', [1]);
echo '<pre/>'; print_r($result); exit();

you can print result like this or you can use build in debugger function.

$results = \Db::select('select * from engegraph_forms_membros where id = ?', [1]);
dd($result);
// or dump($result);

if you use dump/dd function you dont need to worry it can print anything. dd [die and dump] stops php flow to next statements. dump will continues flow so you can print another values/or/execute next statements if you need.

if any doubts please add comments.

Ad
source: stackoverflow.com
Ad