PHP Interview Questions -6

PHP Interview Questions -6

1. Are the PHP variable names case sensitive?

Yes. The php variable names cases sensitive.

2. Are the PHP function names case sensitive?

No, Its not case sensitve functions.

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

Here’s a list of some of the more important new features:

Extended API module.

Generalized build process under Unix.

Generic web server interface that also supports multi-threaded web servers

Improved syntax highlighter.

Native HTTP session support.

Output buffering support.

More powerful configuration system.

Reference counting.

4. Can I use php with cron on unix systems?

Yes that’s possible, how you do it depends a little on your installation.

1. If you have php installed as CGI on your system you can ex. simply do:

0 10 * * * /path/to/php /path/to/script > /dev/null.

2. If you dont have php installed as CGI you can use a unix console program for

fetching URLs, we reccommend lynx or wget.

Example of using lynx:

0 10 * * * lynx -dump > /dev/null

Example of using wget:

0 10 * * * wget > /dev/null..

5. What is caching?

“Meta tags are easy to use, but aren’t very effective. That’s because they’re usually only honored by browser caches (which actually read the HTML), not proxy caches (which almost never read the HTML in the document).”

If a page is changed “nearly every day”, it will hardly be a problem in practical terms.

And in any case, it’s something to be handled at the server level, by making the server send some useful expiration information, using whatever needs to be done on a specific

