PHP-MySQL

Most Essential And Frequently Asked Interview Questions And Answer

Ans:

PHP-MYSQL |  mysqli_fetch_assoc() VS  mysqli_fetch_array()

mysqli_fetch_assoc() function fetch a result row as an associative array where as mysqli_fetch_array() function fetch a result row as an associative array, a numeric array, or both.

View Detials
Ans:

PHP-MYSQL |  mysqli_fetch_object () VS  mysqli_fetch_array()

mysqli_fetch_object()  fetch a result row as an object where as mysqli_fetch_array()  fetch a result row as an associative array, a numeric array, or both.

View Detials
Ans:

PHP-MYSQL |  Fetch Recoards From MySql table

There are 4 ways:

  1. mysqli_fetch_row() - Get a result row as an enumerated array
  2. mysqli_fetch_array() - Fetch a result row as an associative array, a numeric array, or both
  3. mysqli_fetch_object() - Fetch a result row as an object
  4. mysqli_fetch_assoc() - Fetch a result row as an associative array
View Detials
Ans:

OPTIMIZE command is use for optimize a table.

 OPTIMIZE TABLE `users` 

 

Ans:

For increaseing the speed of a query we have to do couple of things

  • First of all instead of using select * from table1, use select column1, column2, column3.. from table1.
  • Try to introduce index in the table.
  • Always use limit keyword if we are looking for any specific number of rows from the result set.
Ans:

DATEDIFF function is use for finding the number of days between two given dates using MySQL

 DATEDIFF(‘2018-03-07′,’2017-01-01’)

 

Ans:

Bellow code is use for the same

 $sql = "SELECT * FROM table1";
$result = mysql_query($sql, $db_link);
$num_rows = mysql_num_rows($result);
echo $num_rows;

 

Ans:

The three different way in PHP to connect with MySQL is:

  1. MySQL
  2. MySQLI
  3. PDO

Note: We should use MySQLI because MySQLI is imporoved version of MySQL and have more function then MySQL.

Ans:

Mostly we use:

  • utf8_general_ci
  • utf8_unicode_ci

utf8_general_ci is use for fast sorting but it is less accurate whereas utf8_unicode_ci is used for better accuracy but little slow as compare to utf8_general_ci.

We can also use other collation based on specific languages like utf8_swedish_ci.

Ans:

There are 5 different types of storage engine present in MySql.

  1. MyISAM
  2. Heap
  3. Merge
  4. INNO DB
  5. ISAM

MyISAM is the default storage engine for MySQL

Ans:

Cross-site scripting (XSS)

Cross-site scripting (XSS) is a type of computer security vulnerability typically found in web applications. XSS enables attackers to inject client-side script into web pages viewed by other users. A cross-site scripting vulnerability may be used by attackers to bypass access controls such as the same-origin policy.

Ans:

By using mysql function mysqli_insert_id() we can retrive the last inserted id in database table.