Showing posts with label questions. Show all posts
Showing posts with label questions. Show all posts

Friday, July 1, 2016

PHP Interview Questions Part 1

Common PHP Interview Questions

1. What is CAPTCHA?

CAPTCHA stands for Completely Automated Public Turing Test to tell Computers and Humans Apart. To prevent spammers from using bots to automatically fill out forms, CAPTCHA programmers will generate an image containing distorted images of a string of numbers and letters. Computers cannot determine what the numbers and letters are from the image but humans have great pattern recognition abilities and will be able to fairly accurately determine the string of numbers and letters. By entering the numbers and letters from the image in the validation field, the application can be fairly assured that there is a human client using it. To read more look here:
http://en.wikipedia.org/wiki/Captcha


2. What is difference between require_once(), require(), include().

Difference between require() and require_once(): require() includes and evaluates a specific file, while require_once() does that only if it has not been included before (on the same page). So, require_once() is recommended to use when you want to include a file where you have a lot of functions for example. This way you make sure you dont include the file more times and you will not get the "function re-declared" error. Difference between require() and include() is that require() produces a FATAL ERROR if the file you want to include is not found, while include() only produces a WARNING. There is also include_once() which is the same as include(), but the difference between them is the same as the difference between require() and require_once().


3. If you have to work with dates in the following format: "Tuesday, February 14, 2006 @ 10:39 am", how can you convert them to another format, that is easier to use?

The strtotime function can convert a string to a timestamp. A timestamp can be converted to date format. So it is best to store the dates as timestamp in the database, and just output them in the format you like.

So lets say we have
$date = "Tuesday, February 14, 2006 @ 10:39 am";
In order to convert that to a timestamp, we need to get rid of the "@" sign, and we can use the remaining string as a parameter for the strtotime function.

So we have
$date = str_replace("@ ","",$date);
$date = strtotime($date);

now $date is a timestamp
and we can say:

echo date("d M Y",$date);


4. How we know browser properties?

get_browser() attempts to determine the capabilities of the users browser. This is done by looking up the browsers information in the browscap.ini file.

echo $_SERVER[HTTP_USER_AGENT] . " ";

$browser = get_browser();

foreach ($browser as $name => $value) {
echo "$name $value
";
}


5. How i will check that user is, logged in or not. i want to make it a function and i want to use in each page and after login i want to go in current page(same page. where i was working)?

For this we can use the session objec($_SESSION)t. When the user login with his/ her user name and password, usually we check those to ensure for correctness. If that user name and password are valid one then we can store that user name in a session and then we can very that session variable has been set or not in a single files and we can include that file in all pages.

6. How i can get IP address?

We can use SERVER var $_SERVER[SERVER_ADDR] and getenv("REMOTE_ADDR") functions to get the IP address.

7. What is differenc between mysql_connect and mysql_pconnec?

mysql_pconnect establishes a persistent connection. If you dont need one (such as a website that is mostly HTML files or PHP files that dont call the db) then you dont need to use it. mysql_connect establishes a connection for the duration of the script that access the db. Once the script has finished executing it closes the connection. The only time you need to close the connection manually is if you jump out of the script for any reason.

If you do use mysql_pconnect. You only need to call it once for the session. Thats the beauty of it. It will hold open a connection to the db that you can use over and over again simply by calling the resource ID whenever you need to interact with the db.

8. What is the difference between echo and print statement?

There is a slight difference between print and echo which would depend on how you want to use the outcome. Using the print method can return a true/false value. This may be helpful during a script execution of some sort. Echo does not return a value, but has been considered as a faster executed command. All this can get into a rather complicated discussion, so for now, you can just use whichever one you prefer.

9. How to make a download page in own site, which i can know that how many file has been loaded by particular user or particular IP address?

We can use hyperlink having URL where file are kept. and we only allow registered user to download. from session of user we can get the user detail 

Thursday, June 16, 2016

PHP Interview Questions Part 2

PHP Interview Questions

1. what is the output of 2^2 in php ?

The answer is 0 (Zero).

Everyone expected answer would be 4.But answer is zero.How it happened only in php ?The ^ operator is different in each language.In PHP ^ means the bitwise exlusive or of the two numbers.

