Find Interview Questions for Top Companies
Ques:- How can we destroy the session, how can we unset the variable of a session?
Asked In :-
Right Answer:
To destroy a session in PHP, use `session_destroy();`. To unset a specific session variable, use `unset($_SESSION['variable_name']);`.
Comments
Admin May 17, 2020

the better way of destroying a session is to first unset all
the values of $_SESSION variables individually, and then use
the session_destroy() function

Admin May 17, 2020

session_destroy() function destroys all data registered to
current session. use unset function to destroy varible
specified with session. So to destroy $name registered with
session use unset($name) in your php script.

Ques:- How can we take a backup of a mysql table and how can we restore it. ?
Asked In :-
Right Answer:
To take a backup of a MySQL table, you can use the `mysqldump` command:

```bash
mysqldump -u username -p database_name table_name > backup_file.sql
```

To restore the table from the backup, use the following command:

```bash
mysql -u username -p database_name < backup_file.sql
```
Comments
Admin May 17, 2020

We can use below query for exporting data to a .txt file.
mysql> SELECT * FROM <table_name> INTO
OUTFILE '<file_name>' FIELDS TERMINATED BY ',';
We can use below query for importing data from .txt file
mysql> LOAD DATA INFILE <file_name> INTO
TABLE '<table_name>'
FIELDS TERMINATED BY ',';

Admin May 17, 2020

backup of a table:
click on phpmyadmin -> open the database -> click on the
table -> click on export button -> give the file name ->
click on go button -> after that select the table create
statement and insert statement after that save the matter as
a text file.
Restore of a table:
click on phpmyadmin -> open the database ->click on import
button -> and select the file location -> and click on go
button.

Ques:- How can we optimize or increase the speed of a mysql select query?
Asked In :-
Right Answer:
To optimize or increase the speed of a MySQL SELECT query, you can:

1. Use indexes on columns that are frequently used in WHERE clauses, JOINs, and ORDER BY clauses.
2. Select only the columns you need instead of using SELECT *.
3. Use LIMIT to restrict the number of rows returned if applicable.
4. Optimize your database schema by normalizing or denormalizing as needed.
5. Analyze and optimize your queries using the EXPLAIN statement to understand their execution plan.
6. Avoid using functions on indexed columns in WHERE clauses.
7. Use proper data types for your columns.
8. Consider caching query results if the data does not change frequently.
Comments
Admin May 17, 2020

Using Proper Index.
Using LIMIT
using Primary KEy.
Important : Whenever the huge no of updation or deletion
happened in that table use OPTIMIZE TABLE command.This will
reduce the unused space.

Admin May 17, 2020

For increase speed of select query, there are some factor
like...
-By using Limit in query
-By using Index on table
-By using Primary key

Ques:- What is the maximum size of a file that can be uploaded using PHP and how can we change this?
Asked In :-
Right Answer:
The maximum file upload size in PHP is controlled by the `upload_max_filesize` directive in the `php.ini` configuration file. To change this limit, you can modify the `upload_max_filesize` value in `php.ini`, and also ensure that `post_max_size` is larger than `upload_max_filesize`.
Comments
Admin May 17, 2020

By default it is 2Mb. But you can change this limitation in
php.ini file.There is a variable 'upload_max_filesize'

Admin May 17, 2020

2mb

Ques:- How can we increase the execution time of a PHP script?
Asked In :-
Right Answer:
You can increase the execution time of a PHP script by using the `set_time_limit()` function or by modifying the `max_execution_time` directive in the `php.ini` file. For example, you can set it in your script like this:

```php
set_time_limit(300); // Sets the execution time to 300 seconds
```

Or in `php.ini`, you can change it to:

```
max_execution_time = 300
```
Comments
Admin May 17, 2020

Three ways we can solve this.
1) set_time_limit() function
2) ini_set() function
3) Modifying `max_execution_time' value in PHP
configuration(php.ini) file
1 and 2 are using for temporarily purpose. 3 is for permanent.

Admin May 17, 2020

with the help of set_time_limit

Ques:- How can we get the properties (size, type, width, height) of an image using PHP image functions?
Asked In :-
Right Answer:
You can use the `getimagesize()` function in PHP to get the properties of an image. It returns an array containing the image's size, type, width, and height. Here’s an example:

```php
$imagePath = 'path/to/image.jpg';
$imageInfo = getimagesize($imagePath);

