pickzy.com

C  |  C++  |  Objective-C  |  VC++  |  Win32  |  MFC  |  Java  |  Php  |  Delphi  |  Visual Basic  |  .Net  |  Networking  |  General  |  Games  |  Jobs  |  Javascript  |  




Menu

pickSourcecode.com


        

 




 

Php > Articles

 

PHP Interview questions and answers

  1. What are the differences between Get and post methods in form submitting, give the case where we can use get and we can use post methods?

  2. Who is the father of PHP and explain the changes in PHP versions?

  3. How can we submit a form without a submit button?

  4. In how many ways we can retrieve the date in the result set of mysql using PHP?

  5. What is the difference between mysql_fetch_object and mysql_fetch_array?

  6. What is the difference between $message and $$message?

  7. How can we extract string ‘abc.com ‘ from a string ‘http://info@abc.com’ using regular expression of PHP?

  8. How can we create a database using PHP and mysql?

  9. What are the differences between require and include, include_once?

  10. Can we use include (”abc.PHP”) two times in a PHP page “makeit.PHP”?

  11. What are the different tables present in mysql, which type of table is generated when we are creating a table in the following syntax: create table employee(eno int(2),ename varchar(10)) ?

  12. Functions in IMAP, POP3 AND LDAP?

  13. How can I execute a PHP script using command line?

  14. Suppose your Zend engine supports the mode <? ?> Then how can u configure your PHP Zend engine to support <?PHP ?> mode ?

  15. Shopping cart online validation i.e. how can we configure Paypal, etc.?

  16. What is meant by nl2br()?

  17. Draw the architecture of Zend engine?

  18. What are the current versions of apache, PHP, and mysql?

  19. What are the reasons for selecting lamp (linux, apache, mysql, PHP) instead of combination of other software programmes, servers and operating systems?

  20. How can we encrypt and decrypt a data present in a mysql table using mysql?

  21. How can we encrypt the username and password using PHP?

  22. What are the features and advantages of object-oriented programming?

  23. What are the differences between procedure-oriented languages and object-oriented languages?

  24. What is the use of friend function?

  25. What are the differences between public, private, protected, static, transient, final and volatile?

  26. What are the different types of errors in PHP?

  27. What is the functionality of the function strstr and stristr?

  28. What are the differences between PHP 3 and PHP 4 and PHP 5?

  29. How can we convert asp pages to PHP pages?

  30. What is the functionality of the function htmlentities?

  31. How can we get second of the current time using date function?

  32. How can we convert the time zones using PHP?

  33. What is meant by urlencode and urldocode?

  34. What is the difference between the functions unlink and unset?

  35. How can we register the variables into a session?

  36. How can we get the properties (size, type, width, height) of an image using PHP image functions?

  37. How can we get the browser properties using PHP?

  38. What is the maximum size of a file that can be uploaded using PHP and how can we change this?

  39. How can we increase the execution time of a PHP script?

  40. How can we take a backup of a mysql table and how can we restore it. ?

  41. How can we optimize or increase the speed of a mysql select query?

  42. How many ways can we get the value of current session id?

  43. How can we destroy the session, how can we unset the variable of a session?

  44. How can we destroy the cookie?

  45. How many ways we can pass the variable through the navigation between the pages?

  46. What is the difference between ereg_replace() and eregi_replace()?

  47. What are the different functions in sorting an array?

  48. How can we know the count/number of elements of an array?

  49. What is the PHP predefined variable that tells the What types of images that PHP supports?

  50. How can I know that a variable is a number or not using a JavaScript?

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

  52. How can I retrieve values from one database server and store them in other database server using PHP?

  53. List out the predefined classes in PHP?

  54. How can I make a script that can be bilanguage (supports English, German)?

  55. What are the difference between abstract class and interface?

  56. How can we send mail using JavaScript?

 

Answers:

 

Q9.

The include_once() statement includes and evaluates the specified file during the execution of the script. This is a behavior similar to the include() statement, with the only difference being that if the code from a file has already been included, it will not be included again. The major difference between include() and require() is that in failure include produces a warning message whereas require produces a Fatal errors.

(or)

include() & require() - includes the file during the execution of the script.
but is there is any problem include() generate a warning message where as
require() generates the fatal error.
include_once() & require_once() - same as include() and require() but
if file is already included then does not produce any error or not
include that file again

Q5) What is the difference between mysql_fetch_object
and mysql_fetch_array?

Ans :
Speed-wise, the function is identical to mysql_fetch_array(),
and almost as quick as mysql_fetch_row() (the difference is
insignificant).

mysql_fetch_object() is similar to mysql_fetch_array(),
with one difference - an object is returned,
instead of an array. Indirectly, that means that you can only
access the data by the field names, and not by their offsets
(numbers are illegal property names).

(or)

mysql_fetch_array — Fetch a result row as an associative ARRAY, a numeric array, or both
mysql_fetch_object — Fetch a result row as an OBJECT

4. IN HOW MANY WAYS WE CAN RETRIEVE THE DATE IN THE RESULT SET OF MYSQL USING PHP?

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

6. WHAT IS THE DIFFERENCE BETWEEN $MESSAGE AND $$MESSAGE?

$message is a variable
$$message is a variable variable.
A variable variable allows us to change the name of a variable dynamically.