2. What Is a Session?

A session is a logical object created by the PHP engine to allow you to preserve data across subsequent HTTP requests.There is only one session object available to your PHP scripts at any time. Data saved to the session by a script can be retrieved by the same script or another script when requested from the same visitor.Sessions are commonly used to store temporary data to allow multiple PHP pages to offer a complete functional transaction for the same visitor.

3. What is meant by PEAR in php?

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

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

Simple arithmetic:

$date1 = date(‘Y-m-d’);

$date2 = ’2006-07-01?;

$days = (strtotime() – strtotime()) / (60 * 60 * 24);

echo “Number of days since ’2006-07-01?: $days”

5. How can we repair a MySQL table?

The syntax for repairing a mysql table is:

REPAIR TABLE tablename

REPAIR TABLE tablename QUICK

REPAIR TABLE tablename EXTENDED

This command will repair the table specified.

If QUICK is given, MySQL will do a repair of only the index tree.

If EXTENDED is given, it will create index row by row.

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

Anwser 1:

$message is a simple variable whereas $$message is a reference variable. Example:

$user = ‘bob’

is equivalent to

$holder = ‘user’;

$$holder = ‘bob’;

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

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

8. What does a special set of tags do in PHP?

The output is displayed directly to the browser.How do you define a constant?

Via define() directive, like define (“MYCONSTANT”, 100);

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

Anwser 1:

require_once() and include_once() are both the functions to include and evaluate the specified file only once. If the specified file is included previous to the present call occurrence, it will not be done again.But require() and include() will do it as many times they are asked to do.

Anwser 2:

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

Anwser 3:

All three are used to an include file into the current page.

If the file is not present, require(), calls a fatal error, while in include() does not.

The include_once() statement includes and evaluates the specified file during the execution of the script. This is a behavior similar to the include() statement, with the only difference being that if the code from a file has already been included, it will not be included again. It des not call a fatal error if file not exists. require_once() does the same as include_once(), but it calls a fatal error if file not exists.

Anwser 4:

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

10. What is meant by urlencode and urldecode?

Anwser 1:

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

urldecode() returns the URL decoded version of the given string.

Anwser 2:

string urlencode(str) – Returns the URL encoded version of the input string. String values to be used in URL query string need to be URL encoded. In the URL encoded version:

Alphanumeric characters are maintained as is.

Space characters are converted to “+” characters.

Other non-alphanumeric characters are converted “%” followed by two hex digits representing the converted character.

string urldecode(str) – Returns the original string of the input URL encoded string.For example:

$discount =”10.00%”;

$url = “http://domain.com/submit.php?disc=”.urlencode($discount);

echo $url;You will get “http://domain.com/submit.php?disc=10%2E00%25?.

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

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

$_FILES[$fieldName][name] – The Original file name on the browser system.

$_FILES[$fieldName][type] – The file type determined by the browser.

$_FILES[$fieldName][size] – The Number of bytes of the file content.

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

$_FILES[$fieldName][error] – The error code associated with this file upload.

The $fieldName is the name used in the input name="fieldName" type="FILE,".

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


Saturday, June 4, 2016

PHP Interview Questions Part 3

PHP Interview Questions

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

Just run the PHP CLI (Command Line Interface) program and provide the PHP script file name as the command line argument. For example, “php myScript.php”, assuming “php” is the command to invoke the CLI program.

Be aware that if your PHP script was written for the Web CGI interface, it may not execute properly in command line environment.I am trying to assign a variable the value of 0123, but it keeps coming up with a different number, what’s the problem?

PHP Interpreter treats numbers beginning with 0 as octal. Look at the similar PHP interview questions for more numeric problems.Would I use print “$a dollars” or “{$a} dollars” to print out the amount of dollars in this example?

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

2. 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))?

(Answer) Total 5 types of tables we can create

1. MyISAM2. Heap

3. Merge

4. INNO DB

5. ISAM

MyISAM is the default storage engine as of MySQL 3.23. When you fire the above create query MySQL will create a MyISAM table.

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

Answer1

You can encrypt a password with the following Mysql>SET PASSWORD=PASSWORD(“Password”);

Answer2

