Php Interview Questions and Answers – Part 7

This is the 7th part of Php Interview Questions and Answers.

1- How can we destroy the session, how can we unset the variable of a session?

session_unregister() – Unregister a global variable from the current session

session_unset() – Free all session variables
2- What are the different functions in sorting an array?
Sorting functions in PHP:








3- How can we know the count/number of elements of an array?
2 ways:

a) sizeof($array) – This function is an alias of count()

b) count($urarray) – This function returns the number of elements in an array.

Interestingly if you just pass a simple var instead of an array, count() will return 1.
4- How many ways we can pass the variable through the navigation between the pages?
At least 3 ways:

1. Put the variable into session in the first page, and get it back from session in the next page.

2. Put the variable into cookie in the first page, and get it back from the cookie in the next page.

3. Put the variable into a hidden form field, and get it back from the form in the next page.
5- What is the maximum length of a table name, a database name, or a field name in MySQL?
Database name: 64 characters

Table name: 64 characters

Column name: 64 characters
6- What’s the difference between md5(), crc32() and sha1() crypto on PHP?
The major difference is the length of the hash generated. CRC32 is, evidently, 32 bits, while sha1() returns a 128 bit value, and md5() returns a 160 bit value. This is important when avoiding collisions.
7- How can we find the number of rows in a result set using PHP?
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”;
8- Give the syntax of GRANT commands?
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.

We can grant rights on all databse by usingh *.* or some specific database by database.* or a specific table by database.table_name.

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *