aaronpk / iMessage-Export

Archive your iMessage history to HTML, CSV or SQL
205 stars 29 forks source link

Unable to open database file #10

Open edmondchuc opened 5 years ago

edmondchuc commented 5 years ago

When I run php contacts.php I get



Fatal error: Uncaught PDOException: SQLSTATE[HY000] [14] unable to open database file in /Users/edmondchuc/projects/iMessage-Export/include.php:4
Stack trace:
#0 /Users/edmondchuc/projects/iMessage-Export/include.php(4): PDO->__construct('sqlite:/Users/e...')
#1 /Users/edmondchuc/projects/iMessage-Export/contacts.php(3): include('/Users/edmondch...')
#2 {main}
  thrown in /Users/edmondchuc/projects/iMessage-Export/include.php on line 4```

Am I doing something wrong?
stevenleeg commented 5 years ago

Looks like MacOS has some sort of protections on the ~/Library/Messages directory that prevent command line programs from being able to access it– looks like the same sort of thing happens if you try to run ls ~/Library/Messages (even with sudo).

I didn't look too much into why this is the case, but if you're looking for a quick workaround, open up the messages folder with Finder:

$ open ~/Library/Messages

then copy the chat.db file onto your desktop. You can then open include.php and change the first line to this:

$db = new PDO('sqlite:' . $_SERVER['HOME'] . '/Desktop/chat.db');

and that should fix it!

awendland commented 4 years ago

I was able to fix this on macOS Catalina without copying the chat.db file by going into System Preferences > Security > Privacy > Full Disk Access and enabling my terminal which I used to run php contacts.php (which had previously thrown the same error OP mentioned). I was using the default macOS Terminal app.