July 27, 2021
PHP MySQL Interview Questions and Answers

PHP MySQL Interview Questions and Answers

PHP MySQL Interview Questions and Answers

PHP Online Training1. What is a Session?

ANS: A session is a logical object created by the PHP engine to allow you to preserve data across subsequent HTTP requests.

There is only one session object available to your PHP scripts at any time. Data saved to the session by a script can be retrieved by the same script or another script when requested from the same visitor.

Sessions are commonly used to store temporary data to allow multiple PHP pages to offer a complete functional transaction for the same visitor.

2. How can we repair a MySQL table?

ANS: The syntax for repairing a mysql table is:

REPAIR TABLE tablename

This command will repair the table specified.
If QUICK is given, MySQL will do a repair of only the index tree.
If EXTENDED is given, it will create index row by row.

3. What is the difference between mysql_fetch_object and mysql_fetch_array?

ANS: MySQL fetch object will collect first single matching record where mysql_fetch_array will collect all matching records from the table in an array

4. What are the different tables present in MySQL?

ANS. Total 5 types of tables we can create
2. Heap
3. Merge

5. How can we create a database using PHP and mysql?

ANS: We can create MySQL database with the use of mysql_create_db ($database Name) to create a database.

6. How many ways we can retrieve the date in result set of mysql using php?

ANS: As individual objects so single record or as a set or arrays.

7. How many values can the SET function of MySQL take?

ANS: MySQL SET function can take zero or more values, but at the maximum it can take 64 values.

8. How can we encrypt and decrypt a data present in a mysql table using mysql?


9. What are the MySQL database files stored in system?

ANS: Data is stored in name.myd
Table structure is stored in name.frm
Index is stored in name.myi

10. How can increase the performance of MySQL select query?

ANS: We can use LIMIT to stop MySql for further search in table after we have received our required no. of records, also we can use LEFT JOIN or RIGHT JOIN instead of full join in cases we have related data in two or more tables.

11. What Is a Persistent Cookie?

ANS: A persistent cookie is a cookie which is stored in a cookie file permanently on the browser’s computer. By default, cookies are created as temporary cookies which stored only in the browser’s memory.

12. How to get the http Request in PHP?

ANS: When PHP is used on a Web server to handle a HTTP request, it converts information submitted in the HTTP request as predefined variables:

$_GET – Associate array of variables submitted with GET method.
$_POST – Associate array of variables submitted with POST method.
$_COOKIE – Associate array of variables submitted as cookies.
$_REQUEST – Associate array of variables from $_GET, $_POST, and $_COOKIE.
$_SERVER – Associate array of all information from the server and the HTTP request.

13. How you provide security for PHP application?

ANS: There are many ways to accomplish the security tasks but the most common 7 ways are

1. Validate Input. Never trust your user and always filter input before taking it to any operation.
2. Provide access control.
3. Session ID protection
4. Preventing Cross Site Scripting (XSS) flaws
5. SQL injection vulnerabilities.
6. Turning off error reporting and exposing to the site for hackers. Instead use log file to catch exceptions
7. Effective Data handling

14. What is SQL Injection in PHP security?

ANS:     SQL injection attacks are extremely simple to defend against, but many applications are still vulnerable.

Protecting against SQL injection is easy:

Filter your data. This cannot be overstressed. With good data filtering in place, most security concerns are mitigated, and some are practically eliminated.

Quote your data. If your database allows it (MySQL does), put single quotes around all values in your SQL statements, regardless of the data type.

Escape your data. Sometimes valid data can unintentionally interfere with the format of the SQL statement itself. Use mysql_escape_string () or an escaping function native to your particular database. If there isn’t a specific one, addslashes () is a good last resort.

15. In how many ways we can retrieve the data in the result set of MySQL using PHP?

ANS:  You can do it by 4 Ways
1. Mysql_fetch_row.

2. Mysql_fetch_array

3. Mysql_fetch_object

4. Mysql_fetch_assoc

For Best PHP Online Training please visit http://www.revanthtechnologies.com