Friday 20 September 2013

PHP Basic Questions Online | PHP Interview Questions and Answers for freshers pdf free | PHP Quiz Online

PHP Interview Questions with Answers

 
PHP Interview Questions with Answers
Q1 : How can we take a backup of a MySQL table and how can we restore it. ?

Answer : To backup: BACKUP TABLE tbl_name[,tbl_name…] TO ‘/path/to/backup/directory’ RESTORE TABLE tbl_name[,tbl_name…] FROM ‘/path/to/backup/directory’mysqldump: Dumping Table Structure and 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!

Q2: How can we optimize or increase the speed of a MySQL select query?

Answer : 
• 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.

Q3 : How many ways can we get the value of current session id?


Answer : session_id() returns the session id for the current session.

Q4 : How can we destroy the session, how can we unset the variable of a session?

Answer : session_unregister — Unregister a global variable from the current session

session_unset — Free all session variables

Q5 : How can we destroy the cookie?

Answer : Set the cookie in past.

Q6 : How many ways we can pass the variable through the navigation between the pages?

Answer : •GET/QueryString
•POST

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

Answer : 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.

Q8 : What are the different functions in sorting an array?

Answer : Sort(), arsort(),
asort(), ksort(),
natsort(), natcasesort(),
rsort(), usort(),
array_multisort(), and
uksort().

Q9 : How can we know the count/number of elements of an array?

Answer : 2 ways
a) sizeof($urarray) This function is an alias of count()
b) count($urarray)
 
//////////////////////////////////////////////////////////////////

Related Posts:

//////////////////////////////////////////////////////////////////

Q10 : What is the PHP predefined variable that tells the What types of images that PHP supports?

Answer : Though i am not sure if this is wrong or not, With the exif extension you are able to work with image meta data.

Q11 : How can I know that a variable is a number or not using a JavaScript?

Answer : 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.

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

Answer :
Case Studio
Smart Draw

Q13 : How can I retrieve values from one database server and store themin other database server using PHP?

Answer : WeWe 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 yousupply the link as because the link was overwritten by the new db.so 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 whichindicates whether a link will be created or not. As we connect to the $db2 with this optional parameter set to ‘true’, so both link willremain live. Now the following query will execute successfully.
$res3 = mysql_query(”query”,$db1);

Q14 : List out the predefined classes in PHP?

Answer : Directory
stdClass
__PHP_Incomplete_Class
exception
php_user_filter

Q15 : How can I make a script that can be bi-language (supports  English, German)?

Answer : 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 run-time choose the required language option.

Q16 : What are the difference between abstract class and interface?

Answer : Abstract class: abstract classes are the class where one or moremethods are abstract but not necessarily all method has to be abstract.

Abstract methods are the methods, which are declare in its class but not defined. 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 defined by its implemented class.

Q17 : How can we send mail using JavaScript?

Answer : JavaScript does not have any networking capabilities as it isdesigned to work on client site. As a result we can not send mails usingJavaScript. But we can call the client side mail protocol mailtovia JavaScript to prompt for an Email  to send. this requires the client to approve it.

Q18 : How can we repair a MySQL table?

Answer : 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 givenit will create index row by row.

Q19 : What are the advantages of stored procedures, triggers, indexes?

Answer : A stored procedure is a set of SQL commands that can be compiled andstored in the server. Once this has been done, clients don’t need tokeep re-issuing the entire query but can refer to the stored procedure.This provides better overall performance because the query has to beparsed only once, and less information needs to be sent between theserver and the client. You can also raise the conceptual level by havinglibraries of functions in the server. However, stored procedures ofcourse 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.
 
//////////////////////////////////////////////////////////////////

Related Posts:

//////////////////////////////////////////////////////////////////


Q20 : What is the maximum length of a table name, database name and field name in MySQL?

Answer : The following table describes the maximum length for each type of identifier.
Identifier     Maximum Length(bytes)
Database     64
Table     64
Column     64
Index     64
Alias     255

There are some restrictions on the characters that may appear in identifiers.

Q21 : How many values can the SET function of MySQL take?

Answer : MySQL set can take zero or more values but at the maximum it can take 64 values.

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

Answer : describe Table-Name;

Q23 : How many tables will create when we create table, what are they?

Answer : The ‘.frm’ file stores the table definition.The data file has a ‘.MYD’ (MYData) extension.The index file has a ‘.MYI’ (MYIndex) extension.

Q24 : What is the purpose of the following files having extensions 1) .frm2) .myd 3) .myi? What do these files contain?