You can use the MySQL PASSWORD() function to encrypt username and password. For example,

INSERT into user (password, …) VALUES (PASSWORD($password”)), …);

3. How do you pass a variable by value?

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

4. What is the functionality of the functions STRSTR() and STRISTR()?

string strstr ( string haystack, string needle ) returns part of haystack string from the first occurrence of needle to the end of haystack. This function is case-sensitive.

stristr() is idential to strstr() except that it is case insensitive.

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

strstr() returns part of a given string from the first occurrence of a given substring to the end of the string. For example: strstr(“user@example.com”,”@”) will return “@example.com”.

stristr() is idential to strstr() except that it is case insensitive.


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

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

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

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

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

In MySQL, the default table type is MyISAM.

Each MyISAM table is stored on disk in three files. The files have names that begin with the table name and have an extension to indicate the file type.

The ‘.frm’ file stores the table definition.

The data file has a ‘.MYD’ (MYData) extension.

The index file has a ‘.MYI’ (MYIndex) extension

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

100, it’s a reference to existing variable.

10. Are objects passed by value or by reference?

Everything is passed by value.

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

DROP TABLE table_name – This will delete the table and its data.

TRUNCATE TABLE table_name – This will delete the data of the table, but not the table definition.

Thursday, June 2, 2016

PHP Interview Questions Part 6

1) What is the use of “Final class” and can a final class be an abstract?

(Ans) The “Final” keyword is used to make the class un-inheritable. So the class or it’s methods can not be overridden.
final class Class1 {
// ...
}

class FatalClass extends Class1 {
// ...
}

$out= new FatalClass();

An Abstract class will never be a final class as an abstract class must be extendable.

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

(Ans) Simple arithmetic:
$date1 = date(‘Y-m-d’);
$date2 = ’2006-07-01?;
$days = (strtotime() – strtotime()) / (60 * 60 * 24);
echo “Number of days since ’2006-07-01?: $days”;

3)  How To Write the FORM Tag Correctly for Uploading Files?

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

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

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

<?php

print("<html><form action=processing_uploaded_files.php"

." method=post enctype=multipart/form-data> ");

print("Please submit an image file a Web site logo for"

." fyicenter.com:<br> ");

print("<input type=file name=fyicenter_logo><br> ");

print("<input type=submit> ");

print("</form></html> ");

?>

4) Consider the following code snippet. Is this code acceptable from a security standpoint?

Assume that the $action and $data variables are designed to be accepted from the user and
register_globals is enabled.

<?php
if(isUserAdmin()) {
$isAdmin = true;
}
$data = validate_and_return_input($data);
switch($action){
case add:
addSomething($data);
break;
case delete:
if($isAdmin) {
deleteSomething($data);
}
break;
case edit:
if($isAdmin) {
editSomething($data);
}
break;
default:
print “Bad Action.”;
}
?>

A. Yes, it is secure. It checks for $isAdmin to be True before executing protected operations
B. No, it is not secure because it doesn’t make sure $action is valid input
C. No, it is not secure because $isAdmin can be hijacked by exploiting register_globals
D. Yes, it is secure because it validates the user-data $data
E. Both A and B

(Ans) The correct answer is C. This code is, by any means, not secure! In fact, it is the classic security exploit of PHP scripts using the register_globals configuration directive. The problem lies in the $isAdmin variable: although this is clearly a Boolean value, it is only set in the event that the user is an Admin and not set at all if the user is not. Because register_globals is enabled, by simply appending that variable to the end of the URL as a GET parameter, a malicious user could easily impersonate an administrator.


5) Which of the following will not combine strings $s1 and $s2 into a single string?
$s1 = a;
$s2 = b;
A. $s1 + $s2
B. "{$s1}{$s2}"
C. $s1.$s2
D. implode(, array($s1,$s2))
E. All of the above combine the strings

(Ans) You can not concatenate 2 string using “+”. The answer will be “0?; so here the answer is A.

6) Consider the following php script. What line of code should be inserted in the marked location in order to display the string php when this script is executed?