$width = $imageInfo[0];
$height = $imageInfo[1];
$type = $imageInfo['mime'];
$size = filesize($imagePath); // Size in bytes
```

This will give you the width, height, type, and size of the image.
Comments
Admin May 17, 2020

exif_imagetype()- for getting type of the image
getimagesize() - for getting size of the image
imagesx - for width
imagesy - for height

Admin May 17, 2020

we can use getimagesize() function which will rtun the array
of its dimension.

Ques:- How can we convert the time zones using PHP?
Asked In :-
Right Answer:
You can convert time zones in PHP using the `DateTime` class along with the `DateTimeZone` class. Here’s an example:

```php
$date = new DateTime('now', new DateTimeZone('America/New_York'));
$date->setTimezone(new DateTimeZone('Europe/London'));
echo $date->format('Y-m-d H:i:s');
```
Comments
Admin May 17, 2020

By using date_default_timezone_get and
date_default_timezone_set function on PHP 5.1.0
// Discover what 8am in Tokyo relates to on the East Coast
of the US
// Set the default timezone to Tokyo time:
date_default_timezone_set('Asia/Tokyo');
// Now generate the timestamp for that particular timezone,
on Jan 1st, 2000
$stamp = mktime(8, 0, 0, 1, 1, 2000);
// Now set the timezone back to US/Eastern
date_default_timezone_set('US/Eastern');
// Output the date in a standard format (RFC1123), this will
print:
// Fri, 31 Dec 1999 18:00:00 EST
echo '
', date(DATE_RFC1123, $stamp) ,'
';?>

Ques:- What is the purpose of the following files having extensions 1) .frm 2) .myd 3) .myi? What do these files contain?
Asked In :-
Right Answer:
1) **.frm**: This file contains the table structure (schema) of a MySQL database table.
2) **.myd**: This file stores the actual data (records) of a MySQL database table.
3) **.myi**: This file contains the indexes for a MySQL database table, which helps in faster data retrieval.
Comments
Admin May 17, 2020

1. ftm - contians structure
2. myd - contains data
3. myi - contain index

Admin May 17, 2020

myd-data stored
myi-index information

Ques:- How can we find the number of rows in a result set using PHP?
Asked In :-
Right Answer:
You can find the number of rows in a result set using the `mysqli_num_rows()` function for MySQLi or `rowCount()` method for PDO.

For MySQLi:
```php
$result = mysqli_query($conn, $query);
$rowCount = mysqli_num_rows($result);
```

For PDO:
```php
$stmt = $pdo->query($query);
$rowCount = $stmt->rowCount();
```
Comments
Admin May 17, 2020

a small correction to above answer, mysql_num_rows($rs)

Admin May 17, 2020

$no_of_rows=mysql_num_rows($result_set_name);
echo $no_of_rows;

Ques:- What are the advantages and disadvantages of Cascading Style Sheets?
Asked In :-
Right Answer:
**Advantages of Cascading Style Sheets (CSS):**
1. Separation of content and presentation, making HTML cleaner.
2. Improved website loading speed due to reduced file size.
3. Easier maintenance and updates for design changes.
4. Consistent styling across multiple pages.
5. Enhanced accessibility and adaptability for different devices.

**Disadvantages of Cascading Style Sheets (CSS):**
1. Browser compatibility issues can arise with different CSS features.
2. Learning curve for complex layouts and advanced techniques.
3. Over-reliance on CSS can lead to issues if not properly managed.
4. Debugging CSS can be challenging, especially with cascading rules.
Comments
Admin May 17, 2020

Advantages and Disadvantages
Greater Control. Style sheets allow far greater control
over the appearance of a document. Many different elements
can be defined and customised, including margins, indents,
font size, line and letter spacing. In addition, elements
can be positioned absolutely on the page.
Separation of Style and Content. By ensuring that the style
and content of a document are kept separate, data is kept
more coherent. In this way, as technologies such as XML and
databases increase, there will be more scope for
integration of existing HTML documents.
Accessibility. Similarly, with the separation of style and
content, documents are made more accessible to those with
disabilities. When style sheets are used, software such as
screen-readers are less likely to be confused by spurious
code. For further information on accessibility issues,
please refer to the W3C's page on the Accessibility
Features of CSS.
Smaller Documents. Because all tags or properties need only
be defined once within a document, or even within a
separate document, filesize can be reduced considerably.
Easier Site Maintenance. As it is possible to link many
pages to one individual style sheet, any sitewide changes
can be made by simply changing the one file that the pages
link to, instead of all the individual files.
Browser Support. This is the one major drawback to style
sheets. They are only supported at all by IE 3 and above
and Netscape 4 and above, but even then, the way in which
the two browsers interpret them can vary considerably.
However, older browsers will still display your website,
simply ignoring the elements they do not understand.

Ques:- What is the functionality of the function html entities?
Asked In :-
Right Answer:
The `htmlentities()` function in PHP converts special characters to HTML entities, which helps prevent issues like XSS (Cross-Site Scripting) by ensuring that characters such as `<`, `>`, and `&` are displayed as text rather than being interpreted as HTML code.
Comments
Admin May 17, 2020

Convert all applicable characters to HTML entities (PHP 3,
PHP 4 , PHP 5)
string htmlentities ( string string [, int quote_style [,
string charset]] )

Admin May 17, 2020

htmlentities will convert all applicable characters to HTML
entities.

Ques:- How can we get second of the current time using date function?
Asked In :-
Right Answer:
You can get the seconds of the current time using the date function in PHP like this:

```php
$seconds = date('s');
```
Comments
Admin May 17, 2020

echo date('s');
This function will give the seconds of the current time.

Admin May 17, 2020

$second = date('s');
echo $second;

Ques:- How can I retrieve values from one database server and store them in other database server using PHP?
Asked In :-
Right Answer:
You can retrieve values from one database server and store them in another using PHP by following these steps:

1. Connect to the first database server using `mysqli_connect()` or `PDO`.
2. Execute a query to retrieve the desired values.
3. Store the retrieved values in an array or variable.
4. Connect to the second database server using `mysqli_connect()` or `PDO`.
5. Prepare an `INSERT` statement to store the values in the second database.
6. Execute the `INSERT` statement with the retrieved values.

Example code snippet:

```php
// Connect to the first database
$sourceConn = new mysqli('source_host', 'username', 'password', 'source_db');
$result = $sourceConn->query("SELECT * FROM source_table");