Answer : 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.

Q25 : What is maximum size of a database in MySQL?

Answer : If the operating system or file system 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 offiles 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 to65536 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 table space that can be created from several files. This allows a table to exceed the maximum individual file size. The table space can include raw disk partitions, which allows extremely large tables. The maximum table space 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 documentationspecific to your operating system.Operating System File-size Limit Linux 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

Q26 : Give the syntax of Grant and Revoke commands?

Answer : 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 specificdatabase 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 user.
The 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

Q27: Explain Normalization concept?

Answer : 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 dependent on the primary key, but dependent on another value in the table.

Q28 : How can we find the number of rows in a table using MySQL?

Answer : Use this for mysql>SELECT COUNT(*) FROM table_name;


Q29 : How many ways we can we find the current date using MySQL?

Answer :
SELECT CURDATE();
CURRENT_DATE() = CURDATE()
for time use SELECT CURTIME();
CURRENT_TIME() = CURTIME() 
 
Q30 : What are the advantages and disadvantages of Cascading Style Sheets?

Answer :

External Style Sheets
Advantages : Can control styles for multiple documents at once. Classes can be created for use on multiple HTML element types in many documents.Selector and grouping methods can be used to apply styles under complex contexts.
Disadvantages : An extra download is required to import style information for eachdocument The rendering of the document may be delayed until the externalstyle sheet is loaded becomes slightly unwieldy for small quantities ofstyle 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 complexcontexts. 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 otherstyle specification methods at the local level so only exceptions needto be listed in conjunction with other style methods.
Disadvantages : Does not distance style information from content (a main goal ofSGML/HTML). Can not control styles for multiple documents at once.Author can not create or control classes of elements to control multipleelement types within the document. Selector grouping methods can not beused to create complex element addressing scenarios

Q31 : What type of inheritance that PHP supports?

Answer : In PHP an extended class is always dependent on a single base class,that is, multiple inheritance is supported by interfaces. Classes are extended using the keyword ‘extends’.

Q32 : What is the difference between Primary Key and Unique key?

Answer : Primary Key: A column in a table whose values uniquely identify therows in the table. A primary key value cannot be NULL. Unique Key: Unique Keys are used to uniquely identify each row in thetable. 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 morethan one unique for a table.

Q34 : The structure of table view buyers is as follows:
 
Field                  Type            Null         Key          Default          Extra 
user_pri_id     int(15)          PRI          null           auto_increment
userid             varchar(10)     YES         null   

the value of user_pri_id the last row 999 then What will happen inthe following conditions?Condition1: Delete all the rows and insert another row then.What is the starting value for this auto incremented field user_pri_id ,Condition2: Delete the last row(having the field value 999) andinsert another row then. What is the value for this auto incremented field user_pri_id.


Answer : In both cases let the value for auto increment field be n then nextrow will have value n+1 i.e. 1000.

Q35 : What are the advantages/disadvantages of MySQL and PHP?

Answer : Both of them are open source software (so free of cost), supportcross platform. php is faster then ASP and JSP.

Q36: What is the difference between GROUP BY and ORDER BY in Sql?

Answer : ORDER BY [col1],[col2],…,[coln]; Tells DBMS according to what columns it should sort the result. If two rows will have the same value in col1it will try to sort them according to col2 and so on.GROUP BY[col1],[col2],…,[coln]; Tells 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.

Q37 : What is the difference between char and varchar data types?

Answer : 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 ‘mizan’, if each char takes a byte eg. name varchar(15) will just use 5 bytes if we store ‘mizan’, if each char takes a byte. rest 10 bytes will be free.

Q38: What is the functionality of md5 function in PHP?

Answer : Calculate the md5 hash of a string. The hash is a 32-characterhexadecimal number. I use it to generate keys which I use to identifyusers etc. If I add random no techniques to it the md5 generated nowwill be totally different for the same string I am using.

Q39 : How can I load data from a text file into a table?

Answer : you can use LOAD DATA INFILE file_name; syntax to load datafrom a text file. but you have to make sure thata) data is delimitedb) columns and data matched correctly.

Q40 : How can we know the number of days between two given dates using MySQL?

Answer : SELECT DATEDIFF(’2007-03-07?,’2005-01-01?);


Note: For More Interview Question and Answers visit : http://interviewpdf.blogspot.in/

0 comments:

  © Blogger templates Newspaper III by Ourblogtemplates.com 2008

Back to TOP