SS-TECH LAB SEC-22 ,Noida, .

New Interview Question and Answer

Currently Placed Student
Best Python Training Institute In Noida SS-TECH
Ajay Kumar
[ PHP Developer ]
QUICK QUERY

Online PHP and Python Class started.

Join online php and python class at sstech lab noida.

How can we create a database using PHP and MySQL?

The necessary steps to create a MySQL database using PHP are:

  • Establish a connection to MySQL server from your PHP script.
  • If the connection is successful, write a SQL query to create a database and store it in a string variable.
  • Execute the query.

What is the Importance of Parser in PHP?

PHP parser parses the PHP developed website from the opening to the closing tag. Tags indicate that from where PHP code is being started and ended. In other words, opening and closing tags decide the scope of PHP scripting syntax of closing tag in PHP

<?php syntax of opening tag in PHP
?> syntax of closing tag in PHP

What is Cookies? How to create cookies in PHP?

A cookie is used to identify a user. A cookie is a little record that the server installs on the client's Computer. Each time a similar PC asks for a page with a program, it will send the cookie as well. With PHP, you can both make and recover cookie value.

Some important points regarding Cookies:

  1. Cookies maintain the session id generated at the back end after verifying the user's identity in encrypted form, and it must reside in the browser of the machine
  2. You can store only string values not object because you can't access any object across the website or web apps
  3. Scope: - Multiple pages.
  4. By default, cookies are temporary and transitory cookie saves in the browser only.
  5. By default, cookies are URL particular means Gmail isn't supported in Yahoo and the vice versa.
  6. Per site 20 cookies can be created in one website or web app
  7. The Initial size of the cookie is 50 bytes.
  8. The Maximum size of the cookie is 4096 bytes.

What are include() and require() functions?

The Include() function is used to put data of one PHP file into another PHP file. If errors occur, then the include() function produces a warning but does not stop the execution of the script, and it will continue to execute.

The Require() function is also used to put data of one PHP file to another PHP file. If there are any errors, then the require() function produces a warning and a fatal error and stops the script.

What is the meaning of a Persistent Cookie?

A persistent cookie is permanently stored in a cookie file on the browser's computer. By default, cookies are temporary and are erased if we close the browser.

How can we get IP address of a client in PHP?

  1. $_SERVER["REMOTE_ADDR"];  

Explain PHP split() function.

The PHP split() function splits string into an array by regular expression.

Explain PHP explode() function.

The PHP explode() function breaks a string into an array.

What is htaccess in PHP?

The .htaccess is a configuration file on Apache server. You can change configuration settings using directives in Apache configuration files like .htaccess and httpd.conf.

What are the encryption functions in PHP?

CRYPT() and MD5()

How to stop the execution of PHP script?

The exit() function is used to stop the execution of PHP script.

What are the different types of errors in PHP?

There are 3 types of error in PHP.

  1. Notices:These are non-critical errors. These errors are not displayed to the users.
  2. Warnings:These are more serious errors, but they do not result in script termination. By default, these errors are displayed to the user.
  3. Fatal Errors:These are the most critical errors. These errors may cause due to immediate termination of script.

How can we increase execution time of a PHP script?

By default, the maximum execution time for PHP scripts is set to 30 seconds. If a script takes more than 30 seconds, PHP stops the script and returns an error.

You can change the script run time by changing the max_execution_time directive in the php.ini file.

When a script is called, set_time_limit function restarts the timeout counter from zero. It means, if default timer is set to 30 sec, and 20 sec is specified in function set_time_limit(), then script will run for 45 seconds. If 0sec is specified in this function, script takes unlimited time.

How to create database connection and query in PHP?

Since PHP 4.3, mysql_reate_db() is deprecated. Now you can use the following 2 alternatives.

  • mysqli_query()
  • PDO::_query()

How to create connection in PHP?

The mysqli_connect() function is used to create a connection in PHP.

  1. resource mysqli_connect (server, username, password)    

How do you connect MySQL database with PHP?

There are two methods to connect MySQL database with PHP. Procedural and object-oriented style.

How can you send email in PHP?

The mail() function is used to send email in PHP.

  1. bool mail($to,$subject,$message,$header); 

How to download file in PHP?

The readfile() function is used to download the file in PHP.

  1. int readfile ( string $filename ) 

How to upload file in PHP?

