Monday, 24 December 2012

PHP OOP Interview Questions & Answers

PHP OOP Interview Questions & Answers
1) Explain what is object oriented programming language?
Object oriented programming language allows concepts such as modularity, encapsulation, polymorphism and inheritance. Objects are said to be the most important part of object oriented language.
Concept revolves around making simulation programs around an bject. Organize a program around its data (object)& set well define interface to that data. i.e. objects and a set of well defined interfaces to that data. OOP is the common abbreviation for Object-Oriented Programming. OOps have many properties such as DataHiding,Inheritence,Data Absraction,Data Encapsulation and many more.
2) Name some languages which have object oriented language andcharacteristics?
Some of the languages which have object oriented languages present in them are ABAP, ECMA Script, C++, Perl, LISP, C#, Tcl, VB, Ruby, Python, PHP, etc. Popularity of these languages has increased considerably as they can solve complex problems with ease.
3) Explain about UML?
UML or unified modeling language is regarded to implement complete specifications and features of object oriented language.
Abstract design can be implemented in object oriented programming languages.
It lacks implementation of polymorphism on message arguments which is a OOPs feature.
4) Explain the meaning of object in object oriented programming?
Languages which are called as object oriented almost implement everything in them as objects such as punctuations, characters, prototypes, classes, modules, blocks, etc. They were designed to facilitate and implement object oriented methods.
5) Explain about message passing in object oriented programming?
Message passing is a method by which an object sends data to another object or requests other object to invoke method. This is also known as interfacing.
It acts like a messenger from one object to other object to convey specific instructions.
6) State about Java and its relation to Object oriented programming?
Java is widely used and its share is increasing considerably which is partly due to its close resemblance to object oriented languages such as C and C++. Code written in Java can be transported to many different platforms without changing it. It implements virtual machine.
7) What are the problems faced by the developer using object oriented programming language?
These are some of the problems faced by the developer using object oriented language they are: -
a) Object oriented uses design patterns which can be referred to as anything in general.
b) Repeatable solution to a problem can cause concern and disagreements and it is one of the major problems in software design.
8 ) State some of the advantages of object oriented programming?
Some of the advantages of object oriented programming are as follows: -
a) A clear modular structure can be obtained which can be used as a prototype and it will not reveal the mechanism behind the design. It does have a clear interface.
b) Ease of maintenance and modification to the existing objects can be done with ease.
c) A good framework is provided which facilitates in creating rich GUI applications.
9 ) Explain about inheritance in OOPS?
Objects in one class can acquire properties of the objects in other classes by way of inheritance. Reusability which is a major factor is provided in object oriented programming which adds features to a class without modifying it. New class can be obtained from a class which is already present.
10) Explain about the relationship between object oriented programming anddatabases?
Object oriented programming and relational database programming are almost similar in software engineering. RDBMS will not store objects directly and that’s where object oriented programming comes into play. Object relational mapping is one such solution.
11) Explain about a class in OOP?
In Object oriented programming usage of class often occurs. A class defines the characteristics of an object and its behaviors.
This defines the nature and functioning of a specified object to which it is assigned. Code for a class should be encapsulated.
12) Explain the usage of encapsulation?
Encapsulation specifies the different classes which can use the members of an object.
The main goal of encapsulation is to provide an interface to clients which decrease the dependency on those features and parts which are likely to change in future.
This facilitates easy changes to the code and features.
13) Explain about abstraction?
Abstraction can also be achieved through composition. It solves a complex problem by defining only those classes which are relevant to the problem and not involving the whole complex code into play.
14) Explain what a method is?
A method will affect only a particular object to which it is specified. Methods are verbs meaning they define actions which a particular object will perform. It also defines various other characteristics of a particular object.
15) Name the different Creational patterns in OO design?
There are three patterns of design out of which Creational patterns play an important role the various patterns described underneath this are: -
a) Factory pattern b) Single ton pattern c) Prototype pattern d) Abstract factory pattern e) Builder pattern
16) Explain about realistic modeling?
As we live in a world of objects, it logically follows that the object oriented approach models the real world accurately. The object oriented approach allows you to identify entities as objects having attributes and behavior.
17) Explain about the analysis phase?
The anlaysis or the object oriented analysis phase considers the system as a solution to a problem in its environment or domain. Developer concentrates on obtaining as much information as possible about the problem. Critical requirements needs to be identified.
18) Explain the rationale behind Object Oriented concepts?
Object oriented concepts form the base of all modern programming languages. Understanding the basic concepts of object-orientation helps a developer to use various modern day programming languages, more effectively.
19) Explain about Object oriented programming?
Object oriented programming is one of the most popular methodologies in software development. It offers a powerful model for creating computer programs. It speeds the program development process, improves maintenance and enhances reusability of programs.
20) Explain what is an object?
An object is a combination of messages and data. Objects can receive and send messages and use messages to interact with each other. The messages contain information that is to be passed to the recipient object.
21) Explain the implementation phase with respect to OOP?
The design phase is followed by OOP, which is the implementation phase. OOP provides specifications for writing programs in a programming language. During the implementation phase, programming is done as per the requirements gathered during the analysis and design phases.
22) Explain about the Design Phase?
In the design phase, the developers of the system document their understanding of the system. Design generates the blue print of the system that is to be implemented. The first step in creating an object oriented design is the identification of classes and their relationships.
23) Explain about a class?
Class describes the nature of a particular thing. Structure and modularity is provided by a Class in object oriented programming environment. Characteristics of the class should be understandable by an ordinary non programmer and it should also convey the meaning of the problem statement to him. Class acts like a blue print.
24) Explain about instance in object oriented programming?
Every class and an object have an instance. Instance of a particular object is created at runtime. Values defined for a particular object define its State. Instance of an object explains the relation ship between different elements.
25 ) Explain about inheritance?
Inheritance revolves around the concept of inheriting knowledge and class attributes from the parent class. In general sense a sub class tries to acquire characteristics from a parent class and they can also have their own characteristics. Inheritance forms an important concept in object oriented programming.
26) Explain about multiple inheritance?
Inheritance involves inheriting characteristics from its parents also they can have their own characteristics. In multiple inheritance a class can have characteristics from multiple parents or classes. A sub class can have characteristics from multiple parents and still can have its own characteristics.
27) Explain about encapsulation?
Encapsulation passes the message without revealing the exact functional details of the class. It allows only the relevant information to the user without revealing the functional mechanism through which a particular class had functioned.
28) Explain about abstraction?
Abstraction simplifies a complex problem to a simpler problem by specifying and modeling the class to the relevant problem scenario. It simplifies the problem by giving the class its specific class of inheritance. Composition also helps in solving the problem to an extent.
29) Explain the mechanism of composition?
Composition helps to simplify a complex problem into an easier problem. It makes different classes and objects to interact with each other thus making the problem to be solved automatically.
It interacts with the problem by making different classes and objects to send a message to each other.
30) Explain about polymorphism?
Polymorphism helps a sub class to behave like a parent class. When an object belonging to different data types respond to methods which have a same name, the only condition being that those methods should perform different function.
31) Explain about overriding polymorphism?
Overriding polymorphism is known to occur when a data type can perform different functions. For example an addition operator can perform different functions such as addition, float addition etc. Overriding polymorphism is generally used in complex projects where the use of a parameter is more.
32) Explain about object oriented databases?
Object oriented databases are very popular such as relational database management systems.
Object oriented databases systems use specific structure through which they extract data and they combine the data for a specific output.
These DBMS use object oriented languages to make the process easier.
33) Explain about parametric polymorphism?
Parametric polymorphism is supported by many object oriented languages and they are very important for object oriented techniques. In parametric polymorphism code is written without any specification for the type of data present. Hence it can be used any number of times.
34) What are all the languages which support OOP?
There are several programming languages which are implementing OOP because of its close proximity to solve real life problems.
Languages such as Python, Ruby, Ruby on rails, Perl, PHP, Coldfusion, etc use OOP. Still many languages prefer to use DOM based languages due to the ease in coding.
var gaJsHost = ((”https:” == document.location.protocol)
try {
var pageTracker = _gat._getTracker(”UA-1855756-5?);
pageTracker._trackPageview();
} catch(err) {}
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 : When you want to send short or small data,not containing ASCII characters, then you can use “GET”Method. But for long data sending say more then 100character you can use “POST” method. Once most imp diff is when you are sending the form with“Get” method. You can see the output which you are sendingin the addressbar. Whereas if you send the form with “POST”method then user can not see that information.
Get is an Idompotent method. (Idompotent: The side-effects of N > 0 identical requests is the same as for a single request. The methods GET, HEAD, PUT and DELETE share this property.)”GET” is basically for just getting (retrieving: quering db for data & retriving) data whereas “POST” may involve anything, like storing or updating data, or ordering a product, or sending E-mail.
In GET form data is to be encoded (by a browser) into a URL while the latter means that the form data is to appear within a message body. For GET in IE, Maximum URL Length Is 2,083 Characters in Internet Explorer (Q208427) or approximatly 1k.
2 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 similaraction to post the form values are sent through ‘visible’ query string andis retrieved by login.php by $_GET[’username’] and $_GET[’password’].POST :we are submitting a form to login.php, when we do ’submit’ orsimilar action to post the form, values are sent through ‘invisible’ standeredinput (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 GETmethod is limited(they say Internet Explorer can take care of maximum 2083 characteras a query string).
3. Who is the father of PHP and explain the changes in PHP versions?
Ans : Rasmus Lerdorf is the father of PHP.
PHP 5.1. Beta
MySQL 5.0
4. How can we submit a form without a submit button?
Ans : I can submit a form in many ways, for e.g.
1. When user click on checkbox, or drop down.
2. When user click on radio button.
3. At the end of the form I will type “Click here.
to submit” & link text to the processing file.
form.submit();
Trigger the JavaScript code on any event ( like onselect of drop down list box, onfocus, etc ) document.myform.submit();This will submit the form.
We can submit a from without a submit button help ho javascript like.
5. 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 mysql_fetch_object and mysql_fetch_array?
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.
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).
Speed-wise, the function is identical to mysql_fetch_array(),and almost as quick as mysql_fetch_row() (the difference isinsignificant).
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 onlyaccess the data by the field names, and not by their offsets(numbers are illegal property names).
7 What is the difference between $message and $$message?
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.
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$message is a variable
$$message is a variable variable.
A variable variable allows us to change the name of a variable dynamically.
$message is variable whereas $$message is dynamic varibale.
$message is variable whereas $$message is Dynamic variable.
eg.
$user=”bob”
is equivalent to
$holder=”user”;
$$holder=”bob”;
8.How can we extract string ‘abc.com ‘ from a string ‘http:// info@abc.com’ using regular expression of PHP?
preg_match(”|[^@]*@(.*)|im”, $text, $output);
$output will give result in second index of array, means $output[1] is answer. or
$exploded[1] should have abc.com or
echo mailto:substr(“>substr); or
preg_match(”/^(http:\/\/info@)?([^\/]+)/i”, $data); or
echo $data[2];
preg_match(’/^http:\/\/.+@(.+)$/’,$found); or
echo $found[1];
Use the function split split which returns an array any second element of the returned array will hold the value as abc.com.
9 .How can we create a database using PHP and mysql?
$sql = ‘CREATE DATABASE my_db’;
if (mysql_query($sql, $link))
{ echo “Database my_db created successfully\n”; }
else
{ echo ‘Error creating database: ‘ . mysql_error() . “\n”; }
mysql_create_db() should work
10.What are the differences between require and include, include_once?
require_once(),include_once() both the functions include and evalute the specified file only onceand if the specified file is opened previous to the present call occurrance, it will not be done again.But require() and include() will do it as many times they are asked to do.
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.
11.Can we use include (”abc.PHP”) two times in a PHP page “makeit.PHP”?
Yes we can include that many times we want, but here are some things to make sure of:
(including abc.PHP, the file names are case-sensitive)there shouldnt be any duplicate function names, means there should not be functions or classes or variables with the same name in abc.PHP and makeit.php
12. 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.
Table Types are
· ISAM(Index Sequential Access Method)
  • MyISAM
  • Static
  • Dynamic
  • 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.
MyISAM Table Type is created, if u not specified any table type then default will be applied and MyISAM is default Or
MyISAM is the default storage engine as of MySQL 3.23.
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
13 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.
14 How can I execute a PHP script using command line?
PHP can be executed from Command Line, using the SAP Interface (SAPI) or Server Application Programming Interface named CLI which means Command Line Interface.
The CLI SAPI was released for the first time with PHP 4.2.0, but was still experimental and had to be explicitly enabled with –enable-cli when running ./configure.
Since PHP 4.3.0 the CLI SAPI is no longer experimental and the option –enable-cli is on by default. You may use –disable-cli to disable it.
Through php parse you can execute PHP script using command line. By default location of php parser is so set the path of this directory and just use as following
#php sample.php
As of version 4.3.0, PHP supports a new SAPI type (Server Application Programming Interface) named CLI which means Command Line Interface.
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.
15 Suppose your Zend engine supports the mode Then how can u configure your PHP Zend engine to support mode ?
Its already supported.
In php.ini file:
set
short_open_tag=on
to make PHP support
16 Shopping cart online validation i.e. how can we configure Paypal, etc.?
Returns string with after inserting HTML line breaks before all newlines in a string
17 What is meant by nl2br()?
AES_ENCRYPT(str,key_str) , AES_DECRYPT(crypt_str,key_str)
nl2br — Inserts HTML line breaks before all newlines in a string

Description
string nl2br ( string string)
Returns string with ‘’ inserted before all newlines.
Note: Starting with PHP 4.0.5, nl2br() is now XHTML compliant. All versions before 4.0.5 will return string with ‘’ inserted before newlines instead of ‘’.
Example 1. using nl2br()
this will output :
foo isn’t
bar
18 Draw the architecture of Zend engine?
CRYPT()
MD5()
19 What are the current versions of apache, PHP, and mysql?
or information about latest version of Apache, Php and Mysql please visits the following sites respectively.
PHP: php5.1.2
MySQL: MySQL 5.1

Apache: Apache 2.1
20 What are the reasons for selecting lamp (linux, apache, mysql, PHP) instead of combination of other software programmes, 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.
21 How can we encrypt and decrypt a data present in a mysql table using mysql?
AES_ENCRYPT () and AES_DECRYPT ()
22 How can we encrypt the username and password using PHP?
You can encrypt a password with the following
Mysql>SET PASSWORD=PASSWORD(”Password”);
or
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);
23 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.
24 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 dateobject 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.
25 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.
26 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.
27 What are the different types of errors in PHP?
here are three basic types of runtime errors in PHP:
Three are three types of errors 1) Fatal errors 2) Parser errors 3) Startup 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 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
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.
28 What is the functionality of the function 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.
$domain = strstr($email, ‘@’);
echo $domain; // prints @example.com
stristr() is the case insensitive version of strstr()
strstr() returns part of a given string from the first occurrence of a given substring to the end of the string. For example: strstr.
stristr() is idential to strstr() except that it is case insensitive.
29 How can we convert asp pages to PHP pages?
You can download asp2php front end application from the site http://asp2php.naken.cc/”>http://asp2php.naken.cc/.
30 What is the functionality of the function htmlentities() and htmlsecialchars()?
htmlspecialchars : Convert some special characters to HTML entities (Only the most widley used)
htmlentities : Convert ALL special 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.
31 How can we get second of the current time using date function?
$second = date(“s”);
32 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
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”
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.
33 What is the difference between the functions unlink and unset?
unlink is a function for file system handling. It will simply delete the file in context
unset will set UNSET the variable. e.g
unlink() deletes the given file from the file system.
unset() makes a variable undefined.
unlink: is used to delete a file
unset is used to destroy an eralier declared variable
34 How can we register the variables into a session?
$_SESSION[’name’] = “Chinmay”;
To destroy a session: unset($_SESSION[’name’]);
$_SESSION[’var’] = ‘value’; or
Old way (deprecated):
$var = ‘value’;
session_register(’var’); or
session_register($ur_session_var);
We can use the session_register ($ur_session_var) function.
35 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.
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.
36 What is the maximum size of a file that can be uploaded using PHP and how can we change this?
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.
You can change maximum size of a file set upload_max_filesize variable in php.ini file
37 How can we increase the execution time of a PHP script?
Use set_time_limit(int) where int is the number of seconds forexecution of the script. If it’s set to 0 it’s unlimited. Default valueis 30.
By the use of void set_time_limit ( int seconds)Set the number of seconds a script is allowed to run. If this is reached, the script returns a fatal error. The default limit is 30 seconds or, if it exists, the max_execution_time value defined in the php.ini. If seconds is set to zero, no time limit is imposed.
When called, set_time_limit() restarts the timeout counter from zero. In other words, if the timeout is the default 30 seconds, and 25 seconds into script execution a call such as set_time_limit(20) is made, the script will run for a total of 45 seconds before timing out.
Set max_execution_time variable in php.ini file to your desired time in second.
38 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 andData
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…

No comments:

Post a Comment