Error Can not use object of type PDOStatement as array

1

I'm not able to make header location redirect to a table field.

In this field, you have the link of a PDF document.

See the code:

case 'mostra-id':  

$link = Connection::select("SELECT link FROM 'arquivos' where id =" . App::$key);

$sql = "update 'arquivos' set 'acessos'= acessos + 1 where id=" . App::$key;
$dados = Connection::exec($sql);

header('Location: ' . $link['link']);
break;

The link in the table is written this way: sistema/public/arquivos/pdf/01.pdf

The update is usually correct, but does not open the link when redirecting. Giving the following error:

  

Fatal error: Can not use object of type PDOStatement as array in

    
asked by anonymous 04.02.2016 / 16:46

2 answers

0

$link is not an array to be handled the way you did, it's a PDOStatement then you need to handle it differently.

Try $link->fetchColumn(0) , this is his documentation , this command will fetch the first column of the next line of result set.

    
04.02.2016 / 17:23
1
  

Can not use object of type PDOStatement as array in

The error suggests that the return of select is not an array but probably an object, so change the notation of:

header('Location: ' . $link['link']);

To:

header('Location: ' . $link->link);
    
04.02.2016 / 17:17