100 PHP Interview Questions

100 PHP
INTERVIEW QUESTIONS
1.What is the
difference between $name and $$name?
$name is variable where as $$name
is reference variable
like $name=Sonia and $$name=Singh so $Sonia value is Singh.
2. 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 ()
3. What’s the difference between include and require?
It’s how they handle failures. If
the file is not found by require (), it will cause a fatal error and halt the
execution of the script. If the file is not found by include (), a warning will
be issued, but execution will continue.
4. What is the difference between explode and split?
Split function splits string into array by
regular expression. Explode splits a string into array by string. For Example:
explode (” and”, “India and Pakistan and Srilanka”);
split (” :”, “India: Pakistan: Srilanka”);
Both of these functions will return
an array that contains India,
Pakistan,
and Srilanka.
5. How can you avoid execution time out error while fetching record
from MySQL?
set_time_limit — Limits the
maximum execution time
For Example:
set_time_limit
(0);
If you set to 0 you say that there
is not limit.
6. In how many ways we can retrieve the data in the result set
of

MySQL using PHP?
We can do it by 4 Ways
1. mysql_fetch_row. , 2. mysql_fetch_array , 3. mysql_fetch_object
4. mysql_fetch_assoc
7. 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
8. What
are the different tables (Engine) present in MySQL, which one is default?
 Following tables (Storage Engine) we can create
1. MyISAM(The default storage engine IN MYSQL 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. An .frm file stores the
table format. The data file has an .MYD (MYData) extension. The index file has
an .MYI (MYIndex) extension. )
2. InnoDB(InnoDB is a transaction-safe (ACID compliant) storage engine
for MySQL that has commit, rollback, and crash-recovery capabilities to protect
user data.)
3. Merge
4. Heap (MEMORY)(The MEMORY storage engine creates tables with contents
that are stored in memory. Formerly, these were known as HEAP tables. MEMORY is
the preferred term, although HEAP remains supported for backward compatibility.
)
5. BDB (BerkeleyDB)(Sleepycat Software has provided MySQL with the
Berkeley DB transactional storage engine. This storage engine typically is
called BDB for short. BDB tables may have a greater chance of surviving crashes
and are also capable of COMMIT and ROLLBACK operations on transactions)
6. FEDERATED (It is a storage engine that accesses data in tables of
remote databases rather than in local tables. )
7. ARCHIVE (The ARCHIVE storage engine is used for storing large amounts
of data without indexes in a very small footprint. )
8. CSV (The CSV storage engine stores data in text files using
comma-separated values format.)
9. BLACKHOLE (The BLACKHOLE storage engine acts as a “black
hole” that accepts data but throws it away and does not store it.
Retrievals always return an empty result)
9. What is use of header () function in php?
The header () function sends a raw
HTTP header to a client. We can use herder()
function for redirection of pages. It is important to notice that header ()
must
be called before any actual output is seen.
10. 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.
11. How can we encrypt and decrypt a data present in a MySQL
table

