php - Is "mysqli_query() or die(mysqli_error())" a good practice? -


so use structure execute queries on php, other day pointed out bad practice.

could tell me why wrong , give me tips on should instead? i'm looking learn , improve code.

thanks in advance.

this practice awful. it's bad heredity last century ways of writing code.

instead, have add line before connection code

mysqli_report(mysqli_report_error | mysqli_report_strict); 

it relieve need of writing code every mysql call, make mysqli throw exception in case of error automatically.

while exception way better regular error, can caught , gracefully handled. yet converted error, if not caught, again right - because regular errors, depends on site-wide settings, can either shown on-screen or logged. again without need of writing single line of code.

while developing, have display_errors setting on , see errors moment occurred.
while on live site, display_errors have turned off, log_errors have on instead - , make exception logged, future reference.


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -