Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

remove mysqli_connect warning displaying in page

Tags:

php

$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 working without any problem. But if i try to input a wrong sql server or test it to perform an error. This will display:

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 don't want the warning to display if ever theres a problem in connecting the sql server. i just want my own error to display.

like image 373
galao Avatar asked Jun 20 '13 08:06

galao


1 Answers

2 possible options:

  • set the error_reporing level to NOT to show warnings http://php.net/manual/en/function.error-reporting.php
  • put a @ sign before mysqli_connect, this supresses the warning message
like image 123
Fracsi Avatar answered Nov 13 '22 05:11

Fracsi