php - Can't connect to localhost -


i learning php , working on script connects db , pulls data.

the website have running on localhost php driven cms.

a segment of script here

define ('db_user','myname'); define ('db_password','somepass123'); define ('db_host','localhost'); define ('db_name','sitename');   // make db connection $dbc = @mysqli_connect('db_host','db_user','db_password','db_name')     or die ('could not connect mysql: ' . mysqli_connect_error()); 

when load page draws on php receive following error output data meant be:

could not connect mysql: unknown mysql server host 'db_host' (1)

i did research on , googling around. suspect issue db_host defined elsewhere. plausible? i'm not experienced enough know if right path.

i did find in config/database.php file, i'm not sure if it's relevant:

$config['default'] = array(     'benchmark' => true,     'persistent' => false,     'connection' => array(         'type' => 'mysqli',         'user' => 'myname',         'pass' => 'somepass123',         'host' => 'localhost',         'port' => false,         'socket' => false,         'database' => 'sitename', 

how approach figuring out next steps? common error? have pointers?

you need drop single quotes around constants:

$dbc = mysqli_connect(db_host,db_user,db_password,db_name)          or die ('could not connect mysql: ' . mysqli_connect_error()); 

you should refrain using @ in front of functions. if wish suppress errors, use proper error handling.


Comments

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -