Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 837
Maulik Patel Avatar asked Dec 06 '22 13:12

Maulik Patel


2 Answers

check your port that mysql run . in many cases mysql run in port 3306 but in my mysql it run in port 3308 and I add this:

$conn = new mysqli("localhost", "root", "", "myDB","3308");
like image 56
kamyar Avatar answered Dec 28 '22 06:12

kamyar


I had a similar problem. My code was like this:

$conn=mysqli_connect($servername,$username,$password,$dB) or die("connection failed");
echo "connection success";

Problem: I did not indicate the port number. Solution: I just included the port number, like below:

$conn=mysqli_connect($servername,$username,$password,$db,"3308") or die("connection failed");
echo "connection success";
like image 38
Mabro DoubleC Avatar answered Dec 28 '22 06:12

Mabro DoubleC