$alpha = abcdefghijklmnopqrstuvwxyz;
$letters = array(15, 7, 15);
foreach($letters as $val) {
/* What should be here */
}
A. echo chr($val);
B. echo asc($val);
C. echo substr($alpha, $val, 2);
D. echo $alpha{$val};
E. echo $alpha{$val+1}

(Ans) The answer is D. An array can be accessed like this as well. $alpha{$val}

7)  How can I execute a PHP script using command line?

(Ans) 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.

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

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

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

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

10) What are the different types of errors in PHP?

(Ans) Here are three basic types of runtime errors in PHP:

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

Internally, these variations are represented by twelve different error types.

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

(Ans) By default the maximum size is 2MB,and we can change the following setup at php.iniupload_max_filesize = 2M

12) How can we get the browser properties using PHP?

(Ans)     By using
$_SERVER[HTTP_USER_AGENT]
variable.

13) What is session_set_save_handler in PHP?

(Ans) 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.

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

(Ans) 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 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 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);

 15)  How can we extract string "abc.com" from a string "mailto:info@abc.com?subject=Feedback" using regular expression of PHP?

(Ans) Try this:
$text = "mailto:info@abc.com?subject=Feedback";
preg_match(‘|.*@([^?]*)|’, $text, $output);
echo $output[1];
 Note that the second index of $output, $output[1], gives the match, not the first one, $output[0].

So if md5() generates the most secure hash, why would you ever use the less secure crc32() and sha1()?

Crypto usage in PHP is simple, but that doesn’t mean it’s free. First off, depending on the data that you’re encrypting, you might have reasons to store a 32-bit value in the database instead of the 160-bit value to save on space. Second, the more secure the crypto is, the longer is the computation time to deliver the hash value. A high volume site might be significantly slowed down, if frequent md5() generation is required.

Enjoy!

Still more to come.Wait for the next part.You can also subscribe below to receive the next part of "PHP Interview Questions" series directly in your email.

Cheers!



Thursday, May 12, 2016

PHP Interview Questions Part 5

PHP Interview Questions

1. How can we set and destroy the cookie n php?

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


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

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

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

4. 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)

5. What is session_set_save_handler in PHP?

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

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

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

Answer : Case Studio
Smart Draw

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

Answer : 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,
But you cannot execute new query in $db1, even if you
supply 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 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);

9. List out the predefined classes in PHP?

Answer :Directory
stdClass
__PHP_Incomplete_Class
exception
php_user_filter

10. How can I make a script that can be bi-language (supports English, French)?

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 runtime choose the
required language option.

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

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

12. How can we send mail using JavaScript?

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

13. 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 given it will create index row by row.

14. What are the advantages of stored procedures, triggers, indexes?

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

15. What is the maximum length of a table name, database name, and fieldname 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:

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

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

Answer :describe Table-Name;

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

19. What is the purpose of the following files having extensions
 1) .frm
 2) .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.

20. What is maximum size of a database in MySQL?

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

Saturday, May 7, 2016

PHP Interview Questions Part 4

PHP Interview Questions and Answers

1. How do you call a constructor for a parent class?

parent::constructor($value)

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

Here are three basic types of runtime errors in PHP:

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

Internally, these variations are represented by twelve different error types


3. What’s the special meaning of __sleep and __wakeup?

__sleep returns the array of all the variables than need to be saved, while __wakeup retrieves them.


4. Would you initialize your strings with single quotes or double quotes?

Since the data inside the single-quoted string is not parsed for variable substitution, it’s always a better idea speed-wise to initialize a string with single quotes, unless you specifically need variable substitution.How can we extract string ‘abc.com ‘ from a string http://info@abc.com 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];

5. 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?

Anwser 1:

When we submit a form, which has the GET method it displays pair of name/value used in the form at the address bar of the browser preceded by url. Post method doesn’t display these values.

Anwser 2:

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 100 character you can use POST method.

Once most important difference is when you are sending the form with GET method. You can see the output which you are sending in the address bar. Whereas if you send the form with POST” method then user can not see that information.

Anwser 3:

What are “GET” and “POST”?

GET and POST are methods used to send data to the server: With the GET method, the browser appends the data onto the URL. With the Post method, the data is sent as “standard input.”

Major Difference

