PHP Interview Questions & Answers for experienced

PHP Interview Questions & Answers for experienced are provided here. TutorialsClass helps you to test your knowledge and enhance your experience.
Read PHP Interview Questions & Answers for experienced candidates to get your dream job.

How can we submit a form without a submit button?

Java script submit() function is used for submit form without submit button. For example: document.formname.submit()

<form action="page2.php" name="contactform">// Form elements</form>

What is PHP floor() function?

With the help of the floor() function, we can convert a numeric value to it’s next lower integer value.

Example of floor() function in PHP:

echo "Floor value of $a is $result";    // Output: Floor value of -145.13 is -145

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

Both PHP functions are used to fetch data from MYSQL database, but there is a difference between mysqli_fetch_array() and mysqli_fetch_object() output format.

With the help of mysqli_fetch_array() function, we can fetch a query’s result data row as an array.

Example of mysqli_fetch_array() Function:

$query="SELECT students, marks FROM class";
while ($arr=mysqli_fetch_array($result))
    echo $arr['students']." ".$arr['marks'];
    echo "<br />";

While mysqli_fetch_object() function, we can fetch a query’s result data row as an object.

Example of mysqli_fetch_object() Function:

$query="SELECT students, marks FROM class";
while ($obj=mysqli_fetch_object($result))
    echo $obj->students." ".$obj->marks;
    echo "<br />";

How can you pass a variable by reference in PHP?

By using an ampersand (&) sign in-front of the variable, we can pass the variable by reference.

Why or when to use variable by reference ?

When PHP function arguments are passed by value, and value is changed within function, it does not change variable value outside the function. To allow a function to modify its argument value outside the function, they must be passed by reference.


function add_line(&$line)
    $line.= 'and extra words added.';
$sample_line= 'This is a sample line, ';
echo $sample_line;    // outputs 'This is a sample line,  and extra words added.'

If we do not use value by reference (&), then the output will be: ‘This is a sample line,’

How you can force maximum execution time error in PHP?

We can use sleep function to consume PHP execution time and it will throw PHP error.

  for($i=0; $i<10; $i++)
    echo $i;
    sleep(300); //delay the exicution of the PHP script
Tutorials Class - Output Window

maximum execution time error in php

How to increase maximum execution time in PHP and WordPress

We mostly see that the maximum execution time of a PHP Script is 30 seconds. If a script takes more than 30 seconds to execute, it will throw the following Fatal error.
Fatal error: Maximum execution time of 30 seconds exceeded in ….

We can increase maximum execution time in PHP and WordPress by using various methods. In the following examples, we have increased maximum execution time to 360 seconds (6 minutes).

Method 1: By adding the code in a PHP file:

We can set the maximum execution time by adding this code in a PHP File. You must add this code in that file which is included earlier in all other pages. Then this function will increase maximum execution time in all those files.
For example, put this code in the header (header.php), or configuration (config.php) if available.

Method 2: Inside the .htaccess file:

We can do the same thing inside the .htaccess file as well. Before editing this file, you make sure to have a backup of .htaccess.
php_value max_execution_time 360

Method 3: Inside the php.ini file:

We can also set the maximum execution time by adding this code in the php.ini file.
max_execution_time = 360

Method 4: Inside wp-config.php file in WordPress:

If you are using WordPress then you can place this code in wp-config.php file.

Note: Note: These methods will only work if you are allowed to change PHP configuration by your Hosting Server.

How to Fix Incorrect format parameter error when importing large database in PHPMyAdmin?

Are you getting Incorrect format parameter error in PHPMyAdmin while importing the database? Most of the time this error is encountered when a user imports a large database file.

Common Reason for “Incorrect format parameter” error:

  • The maximum execution time exceeded in PHP for current file/script/action
  • You are uploading maximum upload file size defined for PHP scripts
  • the post request of the uploaded file has exceeded defined maximum size in PHP
  • You have exceeded the maximum amount of memory that a PHP script is allowed to allocate

Therefore, the fix can be made using the PHP configuration file by increasing the limit.

Fix 1: Compress SQL file

If the issue is related to large file size, the easy way is to compress the SQL file (into .zip) before uploading. PHPMyAdmin supports compressed file import directly.

This is also useful If your server does not allow you to change PHP configuration. The compressed file name should look like

Fix 2: Increase Size in PHP Config

Change or Adjust the PHP Configuration setting according to your file upload size and approximate execution time required. Here is an example to increase the limit using php.ini file.

max_execution_time = 600
max_input_time = 300
memory_limit = 256M
post_max_size = 300M
upload_max_filesize = 300M

Note: You can also try setting as maximum as possible but remember to revert it after work is done.

Fix 3: Directly run using SQL tab:

You can directly copy all data from your sql file into SQL tab and Click on the “Go” button to run all queries. However, this option is less likely to succeed if data is large and exceed default maximum execution time in PHP.

Fix 4: Using Command Line:

If your database file is not in MB but in GB, you may need to use the command line to import it. Here is the sample command:

mysql -u root -p db-name < db-file.sql

Most Hosting control panel also provides SSH access for similar commands on server.