Warning: mysqli_connect(): (HY000/1049): Unknown database in mac terminal only

旧城冷巷雨未停 提交于 2020-01-11 12:00:09

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!