// Connect to the second database
$destConn = new mysqli('dest_host', 'username', 'password', 'dest_db');

// Loop through the results and insert into the second database
while ($row = $result->fetch
Comments
Admin May 17, 2020

by using import and export

Admin May 17, 2020

we can always fetch from one database and rewrite to
another. Here is a nice solution of it.
$db1 = mysql_connect(”host”,”user”,”pwd”)
mysql_select_db(”db1″, $db1);
$res1 = mysql_query(”query”,$db1);
$db2 = mysql_connect(”host”,”user”,”pwd”)
mysql_select_db(”db2″, $db2);
$res2 = mysql_query(”query”,$db2);At this point you can only
fetch records from you previous ResultSet,
i.e $res1 - But you cannot execute new query in $db1, even
if you supply the link as because the link was overwritten
by the new db.so at this point the following script will fail
$res3 = mysql_query(”query”,$db1); //this will failSo how to
solve that?
Take a look below.
$db1 = mysql_connect(”host”,”user”,”pwd”)
mysql_select_db(”db1″, $db1);
$res1 = mysql_query(”query”,$db1);
$db2 = mysql_connect(”host”,”user”,”pwd”, true)
mysql_select_db(”db2″, $db2);
$res2 = mysql_query(”query”,$db2);
So mysql_connect has another optional boolean parameter
which indicates whether a link will be created or not. as we
connect to the $db2 with this optional parameter set to
‘true’, so both link will remain live.
now the following query will execute successfully.
$res3 = mysql_query(”query”,$db1);

Ques:- How can I make a script that can be bilanguage (supports English, German)?
Asked In :-
Right Answer:
To create a bilingual script in PHP that supports English and German, you can use an associative array to store translations for each language. Here’s a simple example:

```php
$translations = [
'en' => [
'greeting' => 'Hello',
'farewell' => 'Goodbye'
],
'de' => [
'greeting' => 'Hallo',
'farewell' => 'Auf Wiedersehen'
]
];

$language = 'en'; // Change to 'de' for German

echo $translations[$language]['greeting']; // Outputs: Hello or Hallo
```

You can switch the `$language` variable to 'de' for German or 'en' for English to display the corresponding text.
Comments
Admin May 17, 2020

1. create different files to store different languages
eg: languages/eng.php
languages/ger.php
2. add constant variables in both the files
eg: languages/eng.php :: define('QUES','How are you');
eg: languages/ger.php :: contains define('QUES','Wie geht
es Ihnen');
3. in template page need to use the constant variable to
load the different language
eg: <div><?php echo QUES;?></div>
4. load different files according to language request
5. ofcourse we need to use characters encoding UTF-8 in HTMl
or PHP pages.

Admin May 17, 2020

See PHP Scripts can be written only in english. If you want
support, i mean you want to see pages in Other languages
then use characters encoding UTF-8 in HTMl or PHP pages.
It will work.

Ques:- What is the PHP predefined variable that tells the What types of images that PHP supports?
Asked In :-
Right Answer:
The PHP predefined variable that tells the types of images that PHP supports is `gd_info()`.
Comments
Admin May 17, 2020

int imagetypes ( void )
This function returns a bit-field corresponding to the image
formats supported by the version of GD linked into PHP. The
following bits are returned, IMG_GIF | IMG_JPG | IMG_PNG |
IMG_WBMP | IMG_XPM.

Ques:- How can I know that a variable is a number or not using a JavaScript?
Asked In :-
Right Answer:
You can use the `typeof` operator or the `isNaN()` function. For example:

```javascript
let variable = 5;
if (typeof variable === 'number' && !isNaN(variable)) {
console.log("It's a number");
} else {
console.log("It's not a number");
}
```
Comments
Admin May 17, 2020

By using isNaN() function

Admin May 17, 2020

bool_is_numeric

Ques:- List out some tools through which we can draw E-R diagrams for mysql?
Asked In :-
Right Answer:
1. MySQL Workbench
2. dbForge Studio for MySQL
3. Lucidchart
4. Draw.io
5. DBeaver
6. ER/Studio
7. Microsoft Visio
8. Creately
Comments
Admin May 17, 2020

Microsoft Visio
WorkBench

Admin May 17, 2020

Man dont give wrong answers.
question is about tools for ER for MySQL. Its not related
PHP.ini or something like that.
Well one of the tool which i use is
MySQL WorkBench

Ques:- How many ways we can pass the variable through the navigation between the pages?
Asked In :-
Right Answer:
There are several ways to pass variables between pages in PHP:

1. **GET Method**: Using URL parameters (e.g., `page.php?var=value`).
2. **POST Method**: Submitting form data via HTTP POST.
3. **Sessions**: Storing variables in session storage (`$_SESSION`).
4. **Cookies**: Storing variables in cookies (`$_COOKIE`).
5. **Hidden Form Fields**: Including hidden fields in forms to pass data.
Comments
Admin May 17, 2020

Session
cookies
get
post
request

Admin May 17, 2020

There are three ways to pass variables through the
navigation between the pages.
1. Start the session, register variables that you want to
pass on subsequent pages. In subsequent pages again start
the session so you can get all the varibles that registered
with session.
2. Use query string to pass varibles.
3. With the use of form you can pass varibles which you
have used in the form to the page specified with action
attribute.

Ques:- What is the difference between ereg_replace() and eregi_replace()?
Asked In :-
Right Answer:
`ereg_replace()` is case-sensitive, while `eregi_replace()` is case-insensitive.
Comments
Admin May 17, 2020

eregi_replace() function is identical to ereg_replace()
except that it ignores case distinction when matching
alphabetic characters

Admin May 17, 2020

ereg_replace() is case sensitive like "test" cannot be
treated as "TeSt" and eregi_replace() is not case sensitive
that means insensitive where "test" could be treated as "TeSt".

Ques:- What are the differences between PHP 3 and PHP 4 and PHP 5?
Asked In :-
Right Answer:
PHP 3 introduced support for more databases and improved performance. PHP 4 added the Zend Engine, which enhanced performance and introduced support for sessions and output buffering. PHP 5 brought object-oriented programming features, improved XML support, and the introduction of the PDO (PHP Data Objects) extension for database access.
Comments
Admin May 17, 2020

php3-functionalities are addes
php4-zend engine is added
php5-oops concepts are added

Admin May 17, 2020

Not differences between PHP 3 and PHP 4 and PHP 5



The Core PHP category on takluu.com is designed for developers preparing for interviews that test their understanding of PHP fundamentals and server-side scripting. Core PHP forms the backbone of many web applications, enabling developers to create dynamic, interactive, and database-driven websites.

This section covers important topics such as PHP syntax, variables, data types, control structures, functions, arrays, sessions, cookies, file handling, and error handling. Additionally, it delves into working with forms, connecting to databases using MySQLi or PDO, and implementing security best practices like input validation and SQL injection prevention.

Interview questions often include practical coding problems, debugging scenarios, and explanations of how PHP interacts with the web server and databases. Understanding how to write clean, maintainable code and optimize PHP scripts for performance is also emphasized.

Candidates aspiring for roles like PHP Developer, Backend Developer, or Full Stack Developer will benefit from detailed tutorials, common interview questions, and real-world examples focused on Core PHP concepts.

At Takluu, we focus on building a strong foundation in Core PHP, enabling you to handle coding rounds confidently and develop scalable web solutions.

Whether you are a beginner or looking to refresh your PHP skills, this category provides comprehensive learning material and interview preparation tips to help you succeed.

AmbitionBox Logo

What makes Takluu valuable for interview preparation?

1 Lakh+
Companies
6 Lakh+
Interview Questions
50K+
Job Profiles
20K+
Users