-3

I want to create a file in which database credentials are stored. How can I access that data in a php class since include in class body doesn't work?

fatso88
  • 7
  • 6
  • _..since include in class body doesn't work..._ how comes? That is false. Take a look at [include-code-into-a-php-class](https://stackoverflow.com/questions/1957732/can-i-include-code-into-a-php-class) – B001ᛦ Oct 04 '17 at 11:41
  • Refer: https://www.w3schools.com/php/php_mysql_connect.asp – Abhijit Kumbhar Oct 04 '17 at 11:44

1 Answers1

0

I think better way is you create a file dbconf.php and add db credentials as constants. e.g:

<?php // dbconf.php

define('DB_HOST','127.0.0.1');
define('DB_UER','root');
define('DB_PASS','password');
define('DB_NAME','your_database_name');

Then include this file and you can use these constants anywhere in your project.

usman ikram
  • 461
  • 4
  • 10