11. WHAT ARE THE DIFFERENT TABLES PRESENT IN MYSQL, WHICH TYPE OF TABLE IS GENERATED WHEN WE ARE CREATING A TABLE IN THE FOLLOWING SYNTAX: CREATE TABLE EMPLOYEE(ENO INT(2),ENAME VARCHAR(10)) ?

MyISAM: This is default. Based on Indexed Sequntial Access Method. The above SQL will create a MyISA table.
ISAM : same
HEAP : Fast data access, but will loose data if there is a crash. Cannot have BLOB, TEXT & AUTO INCRIMENT fields
BDB : Supports Transactions using COMMIT & ROLLBACK. Slower that others.
InoDB : same as BDB

12. FUNCTIONS IN IMAP, POP3 AND LDAP?

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

13. HOW CAN I EXECUTE A PHP SCRIPT USING COMMAND LINE?

As of version 4.3.0, PHP supports a new SAPI type (Server Application Programming Interface) named CLI which means Command Line Interface.

14. SUPPOSE YOUR ZEND ENGINE SUPPORTS THE MODE THEN HOW CAN U CONFIGURE YOUR PHP ZEND ENGINE TO SUPPORT MODE ?

Its already supported.

15. WHAT IS MEANT BY NL2BR()?

Returns string with after inserting HTML line breaks before all newlines in a string

16. HOW CAN WE ENCRYPT AND DECRYPT A DATA PRESENT IN A MYSQL TABLE USING MYSQL?

AES_ENCRYPT(str,key_str) , AES_DECRYPT(crypt_str,key_str)

17. ENCRYPTION FUNCTIONS IS PHP

CRYPT()
MD5()

19. WHAT ARE THE DIFFERENT TYPES OF ERRORS IN PHP?

here are three basic types of runtime errors in PHP:

1. Notices: These are trivial, non-critical errors that PHP encounters while executing a script - for example, accessing a variable that has not yet been defined. By default, such errors are not displayed to the user at all - although you can change this default behaviour.

2. Warnings: These are more serious errors - for example, attempting to include() a file which does not exist. By default, these errors are displayed to the user, but they do not result in script termination.

3. Fatal errors: These are critical errors - for example, instantiating an object of a non-existent class, or calling a non-existent function. These errors cause the immediate termination of the script, and PHP’s default behaviour is to display them to the user when they take place.

Internally, these variations are represented by twelve different error types

 

20. WHAT IS THE FUNCTIONALITY OF THE FUNCTIONS STRSTR() AND STRISTR()?

string strstr ( string haystack, string needle )
Returns part of haystack string from the first occurrence of needle to the end of haystack.

$email = ‘user@example.com’;
$domain = strstr($email, ‘@’);
echo $domain; // prints @example.com

stristr() is the case insensitive version of strstr()

21. DIFFERENCE BETWEEN HTMLENTITIES() AND HTMLSPECIALCHARS()]

htmlspecialchars : Convert some special characters to HTML entities (Only the most widley used)
htmlentities : Convert ALL special characters to HTML entities

22. WHAT IS MEANT BY URLENCODE AND URLDOCODE?

urlencode : Returns a string in which all non-alphanumeric characters except -_. have been replaced with a percent (%) sign followed by two hex digits and spaces encoded as plus (+) signs.

urldocode : Decodes URL-encoded string

23. WHAT IS THE DIFFERENCE BETWEEN THE FUNCTIONS UNLINK AND UNSET?

unlink: is used to delete a file
unset is used to destroy an eralier declared variable

24. HOW CAN WE REGISTER THE VARIABLES INTO A SESSION?

$_SESSION[’name’] = “Chinmay”;

To destroy a session: unset($_SESSION[’name’]);

25. HOW CAN WE GET THE PROPERTIES (SIZE, TYPE, WIDTH, HEIGHT) OF AN IMAGE USING PHP IMAGE FUNCTIONS?

getimagesize — Get the size of an image
image_type_to_extension — Get file extension for image type
imagesx — Get image width
imagesy — Get image height

26. UPLOAD FILE SIZE

In Php.ini file: upload_max_filesize integer

The maximum size of an uploaded file.
When an integer is used, the value is measured in bytes.

27. HOW CAN WE INCREASE THE EXECUTION TIME OF A PHP SCRIPT?

Use set_time_limit(int) where int is the number of seconds for
execution of the script. If it’s set to 0 it’s unlimited. Default value
is 30.

28. HOW CAN WE TAKE A BACKUP OF A MYSQL TABLE AND HOW CAN WE RESTORE IT. ?