In simple words, in POST method data is sent by standard input (nothing shown in URL when posting while in GET method data is sent through query string.

Ex: Assume we are logging in with username and password.

GET: we are submitting a form to login.php, when we do submit or similar action, values are sent through visible query string (notice ./login.php?username=…&password=… as URL when executing the script login.php) and is retrieved by login.php by $_GET[username] and $_GET[password].

POST: we are submitting a form to login.php, when we do submit or similar action, values are sent through invisible standard input (notice ./login.php) and is retrieved by login.php by $_POST[username] and $_POST[password].

POST is assumed more secure and we can send lot more data than that of GET method is limited (they say Internet Explorer can take care of maximum 2083 character as a query string).

Anwser 4:

In the get method the data made available to the action page ( where data is received ) by the URL so data can be seen in the address bar. Not advisable if you are sending login info like password etc. In the post method the data will be available as data blocks and not as query string in case of get method.

Anwser 5:

When we submit a form, which has the GET method it pass value in the form of query string (set of name/value pair) and display along with URL. With GET we can a small data submit from the form (a set of 255 character) whereas Post method doesn’t display value with URL. It passes value in the form of Object and we can submit large data from the form.

Anwser 6:

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

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

GET method is mostly used for submitting a small amount and less sensitive data. POST method is mostly used for submitting a large amount or sensitive data.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() is a function for variable management. It will make a variable undefined.How come the code works, but doesn’t for two-dimensional array of mine?

Any time you have an array with more than one dimension, complex parsing syntax is required. print “Contents: {$arr[1][2]}” would’ve worked.How can we register the variables into a session?

session_register($session_var);

$_SESSION[var] = ‘value’;

6. What is the maximum length of a table name, a database name, or a field name in MySQL?

Database name: 64 characters

Table name: 64 characters

Column name: 64 characters

7. What is the difference between characters 23 and x23?

The first one is octal 23, the second is hex 23.

8. With a heredoc syntax, do I get variable substitution inside the heredoc contents?

Yes.

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

We can create MySQL database with the use of mysql_create_db($databaseName) to create a database.

10. I am writing an application in PHP that outputs a printable version of driving directions. It contains some long sentences, and I am a neat freak, and would like to make sure that no line exceeds 50 characters. How do I accomplish that with PHP?

On large strings that need to be formatted according to some length specifications, use wordwrap() or chunk_split().

11. What’s the output of the ucwords function in this example?

$formatted = ucwords(“LEARNPHPEASY IS COLLECTION OF INTERVIEW QUESTIONS”);

print $formatted;

What will be printed is LEARNPHPEASY IS COLLECTION OF INTERVIEW QUESTIONS.

ucwords() makes every first letter of every word capital, but it does not lower-case anything else. To avoid this, and get a properly formatted string, it’s worth using strtolower() first.

12. How can we extract string “abc.com” from a string “mailto:info@abc.com?subject=Feedback” using regular expression of PHP?

$text = “mailto:info@abc.com?subject=Feedback”;

preg_match(‘|.*@([^?]*)|’, $text, $output);

echo $output[1];

Note that the second index of $output, $output[1], gives the match, not the first one, $output[0].So if md5() generates the most secure hash, why would you ever use the less secure crc32() and sha1()?

Crypto usage in PHP is simple, but that doesn’t mean it’s free. First off, depending on the data that you’re encrypting, you might have reasons to store a 32-bit value in the database instead of the 160-bit value to save on space. Second, the more secure the crypto is, the longer is the computation time to deliver the hash value. A high volume site might be significantly slowed down, if frequent md5() generation is required.

 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

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

Sorting functions in PHP:

asort()

arsort()

ksort()krsort()

uksort()

sort()

natsort()

rsort()

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

2 ways:

a) sizeof($array) – This function is an alias of count()

b) count($urarray) – This function returns the number of elements in an array.

Interestingly if you just pass a simple var instead of an array, count() will return

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

At least 3 ways:

1. Put the variable into session in the first page, and get it back from session in the next page.

2. Put the variable into cookie in the first page, and get it back from the cookie in the next page.

3. Put the variable into a hidden form field, and get it back from the form in the next page.


Monday, April 25, 2016

Plus One Mathematics Revision Questions