using MySQL?
AES_ENCRYPT () and AES_DECRYPT ()
12. How
can we encrypt the username and password using PHP?
encryption
decryption
AES_ENCRYT()
AES_DECRYPT()
ENCODE()
DECODE()
DES_ENCRYPT()
DES_DECRYPT()
ENCRYPT()
Not available
MD5()
Not available
OLD_PASSWORD()
Not available
PASSWORD()
Not available
SHA() or SHA1()
Not available
Not available
UNCOMPRESSED_LENGTH()
13. 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
14. 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 .
15. 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.
16. 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.
17. What is the difference between the functions unlink and
unset?
Unlink () deletes the given file
from the file system.
Unset () makes a variable undefined.
18. 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
19. 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
20. 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.
21. How many ways can we get the value of current session
id?
session_id() returns the session id
for the current session.
22. How can we know the count/number of elements of an
array? And
How do you define a
constant?
2 ways
a) sizeof($urarray) This function is an alias of count()
b) count($urarray)
Constants in PHP are defined using
define() directive, like define(“MYCONSTANT”, 100);
23. 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.
24. 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.
25. What is the maximum length of a table name, database
name, and
fieldname in MySQL?
Identifier
Maximum Length
(bytes)
Database
64
Table
64
Column
64
Index
64
Alias
255
26. What are the other commands to know the structure of
table using
MySQL commands except explain command?
describe Table-Name;
27. 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,
28. 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 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
29. 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 have
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), and AVG (col1) with it, if
you want to count all items in group, sum all values or view average
30. 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.
31. How can I load data from a text file into a table?
You can use LOAD DATA INFILE filename;
syntax to load data from a text file. But you have to make sure that a) data is
delimited b) columns and data matched correctly
32. How can we know the number of days between two given
dates using
MySQL?
SELECT DATEDIFF (“2007-03-07″,”2005-01-01”);
33. 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);
34. 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.
35. 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 session
expire make it inactive. At any time by counting the no: of active records we
can get the no: of visitors.
36. Which
library used for making PDF in PHP?
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
generating 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.
37. Which library is used for work image?
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.
38. 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
39. What’s the difference between md5(), crc32() and sha1() crypto on
PHP?
The major difference is the length
of the hash generated. CRC32 is, evidently, 32 bits, while sha1 () returns a
128 bit value, and md5 () returns a 160 bit value. This is important when
avoiding collisions.
40. What are the predefined variables in php?
$GLOBALS, $_REQUEST,$_POST,$_GET,$_COOKIE,$_SESSION,$_FILES,
$_ENV are predefined variables.
41. How to convert
decimal values to characters?
Based on some friendly advice will here my revised version
if $decimal is a variable with your decimal value in it. Echo chr ($decimal);
will print out the character.
42. 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.
43. 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];
44.  What are the
current versions of apache, php, and mysql?
PHP:
php5.1.2
MySQL:
MySQL 5.1
Apache:
Apache 2.1
45. 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.
46. 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.
47. 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.
48. 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 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.
49. How can we get second of the current time using date
function?
$second
= date (“s”);
50. How can we convert the time zones using php?
echo
“Original Time: “. date(“h:i:s”).”n”;
putenv(“TZ=US/Eastern”);
echo
“New Time: “. date(“h:i:s”).”n”;
?>
51. How can we register the variables into a session?
We can
use the session_register ($ur_session_var) function.
52 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.
53. Explain
the ternary conditional operator in PHP?
Expression preceding the ? is evaluated, if it’s true,
then the expression preceding the : is
executed, otherwise, the expression following : is
executed.
54. How many ways we can pass the variable through the
navigation between the pages?
At
least 3 ways:
a)
Register the variable into the session
b)
Pass the variable as a cookie
c)
Pass the variable as part of the URL
55. What are the different functions in sorting an array?
Sorting
functions in PHP:
asort()
arsort()
ksort()
krsort()
uksort()
sort()
natsort()
rsort()
56. How can I know that a variable is a number or not using
a _JavaScript?
function
IsNumeric(sText)
{
var
ValidChars = “0123456789.”;
var
IsNumber=true;
var Char;
for (i
= 0; i < sText.length && IsNumber == true; i++)
{
Char =
sText.charAt(i);
if
(ValidChars.indexOf(Char) == -1)
{IsNumber
=
false;
}
}
return
IsNumber;
}
57. How can I make a script that can be bilanguage
(supports English, German)?
You
can change charset variable in above line in the script to support bilanguage.
58. 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 Form
The
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 Form
Where
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
59. What is the functionality of md5 function in php?
string
md5(string)
Calculate
the md5 hash of a string. The hash is a 32-character hexadecimal number.
We can
use it to generate keys, which we use to identify users etc. If we add random
no
techniques to it the md5 generated now will be totally different for the same
string
we are using.
60. How can we change the name of a column of a table?
MySQL
query to rename table: RENAME TABLE tbl_name
TO new_tbl_name
[, tbl_name2 TO new_tbl_name2] …
or,
ALTER
TABLE tableName CHANGE OldName newName.
61. What are the differences between drop a table and
truncate a table?
Delete
a Table or Database To delete a table (the table structure, attributes, and
Indexes
will also be deleted).What if we only want to get rid of the data inside a
table, and not the table itself?
Use
the TRUNCATE TABLE command (deletes only the data inside the table).
62. When you want to show some part of a text displayed on
an HTML page in red font color, what different possibilities are there to do
this? What are the
Advantages/disadvantages of these methods?
Using
Html font color tag:
I am Amin
Using
tag in CSS:
STRONG
{color:red}
So
when we use the tag:
I am
Amin about this.
Using
Class in CSS:
.colorclass
{
color:#FF3399;
font-weight:900;
}I
am
Amin
If we
use html the modification will be trouble some because we have to change the
code
of the page. But when we use CSS then it will be easy to change the CSS file
and we
can get the desired out put.
63. When viewing an HTML page in a Browser, the Browser
often keeps this page in its cache. What can be possible
advantages/disadvantages of page caching? How can you prevent caching of a
certain page (please give several alternate solutions)?
When
you use the
metatag
in the
header
section at the beginning of an HTML Web page, the Web page may
still
be cached in the Temporary Internet Files folder.
A page
that Internet Explorer is browsing is not cached until half of the 64 KB
>
buffer is filled. Usually, metatags are inserted in the header section of an
>
HTML document, which appears at the beginning of the document. When the
HTML
code is parsed, it is read from top to bottom. When the
CONTENT=”NO-CACHE”>
metatag is read, Internet Explorer looks for the
existence
of the page in cache at that exact moment. If it is there, it is removed. To
properly
prevent the Web page from appearing in the cache, place another header
section
at the end of the HTML ocument. For example:
64. What are the different ways to login to a remote
server? Explain the means,
advantages and disadvantages?
There
is at least 3 ways to logon to a remote server:
Use
ssh or telnet if you concern with security
You
can also use rlogin to logon to a remote server.
65. A company wants to store their invoices in a database.
They already have their
customers and articles in that database. Both customer and
article are each identified by an unique integer value. Please create the SQL
statements for creating the necessary table(s) for storing the invoices in a
MySQL database. An invoice should hold information like invoice number,
customer, date, article(s) and quantity etc.
CREATE
TABLE invoice (
id
int(11) NOT NULL default ‘0’, invoceNo
int(11)
NOT NULL default ‘0’, customer_id
varchar(20)
NOT NULL default ‘0’, article_id
varchar(20)
NOT NULL default ‘0’, date
varchar(20)
NOT NULL default ‘0’, quantity
int(11)
NOT NULL default ‘0’,
PRIMARY
KEY (id)
)
TYPE=MyISAM;
66. What is meant by MIME?
Multipurpose
Internet Mail Extensions.
WWW’s
ability to recognise and handle files of different types is largely dependent
on the
use of the MIME (Multipurpose Internet Mail Extensions) standard. The
standard
provides for a system of registration of file types with information about
the
applications needed to process them. This information is incorporated into Web
server
and browser software, and enables the automatic recognition and display of
registered
file types. …
67. What is meant by PEAR in php?
PEAR
is short for “PHP Extension and Application Repository” and is pronounced
just
like the fruit. The purpose of PEAR is to provide:
A
structured library of open-sourced code for PHP users
A
system for code distribution and package maintenance
A
standard style for code written in PHP
The
PHP Foundation Classes (PFC),
The
PHP Extension Community Library (PECL),
A web
site, mailing lists and download mirrors to support the PHP/PEAR
community
PEAR
is a community-driven project with the PEAR Group as the governing body.
The
project has been founded by Stig S. Bakken in 1999 and quite a lot of people
have
joined the project since then.
68. How can we know that a session is started or not?
A
session starts by session start() function.
This
session_start () is always declared in header portion. it always declares first.
then
we
write session register().
69. What is the default session time in php and how can I
change it?
The
default session time in php is until closing of browser
70. How To
Read the Entire File into a Single String?
If you have a file, and you want to read the entire file
into a single string, you can use the
file_get_contents() function. It opens the specified file,
reads all characters in the file, and
returns them in a single string. Here is a PHP script
example on how to
file_get_contents():
$file = file_get_contents(“/windows/system32/drivers/etc/services”);
print(“Size of the file:
“.strlen($file).”n”);
?>
This script will print:
Size of the file: 7116
71. What are the differences between mysql_fetch_array(),
mysql_fetch_object(),
mysql_fetch_row()?
mysql_fetch_array
— Fetch a result
row as an associative array, a numeric array, or
both.
mysql_fetch_object
( resource result )
Returns
an object with properties that correspond to the fetched row and moves the
internal
data pointer ahead. Returns an object with properties that correspond to
the
fetched row, or FALSE if there are no more rows
mysql_fetch_row()
fetches one row of
data from the result associated with the
specified
result identifier. The row is returned as an array. Each result column is
stored
in an array offset, starting at offset 0.
72. Steps for the payment gateway processing?
An
online payment gateway is the interface between your merchant account and
your
Web site. The online payment gateway allows you to immediately verify credit
card
transactions and authorize funds on a customer’s credit card directly from
your
Web site. It then passes the transaction off to your merchant bank for
processing,
commonly referred to as transaction batching
73. How many ways I can redirect a php page?
Here
are the possible ways of php page redirection.
Using
Java script:
function redirect($filename)
{
if (!headers_sent())
header(‘Location: ‘.$filename);
else {
echo ”;

echo
‘window.location.href=”‘.$filename.'”;’;

echo ”;

echo ”;

echo ”;

echo ”;

}
}
redirect(‘http://maosjb.com’);
?>
Using
php function:
Header(“Location:http://maosjb.com
“);
74. What are the differences between include() and
include_once()
functions?
include_once()
will use the specified file only once. include and require will
use
the specified file as many time we want. If include_once() is used before with
same
name, it can not done again
75. What is the difference between using copy() and move()
function
in php file uploading?
copy (
string source, string dest)
Makes
a copy of the file source to dest. Returns TRUE on success or
FALSE on
failure.
Usage:
if
(!copy($file, $file.’.bak’)) {
echo
“failed to
copy $file…
n”;
}
?>
move_uploaded_file
( string filename, string destination)
This
function checks to ensure that the file designated by filename is a
valid upload
file
(meaning that it was uploaded via PHP’s HTTP POST upload mechanism). If
the
file is valid, it will be moved to the filename given by destination.If filename
is not a valid upload file, then no action will occur, and move_uploaded_file()
will return FALSE. If filename is a valid upload file, but cannot be
moved for some reason, no action will occur, and move_uploaded_file() will
return FALSE. Additionally, a warning will be issued.
76. What is the difference between Reply-to and Return-path
in the headers of a mail function?
Reply-to:
Reply-to is where to delivery the reply of the mail.
Return-path:
Return path is when there is a mail delivery failure occurs then where
to
delivery the failure notification.
77.  How can I find
what type of images that the php version supports?
Using
Imagetypes() function we can know Usage:
if (imagetypes() & IMG_PNG) {
echo
“PNG Support
is enabled”;
}?>
78    What
is DDL, DML and DCL?
    If you look at the large variety of SQL
commands, they can be divided into three large subgroups. Data Definition
Language deals with database schemas and descriptions of how the data should
reside in the database, therefore language statements like CREATE TABLE or
ALTER TABLE belong to DDL. DML deals with data manipulation, and therefore
includes most common SQL statements such SELECT, INSERT, etc. Data Control
Language includes commands such as GRANT, and mostly concerns with rights,
permissions and other controls of the database system.
79    How
do you get the number of rows affected by query?
   SELECT
COUNT (user_id) FROM users would only return the number of user_id’s.
80    If
the value in the column is repeatable, how do you find out the unique values?
Use DISTINCT in the query, such as SELECT
DISTINCT user_firstname FROM users; You can also ask for a number of distinct
values by saying SELECT COUNT (DISTINCT user_firstname) FROM users;
81    How
do you return the a hundred books starting from 25th?
   SELECT
book_title FROM books LIMIT 25, 100. The first number in LIMIT is the offset,
the second is the number.
82    You
wrote a search engine that should retrieve 10 results at a time, but at the
same time you’d like to know how many rows there’re total. How do you display
that to the user?
   SELECT
SQL_CALC_FOUND_ROWS page_title FROM web_pages LIMIT 1,10; SELECT FOUND_ROWS();
The second query (not that COUNT() is never used) will tell you how many
results there’re total, so you can display a phrase “Found 13,450,600
results, displaying 1-10”. Note that FOUND_ROWS does not pay attention to
the LIMITs you specified and always returns the total number of rows affected
by query.
83    How
would you write a query to select all teams that won either 2, 4, 6 or 8 games?
   SELECT
team_name FROM teams WHERE team_won IN (2, 4, 6, 8)
84    How
would you select all the users, whose phone number is null?
   SELECT
user_name FROM users WHERE ISNULL(user_phonenumber);
85    What
does this query mean: SELECT user_name, user_isp FROM users LEFT JOIN isps
USING (user_id)
   It’s
equivalent to saying SELECT user_name, user_isp FROM users LEFT JOIN isps WHERE
users.user_id=isps.user_id
86    How
do you find out which auto increment was assigned on the last insert?
SELECT LAST_INSERT_ID() will return the last
value assigned by the auto_increment function. Note that you don’t have to
specify the table name.
87    What
does –i-am-a-dummy flag to do when starting MySQL?
   Makes
the MySQL  engine refuse UPDATE and DELETE commands where the WHERE clause
is not present.
88. On executing the DELETE statement I
keep getting the error about foreign key constraint failing. What do I do?
   What it means is that so of the data that
you’re trying to delete is still alive in another table. Like if you have a
table for universities and a table for students, which contains the ID of the
university they go to, running a delete on a university table will fail if the
students table still contains people enrolled at that university. Proper way
to do it would be to delete the offending data first, and then delete the
university in question. Quick way would involve running SET
foreign_key_checks=0 before the DELETE command, and setting the parameter back
to 1 after the DELETE is done. If your foreign key was formulated with ON
DELETE CASCADE, the data in dependent tables will be removed automatically.
89   
When would you use ORDER BY in DELETE statement?

When you’re not deleting by row ID. Such as in DELETE FROM
techinterviews_com_questions ORDER BY timestamp LIMIT 1. This will delete the
most recently posted question in the table techinterviews_com_questions.


90   
How can you see all indexes defined for a table?

 SHOW INDEX FROM
techinterviews_questions;


91   
How do I find out all databases starting with
‘tech’ to which I have access to?
– SHOW DATABASES LIKE ‘tech%’;


92   
How do you concatenate strings in MySQL?
CONCAT (string1, string2, string3)


93   
How do you get a portion of a string?
SELECT SUBSTR(title, 1, 10) from techinterviews_questions;


94   
What’s the difference between CHAR_LENGTH and
LENGTH?

The first is, naturally, the character count. The second is byte count. For the
Latin characters the numbers are the same, but they’re not the same for Unicode
and other encodings.
 
95   
How do you offload the time/date handling to
MySQL?

SELECT DATE_FORMAT(techinterviews_timestamp, ‘%Y-%m-%d’) from
techinterviews_questions; A similar TIME_FORMAT function deals with time.


96   
What are ENUMs used for in MySQL?
You can limit the possible values that go into the table. CREATE TABLE months
(month ENUM ‘January’, ‘February’, ‘March’,…); INSERT months VALUES (’April’);


97   
How are ENUMs and SETs represented internally?
As unique integers representing the powers of two, due to storage
optimizations.


98    What
is subquerry? Types of subqurries?

1. Subquery is nothing but a query inside a query which appears only after the
WHERE clause of a select statement.
2. Two types of subquery is there:
    a) Co-Related subquery
    b) Non-Co-related subquery.
99   
What is meant by scalability in database?
   Scalability is a database property by
means of which the database utilizes the available additional
resources such as the memory and the processors to meet the increasing demand.
100. How to view all Triggers
in MySQL?
   Select count(*) from table_name