Online php and mysql interview Questions with answers-- Asked at different competitive exams
Free Online test your knowledge on php and mysql programming exams. Each questions immediate answer or explanation given below, just click View answer button and also have option of Hide Answer button to hide answer. In this given upto 100+ questions and shows answer or explanation under of each question.
Here all the questions and answers, most asked in different competitive exams and shows answers accordingly.
Q71. What is the difference between PHP4 and PHP5?
- Answer: PHP4 cannot support oops concepts and Zend engine 1 is used.
- PHP5 supports oops concepts and Zend engine 2 is used.
- Error supporting is increased in PHP5.
- XML and SQLLite will is increased in PHP5.
Q72. What is meant by nl2br()?
Answer:
nl2br() inserts a HTML tag <br> before all new line characters \n in a string.
echo nl2br(“god bless \n you”);
output:
god bless<br>
you
echo nl2br(“god bless \n you”);
output:
god bless<br>
you
Q73. How can I retrieve values from one database server and store them in other database server using PHP?
Answer:
For this purpose, you can first read the data from one server into session variables. Then connect to other server and simply insert the data into the database.
Q74. WHO IS THE FATHER OF PHP?
Answer:
Rasmus Lerdorf.
Q75. HOW MANY WAYS WE CAN RETRIEVE DATA IN THE RESULT SET OF MYSQL USING PHP?
Answer:
mysql_fetch_array – Fetch a result row as an associative array, a numeric array, or both
mysql_fetch_assoc – Fetch a result row as an associative array
mysql_fetch_object – Fetch a result row as an object
mysql_fetch_row —- Get a result row as an enumerated array
mysql_fetch_assoc – Fetch a result row as an associative array
mysql_fetch_object – Fetch a result row as an object
mysql_fetch_row —- Get a result row as an enumerated array
Q76.What are the functions for IMAP?
Answer:
imap_body – Read the message body
imap_check – Check current mailbox
imap_delete – Mark a message for deletion from current mailbox
imap_mail – Send an email message
imap_check – Check current mailbox
imap_delete – Mark a message for deletion from current mailbox
imap_mail – Send an email message
Q77. How can we increase the execution time of a php script?
Answer1:
By the use of void set_time_limit(int seconds)
Set the number of seconds a script is allowed to run. If this is reached, the script returns a fatal error. The default limit is 30 seconds or, if it exists, the max_execution_time value defined in the php.ini. If seconds is set to zero, no time limit is imposed.
When called, set_time_limit() restarts the timeout counter from zero. In other words, if the timeout is the default 30 seconds, and 25 seconds into script execution a call such as set_time_limit(20) is made, the script will run for a total of 45 seconds before timing out.
Set the number of seconds a script is allowed to run. If this is reached, the script returns a fatal error. The default limit is 30 seconds or, if it exists, the max_execution_time value defined in the php.ini. If seconds is set to zero, no time limit is imposed.
When called, set_time_limit() restarts the timeout counter from zero. In other words, if the timeout is the default 30 seconds, and 25 seconds into script execution a call such as set_time_limit(20) is made, the script will run for a total of 45 seconds before timing out.
Q78. HOW CAN WE TAKE A BACKUP OF A MYSQL TABLE AND HOW CAN WE RESTORE IT?
Answer1:
Create a full backup of your database: shell> mysqldump tab=/path/to/some/dir optdb_name
Or: shell> mysqlhotcopy db_name /path/to/some/dir
The full backup file is just a set of SQL statements, so restoring it is very easy:
shell> mysql “.”Executed”;
Answer2: To backup: BACKUP TABLE tbl_name TO /path/to/backup/directory
’ To restore: RESTORE TABLE tbl_name FROM /path/to/backup/directory
mysqldump: Dumping Table Structure and Data Utility to dump a database or a collection of database for backup or for transferring the data to another SQL server (not necessarily a MySQL server). The dump will contain SQL statements to create the table and/or populate the table.
-t, no-create-info
Don’t write table creation information (the CREATE TABLE statement).
-d, no-data
Don’t write any row information for the table. This is very useful if you just want to get a dump of the structure for a table!
Or: shell> mysqlhotcopy db_name /path/to/some/dir
The full backup file is just a set of SQL statements, so restoring it is very easy:
shell> mysql “.”Executed”;
Answer2: To backup: BACKUP TABLE tbl_name TO /path/to/backup/directory
’ To restore: RESTORE TABLE tbl_name FROM /path/to/backup/directory
mysqldump: Dumping Table Structure and Data Utility to dump a database or a collection of database for backup or for transferring the data to another SQL server (not necessarily a MySQL server). The dump will contain SQL statements to create the table and/or populate the table.
-t, no-create-info
Don’t write table creation information (the CREATE TABLE statement).
-d, no-data
Don’t write any row information for the table. This is very useful if you just want to get a dump of the structure for a table!
Q79. How to set cookies?
Answer:
setcookie(‘variable’,’value’,’time’);
variable – name of the cookie variable
value – value of the cookie variable
time – expiry time
Example: setcookie(‘Test’,$i,time()+3600);
Test – cookie variable name
$i – value of the variable ‘Test’
time()+3600 – denotes that the cookie will expire after an one hour
setcookie(‘variable’,’value’,’time’);
variable – name of the cookie variable
value – value of the cookie variable
time – expiry time
Example: setcookie(‘Test’,$i,time()+3600);
Test – cookie variable name
$i – value of the variable ‘Test’
time()+3600 – denotes that the cookie will expire after an one hour
Q80. How to reset/destroy a cookie ?
Answer:
Reset a cookie by specifying expire time in the past:
Example: setcookie(‘Test’,$i,time()-3600); // already expired time
Reset a cookie by specifying its name only
Example: setcookie(‘Test’);
Example: setcookie(‘Test’,$i,time()-3600); // already expired time
Reset a cookie by specifying its name only
Example: setcookie(‘Test’);
0 Comments:
Post a Comment