+ 1
Php connection error?
This code deceiving me by not getting execute this code shows error as well as connected....show me the right way of doing this...or pls tell why? https://code.sololearn.com/wJUJRtpmkuRl/?ref=app
10 Answers
+ 1
if you want to prevent error from being shown just put this line on top level of your code:
error_reporting(~E_ALL);
+ 1
try this on your local but not in sololearn playground:
<?php
$db = [];
$db['db_host'] = 'localhost';
$db['db_user'] = 'root';
$db['db_pass'] = '';
$db['db_name'] = 'cms';
foreach ($db as $key => $values){
define(strtoupper($key), $values);
}
$connection = mysqli_connect( DB_HOST, DB_USER, DB_PASS, DB_NAME );
if($connection ){
echo "connected";
}
?>
+ 1
What is wrong on mine...just the empty declaration of db đ??
+ 1
you're not explicitly declared "$db" variable
+ 1
But why it is then shows connected on my local texteditor
+ 1
you're not getting any kind of errors ?
+ 1
"Notice undefined variable db and so so."...and then at last shows me connected
+ 1
Actually i am using the post method to display dynamically on my browser...but due to that notice error on connection time i am misleading...
+ 1
and the reason why it's always show connected because mysqli_connect function always return an object of type mysqli:
http://php.net/manual/en/mysqli.construct.php#refsect1-mysqli.construct-returnvalues
+ 1
đ