PHP MySQL Interview Questions & Answers
PHP MySQL Interview Questions & Answers
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:
<?php
$conn=mysqli_connect("localhost","username","password","db");
$query="SELECT students, marks FROM class";
$result=mysqli_query($conn,$query);
while ($arr=mysqli_fetch_array($result))
{
echo $arr['students']." ".$arr['marks'];
echo "<br />";
}
mysqli_close($conn);
?>
While mysqli_fetch_object()
function, we can fetch a query’s result data row as an object.
Example of mysqli_fetch_object() Function:
<?php
$conn=mysqli_connect("localhost","username","password","db");
$query="SELECT students, marks FROM class";
$result=mysqli_query($conn,$query);
while ($obj=mysqli_fetch_object($result))
{
echo $obj->students." ".$obj->marks;
echo "<br />";
}
mysqli_close($conn);
?>
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 db-name.sql.zip
.
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.