To backup: BACKUP TABLE tbl_name[,tbl_name…] TO ‘/path/to/backup/directory’
RESTORE TABLE tbl_name[,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!

29. OPTIMISING QUERIES

First, one thing that affects all queries: The more complex permission system setup you have, the more overhead you get.
If you do not have any GRANT statements done, MySQL will optimise the permission checking somewhat. So if you have a very high volume it may be worth the time to avoid grants. Otherwise, more permission check results in a larger overhead.

30. COOKIES

setcookie(”variable”,”value”,”time”);

variable - name of the cookie variable
variable - 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

31. HOW TO RESET/DESTROY A COOKIE

Reset a cookie by specifying expiry time
Example: setcookie(”test”,$i,time()-3600); // already expired time

Reset a cookie by specifying its name only
setcookie(”test”);

32. 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

33. WHAT TYPES OF IMAGES THAT PHP SUPPORTS?

imagetypes — Return the image types supported by this PHP build
This function returns a bit-field corresponding to the image formats supported by the version of GD linked into PHP. The following bits are returned, IMG_GIF | IMG_JPG | IMG_PNG | IMG_WBMP | IMG_XPM. To check for PNG support, for example, do this: Example 1. imagetypes() example

34. CHECK IF A VARIABLE IS INTEGER IN JAVASCRIPT

var myValue =9.8;
if(parseInt(myValue)== myValue)
alert(’Integer’);
else
alert(’Not’);

35. TOOLS USED FOR DRAWING ER DIAGRAMS.

Case Studio
Smart Draw

What are "Get" and "Post"?
Get and Post are methods used to send data to the server: With the Get method, the browser appends the data onto the URL. With the Post method, the data is sent as "standard input."
Major Difference
In simple words, in POST method data is sent by standered input (nothing
shown in url when posting while in GET method data is sent through query string.

ex:
Assume we are logging in with username and password.
GET: we are submitting a form to login.php, when we do ’submit’ or similar
action to post the form values are sent through ‘visible’ query string (notice
‘../login.php?username&password’ as url when executing the script login.php)and
is retrieved by login.php by $_GET[’username’] and $_GET[’password’].
POST :we are submitting a form to login.php, when we do ’submit’ or
similar action to post the form, values are sent through ‘invisible’ standered
input (notice ‘../login.php’) and is retrieved by login.php by $_POST[’username’]
and $_POST[’password’].
POST is assumed more secure and we can send lot more data than that of GET
method is limited(they say Internet Explorer can take care of maximum 2083 character
as a query string).

1. What are the differences between Get and post methods in form submitting, give the case where we can use get and we can use post methods?
Ans :-
In the get method the data made available to the action page ( where data is received ) by the URL so data can be seen in the address bar. Not advisable if you are sending login info like password etc. In the post method the data will be available as data blocks and not as query string in case of get method.

2. Who is the father of php and explain the changes in php versions?
Ans :-
Rasmus Lerdorf for version changes goto http://php.net/

3. How can we submit from without a submit button?
Ans:-
Trigger the JavaScript code on any event ( like onselect of drop down list box, onfocus, etc ) document.myform.submit();This will submit the form.

4. How many ways we can retrieve the date in result set of mysql using php?
Ans:-
As individual objects so single record or as a set or arrays.

5. What is the difference between mysql_fetch_object and mysql_fetch_array?
Ans:-
MySQL fetch object will collect first single matching record where mysql_fetch_array will collect all matching records from the table in an array

6. What is the difference between $message and $$message?
Ans:-
Both are variables only
$message is a variable and if used with print statement, the content of the $message variable will be displayed. Where as with $$message variable, the content of the $message will also be treated as variable and the content of that variable will be displayed. For ex: If $message contains “var”, then it displays the content of $var on the screen.

7. How can we extract string ‘abc.com ‘ from a string ‘http://info@abc.com’ using regular _expression of php?
Ans:-
preg_match(”/^(http:\/\/info@)?([^\/]+)/i”,”http://info@abc.com”, $data);
echo $data[2];

Use the function split split(“@”,”http://info@abc.com”) which returns an array any second element of the returned array will hold the value as abc.com.

8. How can we create a database using php and mysql?
Ans:-
mysql_create_db()

9. What are the differences between require and include, include_once?Ans:-
File will not be included more than once.
If we want to include a file once only and further calling of the file will be ignored then we have to use the PHP function include_once(). This will prevent problems with function redefinitions, variable value reassignments, etc.

10. Can we use include (”abc.php”) two times in a php page “makeit.php”?
Ans:-
Yes we can include..

11. What are the different tables present in mysql, which type of table is generated when we are creating a table in the following syntax: create table employee(eno int(2),ename varchar(10)) ?
Ans:-
Total 5 types of tables we can create
1. MyISAM
2. Heap
3. Merge
4. INNO DB
5. ISAM
MyISAM is the default storage engine as of MySQL 3.23.

Table Types are
· ISAM(Index Sequential Access Method)
· MyISAM
o Static
o Dynamic
o Compress
· Merge
· Heap (Fastest tables because it stores in to the RAM)
· BDB
· InnoDB (Transaction safe table)

When you fire the above create query MySQL will create the Dynamic table.
http://dev.mysql.com/doc/mysql/en/storage-engines.html
MyISAM Table Type is created, if u not specified any table type then default will be applied and MyISAM is default

13. How can I execute a PHP script using command line?
Ans:-
Through php parse you can execute PHP script using command line. By default location of php parser is /var/www/html so set the path of this directory and just use as following
#php sample.php

16. What is meant by nl2br()?
Ans:-
nl2br() inserts html in string
echo nl2br(”god bless \n you”);

output–
god bless
you

Returns string with ‘’ inserted before all newlines

20. How can we encrypt and decrypt a data present in a mysql table using mysql?
Ans:-
AES_ENCRYPT() and AES_DECRYPT()

21. How can we encrypt the username and password using PHP?
Ans:-
You can encrypt a password with the following
Mysql>SET PASSWORD=PASSWORD(”Password”);

26. What are the different types of errors in PHP?
Ans:-
Three are three types of errors 1) Fatal errors 2) Parser errors 3) Startup errors.

27. What is the functionality of the function strstr and stristr?
Ans:-
string strstr ( string str1, string str2) this function search the string str1 for the first occurrence of the string str2 and returns the part of the string str1 from the first occurrence of the string str2. This function is case-sensitive and for case-insensitive search use stristr() function.

28. What are the differences between PHP 3 and PHP 4 and PHP 5?
Ans:-
for this ans goto http://php.net and check the version changes

29. How can we convert asp pages to PHP pages?
Ans:-
You can download asp2php front end application from the site http://asp2php.naken.cc.

33. What is meant by urlencode and urldocode?
Ans:-
string urlencode(str)
where str contains a string like this “hello world” and the return value will be URL encoded and can be use to append with URLs, normaly used to appned data for GET like someurl.com?var=hello%world
string urldocode(str)
this will simple decode the GET variable’s value
Like it echo (urldecode($_GET_VARS[var])) will output “Hello world”

34. What is the difference between the functions unlink and unset?
Ans:-
unlink is a function for file system handling. It will simply delete the file in context
unset will set UNSET the variable. e.g

35. How can we register the variables into a session?
Ans:-
Yes we can
session_register($ur_session_var);

42. How many ways can we get the value of current session id?
ans:-
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?
Ans:-
session_unregister — Unregister a global variable from the current session
session_unset — Free all session variables

44. How can we destroy the cookie?
Ans:-
Set the cookie in past

45. How many ways we can pass the variable through the navigation between the pages?
Ans:-
GET or QueryString and POST

46. What is the difference between ereg_replace() and eregi_replace()?
Ans:-
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?
Ans:-
Sorting functions in PHP,
asort-http://www.php.net/manual/en/function.asort.php
arsort-http://www.php.net/manual/en/function.arsort.php
ksort-http://www.php.net/manual/en/function.ksort.php
krsort-http://www.php.net/manual/en/function.krsort.php
uksort-http://www.php.net/manual/en/function.uksort.php
sort-http://www.php.net/manual/en/function.sort.php
natsort-http://www.php.net/manual/en/function.natsort.php
rsort-http://www.php.net/manual/en/function.rsort.php

48. How can we know the count/number of elements of an array?
Ans:-
2 ways
a) sizeof($urarray) This function is an alias of count()
b) count($urarray)
interestingly if u just pass a simple var instead of a an array it will return 1.

