Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to open database file #10

Open
edmondchuc opened this issue Jun 12, 2019 · 2 comments
Open

Unable to open database file #10

edmondchuc opened this issue Jun 12, 2019 · 2 comments

Comments

@edmondchuc
Copy link

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
Copy link

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
Copy link

awendland commented Jul 17, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants