PHP Interview Questions – Set 06

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.

How to download file in PHP?

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

int readfile ( string $filename )

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 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.

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:

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

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

$_SERVER[“REMOTE_ADDR“];

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 is $_SESSION in PHP?

A session creates a file in a temporary directory on the server where registered session variables and their session id are stored. This data will be available to all pages on the site amid that visit.

The area of the temporary record is controlled by a setting in the php.ini document called session.save_path.

At the point when a session is begun following things happen –

  1. PHP first makes two duplicates of one of a kind session id for that particular session of the client which is an arbitrary string of 32 hexadecimal numbers, for example, 3c7foj34c3jjhkyepop2fc937e3443.
  2. One copy of unique session id automatically sent to the user?s computer for the sake of synchronization in future ahead, and one copy is being maintained at server side till the session is running.
  3. Whenever you want to access the page of website or web app, then session id of the current user will be associated with the HTTP header, and that will be compared by the session id which is being maintained at the server. After completing the comparison process, you can easily access the page of the website or web app
  4. A session ends when the user closes the browser, or after leaving the site, the server will terminate the session after a predetermined period, commonly 30 minutes duration.

How many types of array are there in PHP?

There are three types of array in PHP:

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

How can you send email in PHP?

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

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