2020 Posted July 17, 2020 Share Posted July 17, 2020 (edited) Php Folks, As you know, typing the same code over and over again on all files is daunting. I was wondering, if I can have an error_reporting.php file and then put: include('error_reporting.php'); at the top of all my php files as header, where the error_reporting.php would have this content: <?php error_reporting(E_ALL); ini_set('error_reporting','E_ALL'); ini_set('display_errors','1'); ini_set('display_startup_errors','1'); ?> Q1. Is that ok or not ? Q2. Usually, I have a conn.php with content like this: <?php $conn = mysqli_connect("localhost","root","","db_database"); $db_server = 'localhost'; $db_user = 'root'; $db_password = ''; $db_database = 'test'; $conn->set_charset('utf8mb4');//Always use Charset. if (!$conn) { //Error Message to show user in technical/development mode to see errors. die("Database Error : " . mysqli_error($conn)); //Error Message to show User in Layman's mode to see errors. die("Database error."); exit(); } ?> And then, on all my php files, I just reference to the conn.php by putting the following line on the header: include('conn.php'); Or: require('conn.php'); And on each php file, just before dealing with mysql, I have a line like this: mysqli_report(MYSQLI_REPORT_ALL|MYSQLI_REPORT_STRICT); $conn->set_charset("utf8mb4"); Now, I am wondering, why should I write the above 2 lines on all my php files that deal with mysql ? To keep things short, why don;t I just add those 2 lines in the error_reporting.php ? So, it looks like this: error_reporting.php <?php ini_set('error_reporting','E_ALL');//error_reporting(E_ALL); ini_set('display_errors','1'); ini_set('display_startup_errors','1'); mysqli_report(MYSQLI_REPORT_ALL|MYSQLI_REPORT_STRICT); $conn->set_charset("utf8mb4"); ?> Shall I do this or not ? Edited July 17, 2020 by 2020 Quote Link to comment https://forums.phpfreaks.com/topic/311113-include-require-files-what-should-i-do/ Share on other sites More sharing options...
Barand Posted July 17, 2020 Share Posted July 17, 2020 Set the values in the php.ini file instead of using ini_set() all the time. That's what it's for. If you have a startup error the code won't even execute, so not of those ini_set()s can happen. Therefore ini_set('dispay_startup_errors', 1) is as much use as a chocolate teapot. 1 Quote Link to comment https://forums.phpfreaks.com/topic/311113-include-require-files-what-should-i-do/#findComment-1579756 Share on other sites More sharing options...
2020 Posted July 17, 2020 Author Share Posted July 17, 2020 2 hours ago, Barand said: Set the values in the php.ini file instead of using ini_set() all the time. That's what it's for. If you have a startup error the code won't even execute, so not of those ini_set()s can happen. Therefore ini_set('dispay_startup_errors', 1) is as much use as a chocolate teapot. I do not know how to deal with .ini files. What to write in it, etc. Not a single clue. Maybe, you can make a video how to do it and upload the video here for everyone to learn from ? Quote Link to comment https://forums.phpfreaks.com/topic/311113-include-require-files-what-should-i-do/#findComment-1579761 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.