Php Interview Question list 2

Q. How come the code works, but doesn’t for two-dimensional array of mine?
ANSWER: Any time you have an array with more than one dimension, complex parsing syntax is required. print “Contents: {$arr[1][2]}” would’ve worked.

Q. What is the difference between characters 23 and x23?
ANSWER: The first one is octal 23, the second is hex 23.

Q. Would you initialize your strings with single quotes or double quotes?
ANSWER: 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.

Q. With a heredoc syntax, do I get variable substitution inside the heredoc contents? ANSWER: Yes.
I want to combine two variables together:
$var1 = ‘Welcome to ‘;
$var2 = ‘’;
What will work faster? Code sample 1: $var 3 = $var1.$var2;
Or code sample 2: $var3 = “$var1$var2”;
Both examples would provide the same result – $var3 equal to “Welcome to”. However, Code Sample 1 will work significantly faster. Try it out with large sets of data (or via concatenating small sets a million times or so), and you will see that concatenation works significantly faster than variable substitution.

Q. So if md5() generates the most secure hash, why would you ever use the less secure crc32() and sha1()?
ANSWER: 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.

Form More Information 

Php Interview Question list 1

Q. What’s the difference between include and require?
ANSWER: It’s how they handle failures. If the file is not found by require(), it will cause a fatal error and halt the execution of the script. If the file is not found by include(), a warning will be issued, but execution will continue.

Q. What does a special set of tags do in PHP?
ANSWER: The output is displayed directly to the browser.

Q. Would I use print “$a dollars” or “{$a} dollars” to print out the amount of dollars in this example? ANSWER: 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.

Q. How do you define a constant?
ANSWER: Via define() directive, like define (“MYCONSTANT”, 100);

Q. I am trying to assign a variable the value of 0123, but it keeps coming up with a different number, what’s the problem?
ANSWER: PHP Interpreter treats numbers beginning with 0 as octal.

Q. How do you pass a variable by value?
ANSWER: Just like in C++, put an ampersand in front of it, like $a = &$b

Q. When are you supposed to use endif to end the conditional statement?
ANSWER: When the original if was followed by : and then the code block without braces.

Q. Explain the ternary conditional operator in PHP?
ANSWER: Expression preceding the ? is evaluated, if it’s true, then the expression preceding the : is executed, otherwise, the expression following : is executed.

Form More Information 

MySQL Interview Question list

What are some good ideas regarding user security in MySQL? –
There is no user without a password. There is no user without a user name. There is no user whose Host column contains % (which here indicates that the user can log in from anywhere in the network or the Internet). There are as few users as possible (in the ideal case only root) who have unrestricted access.

Explain the difference between MyISAM Static and MyISAM Dynamic. –
In MyISAM static all the fields have fixed width. The Dynamic MyISAM table would include fields such as TEXT, BLOB, etc. to accommodate the data types with various lengths. MyISAM Static would be easier to restore in case of corruption, since even though you might lose some data, you know exactly where to look for the beginning of the next record.
What does myisamchk do?
– It compressed the MyISAM tables, which reduces their disk usage.

Explain advantages of InnoDB over MyISAM? – Row-level locking, transactions, foreign key constraints and crash recovery.

Explain advantages of MyISAM over InnoDB?
– Much more conservative approach to disk space management – each MyISAM table is stored in a separate file, which could be compressed then with myisamchk if needed. With InnoDB the tables are stored in tablespace, and not much further optimization is possible. All data except for TEXT and BLOB can occupy 8,000 bytes at most. No full text indexing is available for InnoDB. TRhe COUNT(*)s execute slower than in MyISAM due to tablespace complexity.

What are HEAP tables in MySQL?
– HEAP tables are in-memory. They are usually used for high-speed temporary storage. No TEXT or BLOB fields are allowed within HEAP tables. You can only use the comparison operators = and . HEAP tables do not support AUTO_INCREMENT. Indexes must be NOT NULL.

How do you control the max size of a HEAP table?
– MySQL config variable max_heap_table_size.

What are CSV tables?
– Those are the special tables, data for which is saved into comma-separated values files. They cannot be indexed.

Explain federated tables.
– Introduced in MySQL 5.0, federated tables allow access to the tables located on other databases on other servers.

Form More Information 

General PHP interview question

1.In how many ways we can retrieve the date in the result set of mysql using PHP?
2.What is the difference between mysql_fetch_object and mysql_fetch_array?
3.What is the difference between $message and $$message?
4.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?
5.Who is the father of PHP and explain the changes in PHP versions?
6.How can we submit a form without a submit button?
7.How can we extract string ‘ ‘ from a string ‘’ using regular expression of PHP?
8.How can we create a database using PHP and mysql?
9.What are the differences between require and include, include_once?
10.How can we encrypt and decrypt a data present in a mysql table using mysql?
11.How can we encrypt the username and password using PHP?
12.What are the features and advantages of object-oriented programming?
13.What are the differences between procedure-oriented languages and object-oriented languages?
14.What is the use of friend function?
15.What are the differences between public, private, protected, static, transient, final and volatile?
16.What are the different types of errors in PHP?
17.What is the functionality of the function strstr and stristr?
18.What are the differences between PHP 3 and PHP 4 and PHP 5?
19.How can we convert asp pages to PHP pages?
20.Can we use include (”techinterviews.php”) two times in a PHP page “makeit.PHP”?
21.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(20)) ?
22.Functions in IMAP, POP3 AND LDAP?
23.How can I execute a PHP script using command line?
24.Suppose your Zend engine supports the mode Then how can u configure your PHP Zend engine to support mode ?

Form More Information 


Replacing Substrings
string substr_replace ( string str, string replacmnt, int start [, int len] )

replace the entire instance (say, by changing the ever-so-clichéd “Hello World!” into the more
“l33t” phrase “H3110 W0r1d!” and hence proving your “l33t” status), you could simply invoke



php program
function searchtext ($haystack, $needle){
if (substr_count ($haystack, $needle) == 0){
echo “No instances were found of this search query”;
} else {
$startpos = 0;
$lookagain = true;
while ($lookagain){
if ($pos = strpos ($haystack, $needle, $startpos)){
echo “The search term \”$needle\” was found at position: $pos “; ….