53. List out the predefined classes in PHP?
Ans:-
1. Standard Defined Classes
These classes are defined in the standard set of functions included in the PHP build.

a. Directory
The class from which dir() is instantiated.

b.stdClass

2.Ming Defined Classes
These classes are defined in the Ming extension, and will only be available when that
extension has either been compiled into PHP or dynamically loaded at runtime.

a.swfshape

b. swffill

c. swfgradient

d. swfbitmap

e. swftext

f. swftextfield

g. swffont

h. swfdisplayitem

i. swfmovie

j. swfbutton

k. swfaction

l. swfmorph

m. swfsprite

3. Oracle 8 Defined Classes
These classes are defined in the Oracle 8 extension, and will only be available when
that extension has either been compiled into PHP or dynamically loaded at runtime.

a. OCI-Lob
b. OCI-Collection

4. qtdom Defined Classes
These classes are defined in the qtdom extension, and will only be available when that
extension has either been compiled into PHP or dynamically loaded at runtime.

a. QDomDocument

b. QDomNode

56. How can we send mail using JavaScript?
Ans:-
No You can’t send mail using Javascript but u can execute a client side email client to send the email using mailto: code.

Using clientside email client
function myfunction(form)
{
tdata=document.myform.tbox1.value;
location=”mailto:mailid@domain.com?subject=”+tdata+”/MYFORM”;
return true;
}

This question is wrong. You aren’t really ’sending mail’ when doing a ‘mailto’ and so it’s a misleading question… A smart candidate would just say “It’s not possible” and you may write him off.

57. What is meant by PEAR in php?
Ans:-
PEAR is the next revolution in PHP. This repository is bringing higher level programming to PHP. PEAR is a framework and distribution system for reusable PHP components. It eases installation by bringing an automated wizard, and packing the strength and experience of PHP users into a nicely organised OOP library. PEAR also provides a command-line interface that can be used to automatically install “packages”

