问题
in mac i want to create cronjob but when i run the php file with database i am getting error in terminal.
Warning: mysqli_connect(): (HY000/1049): Unknown database
And In the browser run perfect.
回答1:
Is your PHP environment the same as your browsers PHP? command line php.ini can differ from, for example, your XAMP or other installed webserver
I would recommend checking this first
for me this did the trick
edit your .bash_profile file like
export PATH=/Applications/MAMP/bin/php/php7.1.1/bin:$PATH
edit the path to your PHP bin from your XAMP
回答2:
In my case I got similar error
Warning: mysqli_connect(): (HY000/1049): Unknown database 'login.db' in D:\xampp\htdocs\login\functions\db.php on line 2 so i change [$con=mysqli_connect('localhost', 'root', '', 'login.db');] into [$con=mysqli_connect('localhost', 'root', '', 'login');]
Ii changed 'login.db
' to 'login
' and error disappear
回答3:
If you have this code:
$conn = new mysqli("localhost", "root", "", "myDB");
Try with creating new database called myDB
in localhost/phpmyadmin
.
来源:https://stackoverflow.com/questions/45979819/warning-mysqli-connect-hy000-1049-unknown-database-in-mac-terminal-only