Skip to main content

What is Include,Require,Include once and Require once in PHP?


Include and Include once:- 
It is used to include the content of one PHP file to another PHP file, if the file not found then it will provide a warning and show the remaining data.
If we include the same file multiple times then include will display multiple results but include_once will show single result.
for example, if we create a.php file and echo "hello world" then if we include this file into b.php three times then it will display "hello world" three times but include_once will display "hello world" only once.
Example of include PHP:-
a.php code
<?php
echo "hello world";
?>
b.php 
<?php
rinclude("a.php");
include("a.php");
?>
output helloworld helloworld
Example of includeonce PHP:-
a.php code
<?php
echo "hello world";
?>
b.php 
<?php
rinclude_once("a.php");
include_once("a.php");
?>
output helloworld
Require and Require once:-  It is used to include the content of one PHP file to another PHP file, if a file not found then it will provide fatal error and not show remaining data.
If we include the same file multiple times then require will display multiple results but require_once will show single result.
for example, if we create a.php file and echo "hello world" then if we require this file into b.php three times then it will display "hello world" three times but require_once will display "hello world" only once.
Example of require in  PHP:-
a.php code
<?php
echo "hello world";
?>
b.php 
<?php
require("a.php");
require("a.php");
?>
output helloword helloworld
Example of requireonce PHP:-
a.php code
<?php
echo "hello world";
?>
b.php 

<?php
require_once("a.php");
require_once("a.php");
?>
output helloworld
........................................................................................................................................

What is the difference between require and include?
require to provide a fatal error if the file not found but include provide warning message hence if we need urgent requirement of a file then uses require otherwise use include.
What is the difference between include and include-once?
include will display result multiple times for the same file and include once display result only once.
Where we use to include in the project:-
When we create database connectivity then we should always create a connection file separately into the application that will be included on multiple files so that we can easily customize it.

Comments

Popular posts from this blog

Uncontrolled form input in React-JS

  Uncontrolled form input in React-JS? If we want to take input from users without any separate event handling then we can uncontrolled the data binding technique. The uncontrolled input is similar to the traditional HTML form inputs. The DOM itself handles the form data. Here, the HTML elements maintain their own state that will be updated when the input value changes. To write an uncontrolled component, you need to use a ref to get form values from the DOM. In other words, there is no need to write an event handler for every state update. You can use a ref to access the input field value of the form from the DOM. Example of Uncontrolled Form Input:- import React from "react" ; export class Info extends React . Component {     constructor ( props )     {         super ( props );         this . fun = this . fun . bind ( this ); //event method binding         this . input = React . createRef ();...

JSP Page design using Internal CSS

  JSP is used to design the user interface of an application, CSS is used to provide set of properties. Jsp provide proper page template to create user interface of dynamic web application. We can write CSS using three different ways 1)  inline CSS:-   we will write CSS tag under HTML elements <div style="width:200px; height:100px; background-color:green;"></div> 2)  Internal CSS:-  we will write CSS under <style> block. <style type="text/css"> #abc { width:200px;  height:100px;  background-color:green; } </style> <div id="abc"></div> 3) External CSS:-  we will write CSS to create a separate file and link it into HTML Web pages. create a separate file and named it style.css #abc { width:200px;  height:100px;  background-color:green; } go into Jsp page and link style.css <link href="style.css"  type="text/css" rel="stylesheet"   /> <div id="abc"> </div> Exam...

JDBC using JSP and Servlet

JDBC means Java Database Connectivity ,It is intermediates from Application to database. JDBC has different type of divers and provides to communicate from database server. JDBC contain four different type of approach to communicate with Database Type 1:- JDBC-ODBC Driver Type2:- JDBC Vendor specific Type3 :- JDBC Network Specific Type4:- JDBC Client-Server based Driver  or JAVA thin driver:- Mostly we prefer Type 4 type of Driver to communicate with database server. Step for JDBC:- 1  Create Database using MYSQL ,ORACLE ,MS-SQL or any other database 2   Create Table using database server 3   Create Form according to database table 4  Submit Form and get form data into servlet 5  write JDBC Code:-     5.1)   import package    import java.sql.*     5.2)  Add JDBC Driver according to database ide tools     5.3)  call driver in program         ...