The move_uploaded_file() function is used to upload file in PHP.

  1. bool move_uploaded_file ( string $filename , string $destination )    

What is the method to execute a PHP script from the command line?

You should just run the PHP command line interface (CLI) and specify the file name of the script to be executed as follows.

How to delete file in PHP?

The unlink() function is used to delete a file in PHP.

  1. bool unlink (string $filename)      

How to write in a file in PHP?

PHP fwrite() and fputs() functions are used to write data into file. To write data into a file, you need to use w, r+, w+, x, x+, c or c+ mode.

How to read a file in PHP?

PHP provides various functions to read data from the file. Different functions allow you to read all file data, read data line by line, and read data character by character.

PHP file read functions are given below:

  • fread()
  • fgets()
  • fgetc()

Write syntax to open a file in PHP?

PHP fopen() function is used to open file or URL and returns resource. It accepts two arguments: $filename and $mode.

Syntax:

  1. resource fopen ( string $filename , string $mode [, bool $use_include_path = false [, resource $context ]] )  

What is the difference between session and cookie?

The main difference between session and cookie is that cookies are stored on user's computer in the text file format while sessions are stored on the server side.

Cookies can't hold multiple variables, on the other hand, Session can hold multiple variables.

You can manually set an expiry for a cookie, while session only remains active as long as browser is open.

What is PHP session_start() and session_destroy() function?

PHP session_start() function is used to start the session. It starts new or resumes the current session. It returns the current session if the session is created already. If the session is not available, it creates and returns new sessions.

What is the method to register a variable into a session?

  1. <?php  
  2. Session_register($ur_session_var);  
  3. ?>  

What is a session?

PHP Engine creates a logical object to preserve data across subsequent HTTP requests, which is known as session.

Sessions generally store temporary data to allow multiple PHP pages to offer a complete functional transaction for the same user.

Simply, it maintains data of an user (browser).

How can you retrieve a cookie value?

  1. echo $_COOKIE ["user"];  

Explain setcookie() function in PHP?

PHP setcookie() function is used to set cookie with HTTP response. Once the cookie is set, you can access it by $_COOKIE superglobal variable.

Syntax:

  1. bool setcookie ( string $name [, string $value [, int $expire = 0 [, string $path     
  2. [, string $domain [, bool $secure = false [, bool $httponly = false ]]]]]] )  

Differentiate between require and include?

Require and include both are used to include a file, but if data is not found include sends warning whereas require sends Fatal error.

What are the ways to include file in PHP?

PHP allows you to include file so that page content can be reused again. There are two ways to add the file in PHP.

  1. include
  2. require

How can you submit a form without a submit button?

You can use JavaScript submit() function to submit the form without explicitly clicking any submit button.

What are the methods to submit form in PHP?

There are two methods GET and POST.

Explain some of the PHP string functions?

There are many array functions in PHP:

  • strtolower()
  • strtoupper()
  • ucfirst()
  • lcfirst()
  • ucwords()
  • strrev()
  • strlen()

How to get the length of string?

The strlen() function is used to get the length of the string.

What is the difference between indexed and associative array?

The indexed array holds elements in an indexed form which is represented by number starting from 0 and incremented by 1. For example:

  1. $season=array("summer","winter","spring","autumn");    
  2. The associative array holds elements with name. For example:

    1. $salary=array("Sonoo"=>"350000","John"=>"450000","Kartik"=>"200000");    

Explain some of the PHP array functions?

There are many array functions in PHP:

  • array()
  • array_change_key_case()
  • array_chunk()
  • count()
  • sort()
  • array_reverse()
  • array_search()
  • array_intersect()

How many types of array are there in PHP?

There are three types of array in PHP:

  1. Indexed array: an array with a numeric key.
  2. Associative array: an array where each key has its specific value.
  3. Multidimensional array: an array containing one or more arrays within itself.

What is the array in PHP?

An array is used to store multiple values in a single value. In PHP, it orders maps of pairs of keys and values. It saves the collection of the data type.

What does isset() function?

The isset() function checks if the variable is defined and not null.

hat is the use of header() function in PHP?

The header() function is used to send a raw HTTP header to a client. It must be called before sending the actual output. For example, you can't print any HTML element before using this function.

What is the use of count() function in PHP?

The PHP count() function is used to count total elements in the array, or something an object.

What are magic constants in PHP?

