PHP Interview Questions and Answers
Question - 61 : - How can we destroy the session, how can we unset the variable of a session?
Answer - 61 : - session_unregister() - Unregister a global variable from the current session
session_unset() - Free all session variables
Question - 62 : - How can we find the number of rows in a result set using PHP?
Answer - 62 : - Here is how can you find the number of rows in a result set in PHP:
$result = mysql_query($any_valid_sql, $database_link);
$num_rows = mysql_num_rows($result);
echo "$num_rows rows found";
Question - 63 : - How many ways we can we find the current date using MySQL?
Answer - 63 : - SELECT CURDATE();
SELECT CURRENT_DATE();
SELECT CURTIME();
SELECT CURRENT_TIME();
Question - 64 : - Give the syntax of GRANT commands?
Answer - 64 : - The generic syntax for GRANT is as following
GRANT [rights] on [database] TO [username@hostname] IDENTIFIED BY [password]
Now rights can be:
a) ALL privilages
b) Combination of CREATE, DROP, SELECT, INSERT, UPDATE and DELETE etc.
Question - 65 : - Give the syntax of REVOKE commands?
Answer - 65 : - The generic syntax for revoke is as following
REVOKE [rights] on [database] FROM [username@hostname]
Now rights can be:
a) ALL privileges
b) Combination of CREATE, DROP, SELECT, INSERT, UPDATE and DELETE etc.
We can grant rights on all database by using *.* or some specific database by database.* or a specific table by database.table_name.
Question - 66 : - What is the difference between CHAR and VARCHAR data types?
Answer - 66 : - CHAR is a fixed length data type. CHAR(n) will take n characters of storage even if you enter less than n characters to that column. For example, "Hello!" will be stored as "Hello! " in CHAR(10) column.
VARCHAR is a variable length data type. VARCHAR(n) will take only the required storage for the actual number of characters entered to that column. For example, "Hello!" will be stored as "Hello!" in VARCHAR(10) column.
Question - 67 : - How can we encrypt and decrypt a data present in a mysql table using mysql?
Answer - 67 : - AES_ENCRYPT() and AES_DECRYPT()
Question - 68 : - Will comparison of string "10" and integer 11 work in PHP?
Answer - 68 : - Yes, internally PHP will cast everything to the integer type, so numbers 10 and 11 will be compared.
Question - 69 : - What is the functionality of MD5 function in PHP?
Answer - 69 : - string md5(string)
It calculates the MD5 hash of a string. The hash is a 32-character hexadecimal number.
Question - 70 : - How can I load data from a text file into a table?
Answer - 70 : - The MySQL provides a LOAD DATA INFILE command. You can load data from a file. Great tool but you need to make sure that:
a) Data must be delimited
b) Data fields must match table columns correctly