PHP-PDO-MySQL-Class icon indicating copy to clipboard operation
PHP-PDO-MySQL-Class copied to clipboard

Using define to input database credentials and also making them public

Open sachya opened this issue 9 years ago • 2 comments

<?php
define('DBHost', '127.0.0.1');
define('DBName', 'Database');
define('DBUser', 'root');
define('DBPassword', '');
require(dirname(__FILE__)."/src/PDO.class.php");
$DB = new Db(DBHost, DBName, DBUser, DBPassword);
?>

Why can't use ini file that puts credentials to main db function and link with main db php class, which won't require parameters to be required everytime. Just execute db() and go.

sachya avatar Jul 30 '16 11:07 sachya

I'm worried about bad coding habits will lead to some security issues.

lincanbin avatar Jul 30 '16 12:07 lincanbin

@sachya but you could place the above codes for db connection in a separate file and call just include it on pages you want to execute database functions?

marcus-hiles avatar Mar 27 '19 11:03 marcus-hiles