PHP Interview Questions and Answers – Part 3

41 How can we optimize or increase the speed of a MySQL select query?
• first of all instead of using select * from table1, use select column1, column2, column3.. from table1
• Look for the opportunity to introduce index in the table you are querying.
• use limit keyword if you are looking for any specific number of rows from the result set.

42 How many ways can we get the value of current session id?
session_id() returns the session id for the current session.

43 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

44 How can we set and destroy the cookie n php?
By using setcookie(name, value, expire, path, domain); function we can set the cookie in php ;
Set the cookies in past for destroy. like
setcookie(“user”, “sonia”, time()+3600); for set the cookie
setcookie(“user”, “”, time()-3600); for destroy or delete the cookies;

45 How many ways we can pass the variable through the navigation between the pages?
• GET/QueryString

46 What is the difference between ereg_replace() and eregi_replace()?
eregi_replace() function is identical to ereg_replace() except that this ignores case distinction when matching alphabetic
characters.eregi_replace() function is identical to ereg_replace() except that this ignores case distinction when matching alphabetic characters.

47 What are the different functions in sorting an array?
Sort(), arsort(),
asort(), ksort(),
natsort(), natcasesort(),
rsort(), usort(),
array_multisort(), and

48 How can we know the count/number of elements of an array?
2 ways
a) sizeof($urarray) This function is an alias of count()
b) count($urarray)

49 what is session_set_save_handler in PHP?
session_set_save_handler() sets the user-level session storage functions which are used for storing and retrieving data associated with a session. This is most useful when a storage method other than those supplied by PHP sessions is preferred. i.e. Storing the session data in a local database.

50 How can I know that a variable is a number or not using a JavaScript?
bool is_numeric ( mixed var)
Returns TRUE if var is a number or a numeric string, FALSE otherwise.or use isNaN(mixed var)The isNaN() function is used to check if a value is not a number.

51 List out some tools through which we can draw E-R diagrams for mysql.
Case Studio
Smart Draw

52 How can I retrieve values from one database server and store them in other database server using PHP?
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 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);

53 List out the predefined classes in PHP?

54 How can I make a script that can be bi-language (supports English, German)?
You can maintain two separate language file for each of the language. all the labels are putted in both language files as variables and assign those variables in the PHP source. on runtime choose the required language option.

55 What are the difference between abstract class and interface?
Abstract class: abstract classes are the class where one or more methods are abstract but not necessarily all method has to be abstract.
Abstract methods are the methods, which are declare in its class but not define. The definition of those methods must be in its extending class.Interface: Interfaces are one type of class where all the methods are abstract. That means all the methods only declared but not defined. All the methods must be define by its implemented class.

56 How can we send mail using JavaScript?
JavaScript does not have any networking capabilities as it is designed to work on client site. As a result we can not send mails using JavaScript. But we can call the client side mail protocol mailto via JavaScript to prompt for an email to send. this requires the client to approve it.

57 How can we repair a MySQL table?
The syntex for repairing a MySQL table is
This command will repair the table specified if the quick is given the MySQL will do a repair of only the index tree if the extended is given it will create index row by row

58 What are the advantages of stored procedures, triggers, indexes?
A stored procedure is a set of SQL commands that can be compiled and stored in the server. Once this has been done, clients don’t need to keep re-issuing the entire query but can refer to the stored procedure.
This provides better overall performance because the query has to be parsed only once, and less information needs to be sent between the server and the client. You can also raise the conceptual level by having libraries of functions in the server. However, stored procedures of course do increase the load on the database server system, as more of
the work is done on the server side and less on the client (application) side.Triggers will also be implemented. A trigger is effectively a type of stored procedure, one that is invoked when a particular event occurs.
For example, you can install a stored procedure that is triggered each time a record is deleted from a transaction table and that stored procedure automatically deletes the corresponding customer from a customer table when all his transactions are deleted.Indexes are used to find rows with specific column values quickly.
Without an index, MySQL must begin with the first row and then read through the entire table to find the relevant rows. The larger the table, the more this costs. If the table has an index for the columns in question, MySQL can quickly determine the position to seek to in the middle of the data file without having to look at all the data. If a  table has 1,000 rows, this is at least 100 times faster than reading sequentially. If you need to access most of the rows, it is faster to
read sequentially, because this minimizes disk seeks.

59 What is the maximum length of a table name, database name, and fieldname in MySQL?
The following table describes the maximum length for each type of identifier.
Identifier Maximum Length
Database 64
Table 64
Column 64
Index 64
Alias 255
There are some restrictions on the characters that may appear in identifiers.

60 How many values can the SET function of MySQL take?
MySQL set can take zero or more values but at the maximum it can take 64 values

Sign-up for our email newsletter and get free job alerts, current affairs and GK updates regularly.
Subscribe Here (or)

Leave a Reply

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

6 − = four

Popup Dialog Box Powered By :
  • RSS
  • Facebook
  • Google+
  • Twitter