Friday, January 11, 2008

FAQ - PHP

1) How can we extract string ‘rajinirobo.com ‘ from a string ‘http://info@rajinirobo.com’ using regular expression of PHP?

preg_match(”/^http:\/\/.+@(.+)$/”,’http://info@rajinirobo.com’,$found);
echo $found[1];

2) In how many ways we can retrieve the data in the result set of MySQL using PHP?

1. mysql_fetch_row.
2. mysql_fetch_array
3. mysql_fetch_object
4. mysql_fetch_assoc

3) What are the different types of table in mysql?

5 types of tables we can create
1. MyISAM
2. Heap
3. Merge
4. INNO DB
5. ISAM

4) Difference between MSSQL server & MYSQL?

MS SQL Server 2005

SQL Server is a full-fledged database system developed specifically for large enterprise databases. All advanced features of a relational database are fully implemented. Once you purchase the product, you are only limited to the Sybase-derived engine.

MySQL 5.x

The latest release of MySQL, the 5.X offering, has rounded up on features that lagged commercial equivalents such as SQL Server. Triggers, stored procedures, Views, Information Schema, Serverside Cursors, and Precision Math are features that are implemented but not yet stabilised.

5) What is the difference between echo and print statement?

Print is a function whereas echo is a language construct.

You can use something link $a = print $b while you cant use $a = echo $b.

Print return true or false value on printing. Echo doesn't

Print cannot have multiple expression whereas Echo can have Multiple Expression statement to echo the value.

6) What is the difference between echo and print statement?

echo() can take multiple expressions,Print cannot take multiple expressions.

echo has the slight performance advantage because it doesn't have a return value.

True, echo is a little bit faster.

Print is a function whereas echo is a language construct.

You can use something link $a = print $b while you cant use $a = echo $b.

7) What do you need to do to improve the performance for the script you have written?

Use EXPLAIN to monitor the amount of records retrieved for each query. You can use UNIQUE, LIMIT, WHERE to filter the no of records returned

8) How to reverse given string?

with function:

strrev()

without function:

for($i=0;sizeof($str_name)>$i;$i++)
{

for($l=1;$i-$l;$l--)
{
echo $str_name;
}

9. How many persons have hit my site?

session_start();
(!isset($_SESSION['count'])){ $_SESSION['count']=0;}
else{ $_SESSION['count']++;}
echo "session".$_SESSION['count'];

10. Will PHP supports inheritance?

Yes, PHP supports single inheritance

11. How do you create subdomains using PHP?

* Create the appropriate web root directory, for example /home/sites/username/web , and any subdirectories you wish
* Edit httpd.conf - add a new virtual host section
* Restart httpd

12. How to get the URL domain name in PHP?

$domainName=$_SERVER['HTTP_HOST'];
echo $domainName;

13. What is the difference between Split and Explode?

split() can work using regular expressions while explode() cannot.