PHP magic constants are predefined constants, which change based on their use. They start with a double underscore (__) and end with a double underscore (__).

How a variable is declared in PHP?

A PHP variable is the name of the memory location that holds data. It is temporary storage.

Syntax:

 
  1. $variableName=value;

Which programming language does PHP resemble to?

PHP has borrowed its syntax from Perl and C.

What are the popular frameworks in PHP?

  • CakePHP
  • CodeIgniter
  • Yii 2
  • Symfony
  • Zend Framework etc.

What are the popular Content Management Systems (CMS) in PHP?

  • WordPress: WordPress is a free and open-source content management system (CMS) based on PHP & MySQL. It includes a plug-in architecture and template system. It is mostly connected with blogging but supports another kind of web content, containing more traditional mailing lists and forums, media displays, and online stores.
  • Joomla: Joomla is a free and open-source content management system (CMS) for distributing web content, created by Open Source Matters, Inc. It is based on a model-view-controller web application framework that can be used independently of the CMS.
  • Magento: Magento is an open source E-trade programming, made by Varien Inc., which is valuable for online business. It has a flexible measured design and is versatile with many control alternatives that are useful for clients. Magento utilizes E-trade stage which offers organization extreme E-business arrangements and extensive support network.
  • Drupal: Drupal is a CMS platform developed in PHP and distributed under the GNU (General Public License).

What does the scope of variables mean?

The scope of a variable is the context within which it is defined. For the most part, all PHP variables only have a single scope. This single scope spans included and required files as well.

What does $_COOKIE mean?

$_COOKIE is an associative array of variables sent to the current PHP script using the HTTP Cookies

What does $_ENV mean?

$_ENV is an associative array of variables sent to the current PHP script via the environment method.

What does $_FILES means?

$_FILES is an associative array composed of items sent to the current script via the HTTP POST method.

What does $_SERVER mean?

$_SERVER is an array including information created by the web server such as paths, headers, and script locations.

What is the difference between session_unregister() and session_unset()?

The session_unregister() function unregister a global variable from the current session and the session_unset() function frees all session variables.

When do sessions end?

Sessions automatically end when the PHP script finishes executing but can be manually ended using the session_write_close().

How can you propagate a session id?

You can propagate a session id via cookies or URL parameters.

How to initiate a session in PHP?

The use of the function session_start() lets us activating a session.

what is the definition of a session?

A session is a logical object enabling us to preserve temporary data across multiple PHP pages.

Are Parent constructors called implicitly inside a class constructor?

No, a parent constructor have to be called explicitly as follows:

parent::constructor($value)

In PHP, objects are they passed by value or by reference?

In PHP, objects passed by value.

What does the unset() function mean?

The unset() function is dedicated for variable management. It will make a variable undefined.

How be the result set of Mysql handled in PHP?

The result set can be handled using mysqli_fetch_array, mysqli_fetch_assoc, mysqli_fetch_object or mysqli_fetch_row.

What type of operation is needed when passing values through a form or an URL?

If we would like to pass values through a form or an URL, then we need to encode and to decode them using htmlspecialchars() and urlencode().

How is the comparison of objects done in PHP?

We use the operator '==' to test is two objects are instanced from the same class and have same attributes and equal values. We can test if two objects are referring to the same instance of the same class by the use of the identity operator '==='.

What is the meaning of a final class and a final method?

'final' is introduced in PHP5. Final class means that this class cannot be extended and a final method cannot be overridden.

Is multiple inheritance supported in PHP?

PHP supports only single inheritance; it means that a class can be extended from only one single class using the keyword 'extended'.

What is the difference between $message and $$message?

The $var (single dollar) is a normal variable with the name var that stores any value like string, integer, float, etc.

The $$var (double dollar) is a reference variable that stores the value of the $variable inside it.

How a variable is declared in PHP?

A PHP variable is the name of the memory location that holds data. It is temporary storage.

Syntax:

 
  1. $variableName=value;

What is the difference between "echo" and "print" in PHP?

Echo can output one or more string but print can only output one string and always returns 1.

Echo is faster than print because it does not return any value.

What is "print" in PHP?

PHP print output a string. It is a language construct not a function. So the use of parentheses is not required with the argument list. Unlike echo, it always returns 1.

Syntax:

 
  1. int print ( string $arg)  

What is "echo" in PHP?