server. Telling that a page expired twenty years ago is hardly a good idea if you can expect its lifetime to be a day or more, or at least several hours. Defeating proxy caching brutally wouldn’t be a good idea (and meta tags won’t do that, so the errors in a sense cancel out each other, so to say This has to be at the beginning of the file, with nothing before (e.g. no blank). This is a brute force variation, some adjustments are useful. (Server supporting PHP is recommended)Meta-tags wont work with proxies.

Proxies don’t work on the ‘HTML-layer’ but HTTP. Things depend on proxy settings also.”The Pragma header is generally ineffective because its meaning is not standardized and few caches honor it. Using <meta http-equiv=…> elements in HTML documents is also generally ineffective; some browsers may honor such markup, but other caches ignore it completely.” – Web Design Group That’s because the no-cache pragma is supposed to be part of a HTTP *request*. And *this* has been standardized since way back.

6. What is PHP?

PHP stands for: Hyper Text Preprocessor.

PHP is a server-side scripting language, like ASP. PHP scripts are executedon the server.PHPsupportsmany.databases (MySQL, Informix, Oracle, Sybase, Solid, PostgreSQL, GenericODBC, etc.PHP is an open source software (OSS).

7.How to install PHP on Apache?

You need to add the following lines to httpd.conf (If you’re using Apache for Win32).

ScriptAlias /php/” c:/path-to-php-dir/”

AddType application/x-httpd-php .php

Action application/x-httpd-php “/php/php.exe”

Then restart Apache and it should interpret php files correctly.

8.What is a PHP File?

PHP files may contain text, HTML tags and scripts.

PHP files are returned to the browser as plain HTML.

PHP files have a file extension of “.php”, “.php3?, or “.phtml”.

9. Why PHP?

Ans: PHP runs on different platforms (Windows, Linux, Unix, etc.).
PHP is compatible with almost all servers used today (Apache, IIS, etc.).
PHP is FREE to download from the official PHP resource:
PHP is easy to learn and runs efficiently on the server side.

10. How do I install PHP as a CGI?

What you need to do is to run:

./configure –without-apache –without-apxs –with-other-options.

It will tell you that as you are building it without Apache support, it is building it as a CGI binary. Then do make; make install and it should then be installed (/usr/local/bin/php by default).

11. Are the PHP language constructs (for, return, print…) case sensitive?


12. How do I install PHP as a CGI?

What you need to do is to run:

./configure –without-apache –without-apxs –with-other-options.

It will tell you that as you are building it without Apache support, it is building it as a CGI binary. Then do make; make install and it should then be installed (/usr/local/bin/php by default).

13.How does PHP compare to ASP?

Microsoft’s Active Server Pages (ASP) comes with VBScript and JScript scripting languages, but you can also install scripting engines for Perl, REXX, and Python, whereas PHP will only ever be PHP. The most commonly used flavour of ASP is that written in VBScript. VBScript is a subset of Visual Basic, a standalone compiled language. This very fact makes ASP marketable to VB programmers wishing to build applications for the Internet. However, as a script language VBScript could never compete with its big brother, Visual Basic, only supplement it. In making this point, VBScript is not solely a glue to hold Visual Basic together with an Internet front-end, but that’s really what it does best.

ASP can prove to be very memory hungry beasts and regular calls on system objects, such as Active Data Objects (ADO) for working with databases can make for slow applications on heavily loaded machines. VBScript lacks many important features, which

can be added through Component Object Model (COM) objects. An example of this, is when trying to send e-mail using VBScript, although the objects are available, they can be costly and more time consuming than the PHP equivalent (mail function). PHP can also be ‘added to’ with additional functionality being quite platform dependant. COM functions are supported by the Windows version of PHP and many libraries are available for *nix versions.

VBScript interpreters are available for various Unix based systems and Windows.

However, finding a COM object that will send e-mail on a Unix system is nearly impossible and very expensive. This leads to the conclusion that ASP is only really at home in a Microsoft environment. It has its fair share of security flaws, but when used by professional VB programmers, I have seen ASP provide some immensely powerful interfaces. PHP on the other hand can be seen to provide the best results in the form of stability and speed on Unix based systems.

PHP is Open Source software, which is great as it means that code, manual, updates and support are all free. Although the ASP script engine comes included with IIS and PWS and minimal support is available free, running Microsoft operating systems at a commercial level is always going to be costly.

A lack of high profile sites using PHP makes it a bit harder to prove it’s robustness and gain acceptance from non-programming colleagues (e.g. management), but for a programmer the portability and stability of PHP is beneficial.

14. What is use of header() function in php ? What the Limitation of HEADER()?

In PHP Important to notice the Limitation of HEADER() function is that header() must be called before any actual output is send. Means must use header function before HTML or any echo stateament
There are Number of Use of HEADER() function in php like below
1> The header() function use to sends a raw HTTP header to a client.
2> We can use herder() function for redirection of pages.
3> Use for refresh the page on given time interval automatically.

15. How can we extract string "" from a string "" using regular expression of PHP? More on Reg can you explain

We can extract string "" using this
echo $matches[1];
More On regular expression interview question with very nice examples in

16. How do you connet mysql database with PHP ?

We can connect Mysql Database with PHP using both Procedural and Object oriented style like below
$link = mysqli_connect("localhost", "username", "password", "dbofpcds");

$mysqli = new mysqli("localhost", "username", "password", "dbname");
and in old type of connectivity were
$link = mysql_connect("localhost", "username", "password");
Answer in Details

17.What are the differences between Get and post methods.
There are some defference between GET and POST method
1. GET Method have some limit like only 2Kb data able to send for request But in POST method unlimited data can we send 2. when we use GET method requested data show in url but
Not in POST method so POST method is good for send sensetive request
18. 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.

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

14    In php.ini file:
to make PHP support
20. Shopping cart online validation i.e. how can we configure Paypal,etc.?

Nothing more we have to do only redirect to the payPal url after submit all information needed by paypal like amount,adresss etc.
21.     What is meant by nl2br()?

Inserts HTML line breaks (<BR />) before all newlines in a string.
22. What is htaccess? Why do we use this and Where?

.htaccess files are configuration files of Apache Server which provide
a way to make configuration changes on a per-directory basis. A file, containing one or more configuration directives, is placed in a particular document directory, and the directives apply to that directory, and all subdirectories thereof.

23. How we get IP address of client, previous reference page etc ?

24. What are the reasons for selecting lamp (Linux, apache, MySQL,PHP) instead of commbination 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.
25. How can we encrypt and decrypt a data present in a MySQL table using MySQL?

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

The functions in this section perform encryption and decryption, and
compression and uncompression:
encryption    decryption
ENCRYPT()    Not available
MD5()    Not available
OLD_PASSWORD()    Not available
PASSWORD()    Not available
SHA() or SHA1()    Not available
Not available    UNCOMPRESSED_LENGTH()
27. 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

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

$second = date("s");
29. How can we convert the time zones using PHP?

For convert the time zones using PHP we have to first set time zone By using PHP function date_default_timezone_set() If we want to set time zone of 'Europe/London' we have to call this funtion as date_default_timezone_set('Europe/London') so Now generate the timestamp for that particular timezone, on Sept 1st, 2012 at 8 am $pcds = mktime(8, 0, 0, 9, 1, 2012); Now set the other timezone like US/Eastern date_default_timezone_set('US/Eastern'); date(DATE_RFC1123, $pcds) date(DATE_RFC1123, $pcds)
Output the date in a standard format (RFC1123)
30. 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. It is encoded the same way that the posted data from a WWW form is encoded, that is the same way as in application/x-www-form-urlencoded media type.
urldecode decodes any %##
encoding in the given string.
31. What is the difference between the functions unlink and unset?

unlink() deletes the given file from the file system.
unset() makes a variable undefined.
32. How can we register the variables into a session?

$_SESSION['name'] = "sonia";

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

To know the Image type use exif_imagetype () function
To know the Image size use getimagesize () function
To know the image width use imagesx () function
To know the image height use imagesy() function t
34. How can we get the browser properties using PHP?

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

By default the maximum size is 2MB. and we can change the following setup at  php.iniupload_max_filesize = 2M
36. How can we increase the execution time of a PHP script?

by changing the following setup at php.inimax_execution_time = 30
; Maximum execution time of each script, in seconds
37. 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
RESTORE TABLE tbl_name[,tbl_name…] FROM '/path/to/backup/directory'mysqldump: Dumping Table Structure and DataUtility 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!

38. 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.
39. 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.
40. 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.
41. How can we repair a MySQL table?

The syntex for repairing a MySQL table is REPAIR TABLENAME, [TABLENAME, ], [Quick],[Extended]
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
42. 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.
43. 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    Maximum Length
Database    64
Table    64
Column    64
Index    64
Alias    255
There are some restrictions on the characters that may appear in identifiers:

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

45. what are magic methods?

Magic methods are the members functions that is available to all the instance of class Magic methods always starts with "__". Eg. __construct All magic methods needs to be declared as public To use magic method they should be defined within the class or program scope Various Magic Methods used in PHP 5 are: __construct() __destruct() __set() __get() __call() __toString() __sleep() __wakeup() __isset() __unset() __autoload() __clone()

46. what is magic quotes?

Magic Quotes is a process that automagically escapes ncoming data to the PHP script. It’s preferred to code with magic quotes off and to instead escape the data at runtime, as needed. This feature has been DEPRECATED as of PHP 5.3.0 and REMOVED as of PHP 6.0.0. Relying on this feature is highly discouraged.

47. what is cross site scripting? SQL injection?

Cross-site scripting (XSS) is a type of computer security vulnerability typically found in web applications which allow code injection by malicious web users into the web pages viewed by other users. Examples of such code include HTML code and client-side scripts. SQL injection is a code injection technique that exploits a security vulnerability occurring in the database layer of an application. The vulnerability is present when user input is either incorrectly filtered for string literal escape characters embedded in SQL statements or user input is not strongly typed and thereby unexpectedly executed

48.what is URL rewriting?

Using URL rewriting we can convert dynamic URl to static URL Static URLs are known to be better than Dynamic URLs because of a number of reasons 1. Static URLs typically Rank better in Search Engines. 2. Search Engines are known to index the content of dynamic pages a lot slower compared to static pages. 3. Static URLs are always more friendlier looking to the End Users. along with this we can use URL rewriting in adding variables [cookies] to the URL to handle the sessions.
49. what is the major php security hole? how to avoid?

1. Never include, require, or otherwise open a file with a filename based on user input, without thoroughly checking it first.
2. Be careful with eval() Placing user-inputted values into the eval() function can be extremely dangerous. You essentially give the malicious user the ability to execute any command he or she wishes!
3. Be careful when using register_globals = ON It was originally designed to make programming in PHP easier (and that it did), but misuse of it often led to security holes
4. Never run unescaped queries
5. For protected areas, use sessions or validate the login every time.
6. If you don’t want the file contents to be seen, give the file a .php extension.
50.whether PHP supports Microsoft SQL server ?

The SQL Server Driver for PHP v1.0 is designed to enable reliable, scalable integration with SQL Server for PHP applications deployed on the Windows platform. The Driver for PHP is a PHP 5 extension that allows the reading and writing of SQL Server data from within PHP scripts. using MSSQL or ODBC modules we can access Microsoft SQL server.

51. How many types of Inheritances used in PHP and how we achieve it

As far PHP concern it only support single Inheritance in scripting.
we can also use interface to achieve multiple inheritance.
52. PHP how to know user has read the email?

Using Disposition-Notification-To: in mailheader we can get read receipt.
Add the possibility to define a read receipt when sending an email.
It’s quite straightforward, just edit email.php, and add this at vars definitions:
var $readReceipt = null;
And then, at ‘createHeader’ function add:
if (!empty($this->readReceipt)) {
$this->__header .= ‘Disposition-Notification-To: ‘ . $this->__formatAddress($this->readReceipt) . $this->_newLine;
53. What are default session time and path?

default session time in PHP is 1440 seconds or 24 minutes
Default session save path id temporary folder /tmp

54. how to track user logged out or not? when user is idle ?

By checking the session variable exist or not while loading th page. As the session will exist longer as till browser closes. The default behaviour for sessions is to keep a session open indefinitely and only to expire a session when the browser is closed. This behaviour can be changed in the php.ini file by altering the line session.cookie_lifetime = 0 to a value in seconds. If you wanted the session to finish in 5 minutes you would set this to session.cookie_lifetime = 300 and restart your httpd server.
55. how to track no of user logged in ?
whenever a user logs in track the IP, userID etc..and store it in a DB with a active flag while log out or sesion expire make it inactive. At any time by counting the no: of active records we can get the no: of visitors.
56. in PHP for pdf which library used?

The PDF functions in PHP can create PDF files using the PDFlib library With version 6, PDFlib offers an object-oriented API for PHP 5 in addition to the function-oriented API for PHP 4. There is also the » Panda module. FPDF is a PHP class which allows to generate PDF files with pure PHP, that is to say without using the PDFlib library. F from FPDF stands for Free: you may use it for any kind of usage and modify it to suit your needs. FPDF requires no extension (except zlib to activate compression and GD for GIF support) and works with PHP4 and PHP5.
57. for image work which library?

we will need to compile PHP with the GD library of image functions for this to work. GD and PHP may also require other libraries, depending on which image formats you want to work with.
58. what is design pattern? explain all including singleton pattern?
A design pattern is a general reusable solution to a commonly occurring problem in software design.The Singleton design pattern allows many parts of a program to share a single resource without having to work out the details of the sharing themselves.

59. what is MVC? why its been used?

Model-view-controller (MVC) is an architectural pattern used in software engineering. Successful use of the pattern isolates business logic from user interface considerations, resulting in an application where it is easier to modify either the visual appearance of the application or the underlying business rules without affecting the other. In MVC, the model represents the information (the data) of the application; the view corresponds to elements of the user interface such as text, checkbox items, and so forth; and the controller manages the communication of data and the business rules used to manipulate the data to and from the model. WHY ITS NEEDED IS 1 Modular separation of function 2 Easier to maintain 3 View-Controller separation means:
A — Tweaking design (HTML) without altering code B — Web design staff can modify UI without understanding code
60. what is framework? how it works? what is advantage?

In general, a framework is a real or conceptual structure intended to serve as a support or guide for the building of something that expands the structure into something useful. Advantages : Consistent Programming Model Direct Support for Security Simplified Development Efforts Easy Application Deployment and Maintenance
61. what is CURL?

CURL means Client URL Library
curl is a command line tool for transferring files with URL syntax, supporting FTP, FTPS, HTTP, HTTPS, SCP, SFTP, TFTP, TELNET, DICT, LDAP, LDAPS and FILE. curl supports SSL certificates, HTTP POST, HTTP PUT, FTP uploading, HTTP form based upload, proxies, cookies, user+password authentication (Basic, Digest, NTLM, Negotiate, kerberos…), file transfer resume, proxy tunneling and a busload of other useful tricks.
CURL allows you to connect and communicate to many different types of servers with many different types of protocols. libcurl currently supports the http, https, ftp, gopher, telnet, dict, file, and ldap protocols. libcurl also supports HTTPS certificates, HTTP POST, HTTP PUT, FTP uploading (this can also be done with PHP’s ftp extension), HTTP form based upload, proxies, cookies, and user+password authentication.
62. what is PDO ?
The PDO ( PHP Data Objects ) extension defines a lightweight, consistent interface for accessing databases in PHP. if you are using the PDO API, you could switch the database server you used, from say PgSQL to MySQL, and only need to make minor changes to your PHP code.
While PDO has its advantages, such as a clean, simple, portable API but its main disadvantage is that it doesn't allow you to use all of the advanced features that are available in the latest versions of MySQL server. For example, PDO does not allow you to use MySQL's support for Multiple Statements.
Just need to use below code for connect mysql using PDO
try {
$dbh = new PDO("mysql:host=$hostname;dbname=databasename", $username, $password);
$sql = "SELECT * FROM employee";
foreach ($dbh->query($sql) as $row)
print $row['employee_name'] .' - '. $row['employee_age'] ;
catch(PDOException $e)
echo $e->getMessage();

63. What is PHP's mysqli Extension?
The mysqli extension, or as it is sometimes known, the MySQL improved extension, was developed to take advantage of new features found in MySQL systems versions 4.1.3 and newer. The mysqli extension is included with PHP versions 5 and later.
The mysqli extension has a number of benefits, the key enhancements over the mysql extension being:
=>Object-oriented interface
=>Support for Prepared Statements
=>Support for Multiple Statements
=>Support for Transactions
=>Enhanced debugging capabilities
=>Embedded server support

64. What type of inheritance that PHP supports?

In PHP an extended class is always dependent on a single base class,
that is, multiple inheritance is not supported. Classes are extended
using the keyword 'extends'.
65. What is the difference between Primary Key and Unique key?

Primary Key: A column in a table whose values uniquely identify the rows in the table. A primary key value cannot be NULL.
Unique Key: Unique Keys are used to uniquely identify each row in the table. There can be one and only one row for each unique key value. So
NULL can be a unique key.There can be only one primary key for a table but there can be more than one unique for a table.
66. what is garbage collection? default time ? refresh time?

Garbage Collection is an automated part of PHP , If the Garbage Collection process runs, it then analyzes any files in the /tmp for any session files that have not been accessed in a certain amount of time and physically deletes them. Garbage Collection process only runs in the default session save directory, which is /tmp. If you opt to save your sessions in a different directory, the Garbage Collection process will ignore it. the Garbage Collection process does not differentiate between which sessions belong to whom when run. This is especially important note on shared web servers. If the process is run, it deletes ALL files that have not been accessed in the directory. There are 3 PHP.ini variables, which deal with the garbage collector: PHP ini value name default session.gc_maxlifetime 1440 seconds or 24 minutes session.gc_probability 1 session.gc_divisor 100
67. What are the advantages/disadvantages of MySQL and PHP?

Both of them are open source software (so free of cost), support cross platform. php is faster then ASP and JSP.
68. What is the difference between GROUP BY and ORDER BY in Sql?

ORDER BY [col1],[col2],…,[coln]; Tels DBMS according to what columns it should sort the result. If two rows will hawe the same value in col1 it will try to sort them according to col2 and so on.GROUP BY [col1],[col2],…,[coln]; Tels DBMS to group results with same value of column col1. You can use COUNT(col1), SUM(col1), AVG(col1) with it, if you want to count all items in group, sum all values or view average
69. What is the difference between char and varchar data types?

Set char to occupy n bytes and it will take n bytes even if u r storing a value of n-m bytes Set varchar to occupy n bytes and it will take only the required space and will not use the n bytes eg. name char(15) will waste 10 bytes if we store 'romharshan', if each char takes a byte eg. name varchar(15) will just use 5 bytes if we store 'romharshan', if each char takes a byte. rest 10 bytes will be free.
70.What is the functionality of md5 function in PHP?

Calculate the md5 hash of a string. The hash is a 32-character hexadecimal number. I use it to generate keys which I use to identify users etc. If I add random no techniques to it the md5 generated now will be totally different for the same string I am using.
71. How can I load data from a text file into a table?

you can use LOAD DATA INFILE file_name; syntax to load data from a text file. but you have to make sure thata) data is delimited b) columns and data matched correctly
72. How can we know the number of days between two given dates using MySQL?

SELECT DATEDIFF("2007-03-07","2005-01-01");
72. How can we know the number of days between two given dates using PHP?

$date1 = date("Y-m-d");
$date2 = "2006-08-15";
$days = (strtotime($date1) - strtotime($date2)) / (60 * 60 * 24);
73. How we load all classes that placed in different directory in one PHP File , means how to do auto load classes

by using spl_autoload_register('autoloader::funtion');

Like below

class autoloader


public static function moduleautoloader($class)


$path = $_SERVER['DOCUMENT_ROOT'] . "/modules/{$class}.php";

if (is_readable($path)) require $path;


public static function daoautoloader($class)


$path = $_SERVER['DOCUMENT_ROOT'] . "/dataobjects/{$class}.php";

if (is_readable($path)) require $path;


public static function includesautoloader($class)


$path = $_SERVER['DOCUMENT_ROOT'] . "/includes/{$class}.php";

if (is_readable($path)) require $path;






74. How can we find the number of rows in a table using MySQL?

Use this for mysql
>SELECT COUNT(*) FROM table_name;
75. How can we find the number of rows in a result set using PHP?

$result = mysql_query($sql, $db_link);
$num_rows = mysql_num_rows($result);
echo "$num_rows rows found";
76. How many ways we can we find the current date using MySQL?

for time use
77. What are the advantages and disadvantages of Cascading Style Sheets?

External Style SheetsAdvantagesCan 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 contextsDisadvantagesAn 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 definitionsEmbedded 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
78. What are the differences between procedure-oriented languages and object-oriented languages?

There are lot of difference between procedure language and object oriented like below
1>Procedure language easy for new developer but complex to understand whole software as compare to object oriented model
2>In Procedure language it is difficult to use design pattern mvc , Singleton pattern etc but in OOP you we able to develop design pattern
3>IN OOP language we able to ree use code like Inheritance ,polymorphism etc but this type of thing not available in procedure language on that our Fonda use COPY and PASTE .
79. What is the use of friend function?

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 which names 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.
80. 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.transient: A transient variable is a variable that may not be serialized. volatile: a variable that might be concurrently modified by multiple threads should be declared volatile. Variables declared to be volatile will not be optimized by the compiler because their value can change at
any time.
81. What are the different types of errors in PHP?

Three are three types of errors: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, as you will
see, you can change this default behavior.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 behavior is to display them to the user when they take place.
82. What is the functionality of the function strstr and stristr?

strstr Returns part of string from the first occurrence of needle(sub string that we finding out ) to the end of string.
$email= '';
$domain = strstr($email, '@');
echo $domain; // prints
here @ is the needle
stristr is case-insensitive means able not able to diffrenciate between a and A
83 How can we submit a form without a submit button?

Java script submit() function is used for submit form without submit button
on click call document.formname.submit()
84. How can we convert asp pages to PHP pages?

there are lots of tools available for asp to PHP conversion. you can
search Google for that. the best one is available at
85. What is the functionality of the function 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.

86. 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.
87. How many ways can we get the value of current session id?

session_id() returns the session id for the current session.
88. 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
89. 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;
90. How many ways we can pass the variable through the navigation

91. 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.
92. What are the different functions in sorting an array?

Sort(), arsort(),
asort(), ksort(),
natsort(), natcasesort(),
rsort(), usort(),
array_multisort(), and
93. 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)
94. 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.
95. 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.
96. List out some tools through which we can draw E-R diagrams for mysql.

Case Studio
Smart Draw
97. 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);
98. List out the predefined classes in PHP?