Last updated on 03.09.2015: ??? ?????????? ?????? ??? ?????????????? ???????? ???????????? ??????????????. SCERT ??????????????? ?????? ????????????? 18 ????????? ????????? ??????????? ??????? ?????????????????. ????? ???????????? ????????????? ???????? ???????? ?????? ??? ??????????????????? ??? ?????????????? ?????????? ???????????, ???????????, ??? ?????????? ?????? ????? ??????????????????????????.
??? ?????????? ???????????? ???????????? ? ????????????? ???????? ?????? ?????????????? ???? ?????????????? ??? . ????????? ????????? ????????? ??????? ????? ??????????? ??????? ??????????? ????.?????? ????? ??.??. ,???????? ????????? ?????????????? ??????? ????? ??????????? ??????? ?????????? ???? ??????? ,?????? ???????????? ??.?? ????? ??????????? ??????? ?????????? ?????? ??. ??. ,?????????? ???????????????? The Centre for Future Studies -??? ???????????  ?????? ?????????   ?????????? ????????? ????????????????????.

?????? ?????????? ??????? ?????? ????????? ??????????? ??????????? ??????????? ?????? ???. ??? ?????????? ??????????? ???????? ????????? ?????? ??? ??????.??????? ???? ??????? ??????? ?????? ????????????? ?????? ??????. ???????? ???????????? ?????? ????????????, ?????????? ????? ???????? ? ????????? ???? ??????????????? ??????????. ??????????????? ????? ????? ???????????? ?????????????. ?????????????? ???????????????? ???????? ?????????????? ??????? ?????????????????. ????????????? ?????????????? ??????????? ??? ??????????? ?????????? ????????????????????.
Plus One Maths Study Materials by Anoop Kumar M.K
Multiple Choice Questions(Plus one Mathematics)
Plus One Mathematics Revision Questions
Plus One Maths Tool Kit
Plus One Maths Study Materials by Nisha Vinod
101 Plus One Mathematics Objective Questions by Nisha Vinod 
Plus One Maths Study Materials by Salini V.L
100 Plus One Mathematics Objective Questions by Salini V.L
Plus One Maths Study Materials by Remesh Chennessery
Plus One Mathematics Objective Questions(SET) by Remesh
Plus One Mathematics Notes (Trigonometry) by Remesh
Plus One Model Question Papers
Plus One Mathematics Model Question(First Term) by Remesh Chennessery
Plus One Mathematics Model Question-1 by Remesh Chennessery
Plus One Mathematics Model Question-2 by Remesh Chennessery
Plus One Mathematics Model Question by SCERT
Plus Two Model Question Papers and Study Notes
Plus Two Mathematics Model Question Paper and Study Notes


Sunday, March 27, 2016

Plus One Plus Two Mathematics Previous Questions 2006 2015

2006 ???????? ?????? ???? 2015 ?? ?????? ???????? ?????? ?????? ??? ??? ?????????? ???? ????????? (chapterwise) ????????? ???????? ????? ?????????????????. ??? ?????????? ???????????? ??????, ?????? ????? ??????? ??????????? ?????????????? ????????? ???????? ?????????? ???? ????????? ?????? ?????????? ????? ??? ????????????? ????????? ??????????????. ?????? ???????????? ??????? ????????????? ??????? ?????? ???????? ?????????????? ???? ????????? ??????????? ????????????????????? ????? ??????????????? ?????????? ???????????????? The Centre for Future Studies -??? ??????????? ????? ??? ??????????? ????? ??????? ??????????????? ???? ??????????????? ????????? ??????? ?????? ?????????? ?????????. ?????????? ????????? ??????? ????????????????????? ????????????? ????????? ???????????? ???? ?????????? ????????? ?????????????.
Downloads /XII Maths
XII Mathematics Question Bank (Chapter 1 to 3) 
XII Mathematics Question Bank will be updated on receipt..
Downloads /XI Maths
XI Mathematics Question Bank (Chapter 1 and 2) 
XI Mathematics Question Bank will be updated on receipt..
Related Downloads
XII Mathematics Study Materials
XI Mathematics Study Materials
XI Mathematics Revision Questions(Objective)