Remove mysqli_connect warning on page

$mysqlServer = "***"; $mysqlDb = "***"; $mysqlUser = "***"; $mysqlPass = "***"; $conn = mysqli_connect($mysqlServer, $mysqlUser, $mysqlPass) or die("failed to connect to db"); mysqli_select_db($conn, $mysqlDb) or die("failed to connect select db"); 

I have this code, and its operation is no problem. But if I try to enter the wrong SQL server or test it to execute the error. A message will appear:

 Warning: mysqli_connect(): (HY000/2002): A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. failed to connect select db 

I do not want the warning to be displayed if there is ever a problem connecting the sql server. I just want my own error to be displayed.

+4
source share
3 answers

2 possible options:

+8
source

setting the @ sign before each function to hide errors

 $conn = @mysqli_connect($mysqlServer, $mysqlUser, $mysqlPass) or die("failed to connect to db"); 
0
source

Try the following:

 $conn = mysqli_connect($mysqlServer, $mysqlUser, $mysqlPass, $mysqlDb); 

Pass the database name when connecting as the fourth parameter.

0
source

Source: https://habr.com/ru/post/1487236/


All Articles