99. What are the other commands to know the structure of table using MySQL commands except explain command?

describe Table-Name;
100. How many tables will create when we create table, what are they?

The '.frm' file stores the table definition.
The data file has a '.MYD' (MYData) extension.
The index file has a '.MYI' (MYIndex) extension,
101. What is the purpose of the following files having extensions 1) .frm 2) .myd 3) .myi? What do 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,
102. What is maximum size of a database in MySQL?

If the operating system or filesystem places a limit on the number of files in a directory, MySQL is bound by that constraint.The efficiency of the operating system in handling large numbers of files in a directory can place a practical limit on the number of tables in a database. If the time required to open a file in the directory increases significantly as the number of files increases, database performance can be adversely affected.The amount of available disk space limits the number of tables.MySQL 3.22 had a 4GB (4 gigabyte) limit on table size. With the MyISAM storage engine in MySQL 3.23, the maximum table size was increased to 65536 terabytes (2567 – 1 bytes). With this larger allowed table size,the maximum effective table size for MySQL databases is usually
determined by operating system constraints on file sizes, not by MySQL internal limits.The InnoDB storage engine maintains InnoDB tables within a tablespace
that can be created from several files. This allows a table to exceed the maximum individual file size. The tablespace can include raw disk partitions, which allows extremely large tables. The maximum tablespace size is 64TB. The following table lists some examples of operating system file-size limits. This is only a rough guide and is not intended to be definitive.For the most up-to-date information, be sure to check the documentation specific to your operating system. Operating System File-size LimitLinux 2.2-Intel 32-bit 2GB (LFS: 4GB) Linux 2.4+ (using ext3 filesystem) 4TB Solaris 9/10 16TB
NetWare w/NSS filesystem 8TB Win32 w/ FAT/FAT32 2GB/4GB
Win32 w/ NTFS 2TB (possibly larger)
MacOS X w/ HFS+ 2TB
103. Give the syntax of Grant and Revoke commands?

