0

According to their PHP Packagist repository page https://packagist.org/packages/maxmind-db/reader the following code is all I need to get the reader to work. PHP doesn't seem to like the use MaxMind\Db\Reader;line. Any clue on how to fix this so it uses the reader.

require_once 'vendor/autoload.php';

use MaxMind\Db\Reader;

$reader = new Reader('GeoIP2-City.mmdb');
print_r($reader->get($_SERVER['REMOTE_ADDR']));
$reader->close()
Don't Panic
  • 41,125
  • 10
  • 61
  • 80
White Lotus
  • 353
  • 2
  • 6
  • 16
  • 2
    Please post the actual error you are receiving. – Greg Oschwald Dec 29 '15 at 21:11
  • Parse error: syntax error, unexpected 'use' (T_USE) – White Lotus Dec 29 '15 at 21:11
  • Are you sure you have a semicolon at the end of the require_once line? I see it in your question here, but I mean in the code you are actually running. – Don't Panic Dec 29 '15 at 21:12
  • require_once("dependencies/vendor/autoload.php"); use "MaxMind\Db\Reader"; $database = 'GeoLite2-City.mmdb'; $reader = new Reader($database); print_r($reader->get($_SERVER['REMOTE_ADDR'])); $reader->close(); – White Lotus Dec 29 '15 at 21:14
  • Is there anything above the `require_once` in your file? – Greg Oschwald Dec 29 '15 at 21:14
  • So, which code are you using? The one in the question, or the one in the comment? – Don't Panic Dec 29 '15 at 21:15
  • Comments but those don't count. – White Lotus Dec 29 '15 at 21:15
  • If you're adding more information such as code or the error message, please put it in the question itself, using the edit link, and not in the comments. After your edits, you should respond in the comment so people will be notified that you have made an update, and come back to re-evaluate your question. Code in comments is difficult to read. – Dan Lowe Dec 31 '15 at 21:22

1 Answers1

0

Okay the solution I figured out is that anything that uses the keyword [use] need to be first in the PHP document; e.g. API.

White Lotus
  • 353
  • 2
  • 6
  • 16