When trying to access my image file from my database i get this error:

Fatal error: Cannot use object of type stdClass as array in C:\wamp\www\drupal-7.25\sites\all\modules\database\database_ex.module on line 99

note: line 99 is $uri = $value['url'];

function database_ex_form_submission($uri) {
  $result = db_query("SELECT myimage FROM example");
  $records = $result->fetchAll();

  $res = $result->execute();

  foreach ($records as $value) {
    $uri = $value['url'];
    $url = file_create_url($uri);

What seems to be the problem?

  • As Nicolas PERNOT said , you cannot use object as array. Use $value['url'] as $value->url. Otherwise first print the $value in foreach as check whether it is object or an array.
    – Ajay Reddy
    Nov 13, 2015 at 9:54

1 Answer 1


You say :

note: line 99 is $uri = $value['url'];


$value isn't an array and you can't write $value['url'];.

In fact $value is an object and you have to use this syntax $value->url;

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.