PHP echo output one or more string. It is a language construct not a function. So the use of parentheses is not required. But if you want to pass more than one parameter to echo, the use of parentheses is required.

Syntax:

 
  1. void echo ( string $arg1 [, string $... ] ) 

What are the popular frameworks in PHP?

  • CakePHP
  • CodeIgniter
  • Yii 2
  • Symfony
  • Zend Framework etc.

Explain the difference between PHP4 and PHP5.

PHP4 doesn't support oops concept and uses Zend Engine 1.

PHP5 supports oops concept and uses Zend Engine 2.

What is the name of scripting engine in PHP?

The scripting engine that powers PHP is called Zend Engine 2.

Explain the difference b/w static and dynamic websites?

In static websites, content can't be changed after running the script. You can't change anything on the site. It is predefined.

In dynamic websites, content of script can be changed at the run time. Its content is regenerated every time a user visit or reload. Google, yahoo and every search engine is the example of dynamic website.

What does $GLOBALS mean?

$GLOBALS is associative array including references to all variables which are currently defined in the global scope of the script.

What is the difference between session_unregister() and session_unset()?

The session_unregister() function unregister a global variable from the current session and the session_unset() function frees all session variables.

When do sessions end?

Sessions automatically end when the PHP script finishes executing but can be manually ended using the session_write_close().

How can you propagate a session id?

You can propagate a session id via cookies or URL parameters.

How to initiate a session in PHP?

The use of the function session_start() lets us activating a session.

what is the definition of a session?

A session is a logical object enabling us to preserve temporary data across multiple PHP pages.

How can we automatically escape incoming data?

We have to enable the Magic quotes entry in the configuration file of PHP.

How is it possible to remove escape characters from a string?

The stripslashes function enables us to remove the escape characters before apostrophes in a string.

What does the unset() function mean?

The unset() function is dedicated for variable management. It will make a variable undefined.

What does the unlink() function mean?

The unlink() function is dedicated for file system handling. It simply deletes the file given as entry.

What is the difference between mysqli_fetch_object() and mysqli_fetch_array()?

The mysqli_fetch_object() function collects the first single matching record where mysqli_fetch_array() collects all matching records from the table in an array.

How can we display information of a variable and readable by a human with PHP?

To be able to display a human-readable result we use print_r().

What is the main difference between require() and require_once()?

require(), and require_once() perform the same task except that the second function checks if the PHP script is already included or not before executing it.

What type of operation is needed when passing values through a form or an URL?

If we would like to pass values through a form or an URL, then we need to encode and to decode them using htmlspecialchars() and urlencode().

How can PHP and HTML interact?

It is possible to generate HTML through PHP scripts, and it is possible to pass pieces of information from HTML to PHP.

What is the meaning of a final class and a final method?

'final' is introduced in PHP5. Final class means that this class cannot be extended and a final method cannot be overridden.

Is multiple inheritance supported in PHP?

PHP supports only single inheritance; it means that a class can be extended from only one single class using the keyword 'extended'.

What is the main difference between PHP 4 and PHP 5?

PHP 5 presents many additional OOP (Object Oriented Programming) features.

How can we display the output directly to the browser?

To be able to display the output directly to the browser, we have to use the special tags <?= and ?>.

What is the correct and the most two common way to start and finish a PHP block of code?

The two most common ways to start and finish a PHP script are:

  and 

How do you execute a PHP script from the command line?

Just use the PHP command line interface (CLI) and specify the file name of the script to be executed as follows:

php script.php

What is the actually used PHP version?

Version 7.1 or 7.2 is the recommended version of PHP.

What does PEAR stand for?

PEAR means "PHP Extension and Application Repository". It extends PHP and provides a higher level of programming for web developers.

Which programming language does PHP resemble?

PHP syntax resembles Perl and C

What is the meaning of a final class and a final method?

'final' is introduced in PHP5. Final class means that this class cannot be extended and a final method cannot be overridden.

Is multiple inheritance supported in PHP?

PHP supports only single inheritance; it means that a class can be extended from only one single class using the keyword 'extended'.

How do you execute a PHP script from the command line?

Just use the PHP command line interface (CLI) and specify the file name of the script to be executed as follows:

php script.php

what is php?

PHP is a server side scripting language. that is used to develop Static websites or Dynamic websites or Web applications. PHP stands for Hypertext Pre-processor, that earlier stood for Personal Home Pages.