58. What is the purpose of the following files having extensions 1) frm 2) MYD 3) MYI. What these files contains?
Ans:-
In MySql, the default table type is MyISAM.
Each MyISAM table is stored on disk in three files. The files have names that begin with the table name and have an extension to indicate the file type.
The `.frm’ file stores the table definition.
The data file has a `.MYD’ (MYData) extension.
The index file has a `.MYI’ (MYIndex) extension,

1. What are the differences between GET and POST methods in form submitting, give the case where we can use get and we can use post methods?

On the server side, the main difference between GET and POST is where the submitted is stored. The $_GET array stores data submitted by the GET method. The $_POST array stores data submitted by the POST method.

On the browser side, the difference is that data submitted by the GET method will be displayed in the browser’s address field. Data submitted by the POST method will not be displayed anywhere on the browser.

GET method is mostly used for submitting a small amount and less sensitive data. POST method is mostly used for submitting a large amount or sensitive data.

2. Who is the father of php and explain the changes in php versions?

Rasmus Lerdorf for version changes go to http://php.net/ Marco Tabini is the founder and publisher of php|architect.

3. How can we submit from without a submit button?

We can use a simple JavaScript code linked to an event trigger of any form field. In the JavaScript code, we can call the document.form.submit() function to submit the form. For example:

4. How many ways we can retrieve the date in result set of mysql Using php?

As individual objects so single record or as a set or arrays.

5. What is the difference between mysql_fetch_object and mysql_fetch_array?

MySQL fetch object will collect first single matching record where mysql_fetch_array will collect all matching records from the table in an array.

6. What is the difference between $message and $$message?

They are both variables. But $message is a variable with a fixed name. $$message is a variable who’s name is stored in $message. For example, if $message contains "var", $$message is the same as $var.

7. How can we extract string ‘abc.com ‘ from a string ‘http://info@a…’ using regular _expression of php?

We can use the preg_match() function with "/.*@(.*)$/" as the regular expression pattern. For example: preg_match("/.*@(.*)$/","http://info@abc.com",$data); echo $data[1];

8. How can we create a database using php and mysql?

PHP: mysql_create_db()
Mysql: create database;

9. What are the differences between require and include, include_once?

File will not be included more than once. If we want to include a file once only and further calling of the file will be ignored then we have to use the PHP function include_once(). This will prevent problems with function redefinitions, variable value reassignments, etc.

10. Can we use include ("abc.php") two times in a php page "makeit.php"?

Yes we can include..

11. What are the different tables present in mysql, which type of table is generated when we are creating a table in the following
syntax: create table employee(eno int(2),ename varchar(10)) ?

Total 5 types of tables we can create

1. MyISAM

2. Heap

3. Merge

4. InnoDB

5. ISAM

6. BDB
MyISAM is the default storage engine as of MySQL 3.23.

12. Functions in IMAP, POP3 AND LDAP?

Please visit:
http://fi2.php.net/imap
http://uk2.php.net/ldap

13. How can I execute a php script using command line?

Just run the PHP CLI (Command Line Interface) program and provide the PHP script file name as the command line argument. For example, "php myScript.php", assuming "php" is the command to invoke the CLI program.
Be aware that if your PHP script was written for the Web CGI interface, it may not execute properly in command line environment.

14. Suppose your ZEND engine supports the mode Then how can u configure your php ZEND engine to support mode ?

If you change the line: short_open_tag = off in php.ini file. Then your php ZEND engine support only mode.

15. Shopping cart online validation i.e. how can we configure the paypals?

16. What is meant by nl2br()?

nl2br — Inserts HTML line breaks before all newlines in a string string nl2br (string); Returns string with ” inserted before all newlines. For example: echo nl2br("god bless\n you") will output "god bless \n you" to your browser.

17. Draw the architecture of ZEND engine?

18. What are the current versions of apache, php, and mysql?

PHP: php5.1.2
MySQL: MySQL 5.1
Apache: Apache 2.1

19. What are the reasons for selecting lamp (Linux, apache, mysql, php) instead of combination of other software programs, servers and operating systems?

All of those are open source resource. Security of linux is very very more than windows. Apache is a better server that IIS both in functionality and security. Mysql is world most popular open source database. Php is more faster that asp or any other scripting language.

20. How can we encrypt and decrypt a data present in a mysql table using mysql?

AES_ENCRYPT () and AES_DECRYPT ()

21. How can we encrypt the username and password using php?

You can encrypt a password with the following Mysql>SET PASSWORD=PASSWORD("Password");
We can encode data using base64_encode($string) and can decode using base64_decode($string);

22. What are the features and advantages of OBJECT ORIENTED PROGRAMMING?

One of the main advantages of OO programming is its ease of modification; objects can easily be modified and added to a system there by reducing maintenance costs. OO programming is also considered to be better at modeling the real world than is procedural programming. It allows for more complicated and flexible interactions. OO systems are also easier for non-technical personnel to understand and easier for them to participate in the maintenance and enhancement of a system because it appeals to natural human cognition patterns.
For some systems, an OO approach can speed development time since many objects are standard across systems and can be reused. Components that manage dates, shipping, shopping carts, etc. can be purchased and easily modified for a specific system.

23. What are the differences between PROCEDURE ORIENTED LANGUAGES and OBJECT ORIENTED LANGUAGES?

Traditional programming has the following characteristics:

Functions are written sequentially, so that a change in programming can affect any code that follows it.
If a function is used multiple times in a system (i.e., a piece of code that manages the date), it is often simply cut and pasted into each program (i.e., a change log, order function, fulfillment system, etc). If a date change is needed (i.e., Y2K when the code needed to be changed to handle four numerical digits instead of two), all these pieces of code must be found, modified, and tested.
Code (sequences of computer instructions) and data (information on which the instructions operates on) are kept separate. Multiple sets of code can access and modify one set of data. One set of code may rely on data in multiple places. Multiple sets of code and data are required to work together. Changes made to any of the code sets and data sets can cause problems through out the system.

Object-Oriented programming takes a radically different approach:

Code and data are merged into one indivisible item – an object (the term "component" has also been used to describe an object.) An object is an abstraction of a set of real-world things (for example, an object may be created around "date") The object would contain all information and functionality for that thing (A date
object it may contain labels like January, February, Tuesday, Wednesday. It may contain functionality that manages leap years, determines if it is a business day or a holiday, etc., See Fig. 1). Ideally, information about a particular thing should reside in only one place in a system. The information within an object is encapsulated (or hidden) from the rest of the system.
A system is composed of multiple objects (i.e., date function, reports, order processing, etc., See Fig 2). When one object needs information from another object, a request is sent asking for specific information. (for example, a report object may need to know what today’s date is and will send a request to the date object) These requests are called messages and each object has an interface that manages messages.
OO programming languages include features such as "class", "instance", "inheritance", and "polymorphism" that increase the power and flexibility of an object.

24. What is the use of friend function?

Friend functions
Sometimes a function is best shared among a number of different classes. Such functions can be declared either as member functions of one class or as global functions. In either case they can be set to be friends of other classes, by using a friend specifier in the class that is admitting them. Such functions can use all attributes of the class whichnames them as a friend, as if they were themselves members of that class.
A friend declaration is essentially a prototype for a member function, but instead of requiring an implementation with the name of that class attached by the double colon syntax, a global function or member function of another class provides the match.

class mylinkage
{
private:
mylinkage * prev;
mylinkage * next;

protected:
friend void set_prev(mylinkage* L, mylinkage* N);
void set_next(mylinkage* L);

public:
mylinkage * succ();
mylinkage * pred();
mylinkage();
};

void mylinkage::set_next(mylinkage* L) { next = L; }

void set_prev(mylinkage * L, mylinkage * N ) { N->prev = L; }
Friends in other classes

It is possible to specify a member function of another class as a friend as follows:

class C
{
friend int B::f1();
};
class B
{
int f1();
};

It is also possible to specify all the functions in another class as friends, by specifying the entire class as a friend.

class A
{
friend class B;
};

Friend functions allow binary operators to be defined which combine private data in a pair of objects. This is particularly powerful when using the operator overloading features of C++. We will return to it when we look at overloading.

25. What are the differences between public, private, protected, static, transient, final and volatile?
element Class Interface
Data field Method Constructor
modifier top level nested top level nested
(outer) (inner) (outer) (inner)
final yes yes no yes yes no no
private yes yes yes no yes no yes
protected yes yes yes no yes no yes
public yes yes yes yes yes yes yes
static yes yes no no yes no yes
transient yes no no no no no no
volatile yes no no no no no no

  1. What is the functionality of the function htmlentities?

Answer: htmlentities — Convert all applicable characters to HTML entities
This function is identical to htmlspecialchars() in all ways, except with htmlentities(), all characters which have HTML character entity equivalents are translated into these entities.


33. What is meant by urlencode and urldocode?

urlencode() returns the URL encoded version of the given string. URL coding converts special characters into % signs followed by two hex digits. For example: urlencode("10.00%") will return "10%2E00%25?. URL encoded strings are safe to be used as part of URLs.
urldecode() returns the URL decoded version of the given string.

70. What are the advantages and disadvantages of CASCADE STYLE SHEETS?

External Style Sheets

Advantages

Can control styles for multiple documents at once
Classes can be created for use on multiple HTML element types in many documents
Selector and grouping methods can be used to apply styles under complex contexts

Disadvantages

An extra download is required to import style information for each document
The rendering of the document may be delayed until the external style sheet is loaded
Becomes slightly unwieldy for small quantities of style definitions

Embedded Style Sheets

Advantages

Classes can be created for use on multiple tag types in the document
Selector and grouping methods can be used to apply styles under complex contexts
No additional downloads necessary to receive style information

Disadvantages

This method can not control styles for multiple documents at once

Inline Styles

Advantages

Useful for small quantities of style definitions
Can override other style specification methods at the local level so only exceptions need to be listed in conjunction with other style methods

Disadvantages

Does not distance style information from content (a main goal of SGML/HTML)
Can not control styles for multiple documents at once
Author can not create or control classes of elements to control multiple element types within the document
Selector grouping methods can not be used to create complex element addressing scenarios

69. How many ways we can we find the current date using mysql?

SELECT CURDATE();
CURRENT_DATE() = CURDATE()
for time use
SELECT CURTIME();
CURRENT_TIME() = CURTIME()

25. What are the differences between public, private, protected, static, transient, final and volatile?

Public: Public declared items can be accessed everywhere.
Protected: Protected limits access to inherited and parent classes (and to the class that defines the item).
Private: Private limits visibility only to the class that defines the item.
Static: A static variable exists only in a local function scope, but it does not lose its value when program execution leaves this scope.
Final: Final keyword prevents child classes from overriding a method by prefixing the definition with final. If the class itself is being defined final then it cannot be extended.

What's PHP

The PHP Hypertext Preprocessor is a programming language that allows web developers to create dynamic content that interacts with databases. PHP is basically used for developing web based software applications.

What Is a Session?

A session is a logical object created by the PHP engine to allow you to preserve data across subsequent HTTP requests.

There is only one session object available to your PHP scripts at any time. Data saved to the session by a script can be retrieved by the same script or another script when requested from the same visitor.

Sessions are commonly used to store temporary data to allow multiple PHP pages to offer a complete functional transaction for the same visitor.

How can we know the number of days between two given dates using PHP?

Simple arithmetic:

$date1 = date('Y-m-d');
$date2 = '2006-07-01';
$days = (strtotime() - strtotime()) / (60 * 60 * 24);
echo "Number of days since '2006-07-01': $days";

How can we repair a MySQL table?

The syntex for repairing a mysql table is:

REPAIR TABLE tablename
REPAIR TABLE tablename QUICK
REPAIR TABLE tablename EXTENDED

This command will repair the table specified.
If QUICK is given, MySQL will do a repair of only the index tree.
If EXTENDED is given, it will create index row by row.

What is the difference between $message and $$message?

Anwser 1:
$message is a simple variable whereas $$message is a reference variable. Example:
$user = 'bob'

is equivalent to

$holder = 'user';
$$holder = 'bob';


Anwser 2:
They are both variables. But $message is a variable with a fixed name. $$message is a variable who's name is stored in $message. For example, if $message contains "var", $$message is the same as $var.

What Is a Persistent Cookie?

A persistent cookie is a cookie which is stored in a cookie file permanently on the browser's computer. By default, cookies are created as temporary cookies which stored only in the browser's memory. When the browser is closed, temporary cookies will be erased. You should decide when to use temporary cookies and when to use persistent cookies based on their differences:

  • Temporary cookies can not be used for tracking long-term information.

  • Persistent cookies can be used for tracking long-term information.

  • Temporary cookies are safer because no programs other than the browser can access them.

  • Persistent cookies are less secure because users can open cookie files see the cookie values.

What does a special set of tags <?= and ?> do in PHP?

The output is displayed directly to the browser.

How To Write the FORM Tag Correctly for Uploading Files?

When users clicks the submit button, files specified in the <INPUT TYPE=FILE...> will be transferred from the browser to the Web server. This transferring (uploading) process is controlled by a properly written <FORM...> tag as:

<FORM ACTION=receiving.php METHOD=post ENCTYPE=multipart/form-data>

Note that you must specify METHOD as "post" and ENCTYPE as "multipart/form-data" in order for the uploading process to work. The following PHP code, called logo_upload.php, shows you a complete FORM tag for file uploading:

<?php   print("<html><form action=processing_uploaded_files.php"     ." method=post enctype=multipart/form-data>\n");   print("Please submit an image file a Web site logo for"     ." fyicenter.com:<br>\n");   print("<input type=file name=fyicenter_logo><br>\n");   print("<input type=submit>\n");   print("</form></html>\n"); ?>

What are the differences between require and include, include_once?

Anwser 1:
require_once() and include_once() are both the functions to include and evaluate the specified file only once. If the specified file is included previous to the present call occurrence, it will not be done again.

But require() and include() will do it as many times they are asked to do.

Anwser 2:
The include_once() statement includes and evaluates the specified file during the execution of the script. This is a behavior similar to the include() statement, with the only difference being that if the code from a file has already been included, it will not be included again. The major difference between include() and require() is that in failure include() produces a warning message whereas require() produces a fatal errors.
Anwser 3:
All three are used to an include file into the current page.
If the file is not present, require(), calls a fatal error, while in include() does not.
The include_once() statement includes and evaluates the specified file during the execution of the script. This is a behavior similar to the include() statement, with the only difference being that if the code from a file has already been included, it will not be included again. It des not call a fatal error if file not exists. require_once() does the same as include_once(), but it calls a fatal error if file not exists.
Anwser 4:
File will not be included more than once. If we want to include a file once only and further calling of the file will be ignored then we have to use the PHP function include_once(). This will prevent problems with function redefinitions, variable value reassignments, etc.

What is meant by urlencode and urldecode?

Anwser 1:
urlencode() returns the URL encoded version of the given string. URL coding converts special characters into % signs followed by two hex digits. For example: urlencode("10.00%") will return "10%2E00%25". URL encoded strings are safe to be used as part of URLs.
urldecode() returns the URL decoded version of the given string. Anwser 2:
string urlencode(str) - Returns the URL encoded version of the input string. String values to be used in URL query string need to be URL encoded. In the URL encoded version:

Alphanumeric characters are maintained as is.
Space characters are converted to "+" characters.
Other non-alphanumeric characters are converted "%" followed by two hex digits representing the converted character.
string urldecode(str) - Returns the original string of the input URL encoded string.
For example:
$discount ="10.00%";
$url = "http://domain.com/submit.php?disc=".urlencode($discount);
echo $url;
You will get "http://domain.com/submit.php?disc=10%2E00%25".

How To Get the Uploaded File Information in the Receiving Script?

Once the Web server received the uploaded file, it will call the PHP script specified in the form action attribute to process them. This receiving PHP script can get the uploaded file information through the predefined array called $_FILES. Uploaded file information is organized in $_FILES as a two-dimensional array as:

  • $_FILES[$fieldName]['name'] - The Original file name on the browser system.

  • $_FILES[$fieldName]['type'] - The file type determined by the browser.

  • $_FILES[$fieldName]['size'] - The Number of bytes of the file content.

  • $_FILES[$fieldName]['tmp_name'] - The temporary filename of the file in which the uploaded file was stored on the server.

  • $_FILES[$fieldName]['error'] - The error code associated with this file upload.

The $fieldName is the name used in the <INPUT TYPE=FILE, NAME=fieldName>.

What is the difference between mysql_fetch_object and mysql_fetch_array?

MySQL fetch object will collect first single matching record where mysql_fetch_array will collect all matching records from the table in an array

How can I execute a PHP script using command line?

Just run the PHP CLI (Command Line Interface) program and provide the PHP script file name as the command line argument. For example, "php myScript.php", assuming "php" is the command to invoke the CLI program.
Be aware that if your PHP script was written for the Web CGI interface, it may not execute properly in command line environment.

I am trying to assign a variable the value of 0123, but it keeps coming up with a different number, what’s the problem?

PHP Interpreter treats numbers beginning with 0 as octal. Look at the similar PHP interview questions for more numeric problems.

Would I use print "$a dollars" or "{$a} dollars" to print out the amount of dollars in this example?

In this example it wouldn’t matter, since the variable is all by itself, but if you were to print something like "{$a},000,000 mln dollars", then you definitely need to use the braces.

What are the different tables present in MySQL? Which type of table is generated when we are creating a table in the following syntax: create table employee(eno int(2),ename varchar(10))?

Total 5 types of tables we can create
1. MyISAM
2. Heap
3. Merge
4. INNO DB
5. ISAM
MyISAM is the default storage engine as of MySQL 3.23. When you fire the above create query MySQL will create a MyISAM table.

How To Create a Table?

If you want to create a table, you can run the CREATE TABLE statement as shown in the following sample script:

<?php
include "mysql_connection.php";

$sql = "CREATE TABLE fyi_links ("
. " id INTEGER NOT NULL"
. ", url VARCHAR(80) NOT NULL"
. ", notes VARCHAR(1024)"
. ", counts INTEGER"
. ", time TIMESTAMP DEFAULT sysdate()"
. ")";
if (mysql_query($sql, $con)) {
print("Table fyi_links created.\n");
} else {
print("Table creation failed.\n");
}

mysql_close($con);
?>
Remember that mysql_query() returns TRUE/FALSE on CREATE statements. If you run this script, you will get something like this:
Table fyi_links created.

How can we encrypt the username and password using PHP?

Answer1
You can encrypt a password with the following Mysql>SET PASSWORD=PASSWORD("Password"); Answer2
You can use the MySQL PASSWORD() function to encrypt username and password. For example,
INSERT into user (password, ...) VALUES (PASSWORD($password”)), ...);

How do you pass a variable by value?

Just like in C++, put an ampersand in front of it, like $a = &$b

WHAT IS THE FUNCTIONALITY OF THE FUNCTIONS STRSTR() AND STRISTR()?

string strstr ( string haystack, string needle ) returns part of haystack string from the first occurrence of needle to the end of haystack. This function is case-sensitive.
stristr() is idential to strstr() except that it is case insensitive.

When are you supposed to use endif to end the conditional statement?

When the original if was followed by : and then the code block without braces.

How can we send mail using JavaScript?

No. There is no way to send emails directly using JavaScript.

But you can use JavaScript to execute a client side email program send the email using the "mailto" code. Here is an example:

function myfunction(form)
{
tdata=document.myform.tbox1.value;
location="mailto:mailid@domain.com?subject=...";
return true;
}

What is the functionality of the function strstr and stristr?

strstr() returns part of a given string from the first occurrence of a given substring to the end of the string. For example: strstr("user@example.com","@") will return "@example.com".
stristr() is idential to strstr() except that it is case insensitive.

What is the difference between ereg_replace() and eregi_replace()?

eregi_replace() function is identical to ereg_replace() except that it ignores case distinction when matching alphabetic characters.

How do I find out the number of parameters passed into function9. ?

func_num_args() function returns the number of parameters passed in.

What is the purpose of the following files having extensions: frm, myd, and myi? What these files contain?

In MySQL, the default table type is MyISAM.
Each MyISAM table is stored on disk in three files. The files have names that begin with the table name and have an extension to indicate the file type.
The '.frm' file stores the table definition.
The data file has a '.MYD' (MYData) extension.
The index file has a '.MYI' (MYIndex) extension,

If the variable $a is equal to 5 and variable $b is equal to character a, what’s the value of $$b?

100, it’s a reference to existing variable.

Write a query for the following question

The table tbl_sites contains the following data:
-----------------------------------------------------
Userid sitename country
------------------------------------------------------
1 sureshbabu indian
2 PHPprogrammer andhra
3 PHP.net usa
4 PHPtalk.com germany
5 MySQL.com usa
6 sureshbabu canada
7 PHPbuddy.com pakistan
8. PHPtalk.com austria
9. PHPfreaks.com sourthafrica
10. PHPsupport.net russia
11. sureshbabu australia
12. sureshbabu nepal
13. PHPtalk.com italy
Write a select query that will be displayed the duplicated site name and how many times it is duplicated? …

SELECT sitename, COUNT(*) AS NumOccurrences
FROM tbl_sites
GROUP BY sitename HAVING COUNT(*) > 1

How To Protect Special Characters in Query String?

If you want to include special characters like spaces in the query string, you need to protect them by applying the urlencode() translation function. The script below shows how to use urlencode():

<?php
print("<html>");
print("<p>Please click the links below"
." to submit comments about FYICenter.com:</p>");
$comment = 'I want to say: "It\'s a good site! :->"';
$comment = urlencode($comment);
print("<p>"
."<a href=\"processing_forms.php?name=Guest&comment=$comment\">"
."It's an excellent site!</a></p>");
$comment = 'This visitor said: "It\'s an average site! :-("';
$comment = urlencode($comment);
print("<p>"
.'<a href="processing_forms.php?'.$comment.'">'
."It's an average site.</a></p>");
print("</html>");
?>

Are objects passed by value or by reference?

Everything is passed by value.

What are the differences between DROP a table and TRUNCATE a table?


 
Privacy Policy | About Us