Jump to content

include() & require() Files - What Should I Do ?


2020
 Share

Recommended Posts

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 by 2020
Link to comment
Share on other sites

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.

  • Like 1
Link to comment
Share on other sites

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 ?

Link to comment
Share on other sites

This thread is more than a year old.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.