The generic syntax for grant is as following
> GRANT [rights] on [database/s] TO [username@hostname] IDENTIFIED BY [password]
now rights can be a) All privileges b) combination of create, drop, select, insert, update and delete etc.We can grant rights on all databse by using *.* or some specific database by database.* or a specific table by database.table_name username@hotsname can be either username@localhost, username@hostname
and username@%
where hostname is any valid hostname and % represents any name, the *.*
any condition
password is simply the password of userThe generic syntax for revoke is as following
> REVOKE [rights] on [database/s] FROM [username@hostname]
now rights can be as explained above
a) All privileges
b) combination of create, drop, select, insert, update and delete etc.
username@hotsname can be either username@localhost, username@hostname
and username@%
where hostname is any valid hostname and % represents any name, the *.*
any condition
104. Explain Normalization concept?

The normalization process involves getting our data to conform to three progressive normal forms, and a higher level of normalization cannot be achieved until the previous levels have been achieved (there are actually five normal forms, but the last two are mainly academic and will not be discussed).First Normal FormThe First Normal Form (or 1NF) involves removal of redundant data from horizontal rows. We want to ensure that there is no duplication of
data in a given row, and that every column stores the least amount of information possible (making the field atomic).Second Normal FormWhere the First Normal Form deals with redundancy of data across a horizontal row, Second Normal Form (or 2NF) deals with redundancy of data in vertical columns. As stated earlier, the normal forms are progressive, so to achieve Second Normal Form, your tables must already be in First Normal Form.Third Normal Form I have a confession to make; I do not often use Third Normal Form. In Third Normal Form we are looking for data in our tables that is not fully dependant on the primary key, but dependant on another value in the table


Post a Comment