I attend first interview the following questions were asked by interviewer
1. What is the difference between mysql_fetch_object and mysql_fetch_array?
mysql_fetch_object : will return the results from database as objects. fields will be accessible like in objects i.e $result->name,$result->cust_name
mysql_fetch_array : will return the results from database as an array.The array will be in in associative as well as numeric manner. i.e $result['column_name'] or $result[0].here '0'indicates first column in table
2.difference between print and echo in php
One difference is that echo() can take multiple expressions:
phpPrint cannot take multiple expressions. That is the main distinct difference!
echo "The first", "the second";
?>
3.What is the difference between mysql_connect and mysql_pconnect ? Which one is good in terms of performance ?
mysql_connect opens a normal connections to mysql database.mysql_pconnect opens a persistant connection i.e. if there is any connection open in the script it will use that connection not making a new connection each time.at very high traffic enviornment mysql_connect provides better performance.
4.Types of Arays in php
In PHP, there are two types of Arrays. A Numerical or an Indexed Array and the other is an Associative Array.
In Numerical or an Indexed Array, the indexer of the array which is used to determine the position (also known as Key) of the stored data element is an integer which begins at zero. Consider this example:
| Position in Array | Name |
|---|---|
| 0 => | TCP |
| 1 => | IP |
| 2 => | DNS |
| 3 => | HTTP |
| 4 => | FTP |
| 5 => | SMTP |
In the left column, we are displaying the position of the name of the protocol that is on the right hand side. The position is an integer and is starting at zero. So, if you were to retrieve the name of the protocol which is at 4th position, then the Array will return 'FTP' and not 'HTTP'. In this way PHP uses integers as indexers or the key to store and determine the position of the data element in the Array. So how is it different from an Associative array?
In Associative array, the key or the indexer of the array which is used to refer to the data element is a string and not an integer. Consider this example:
| Abbreviation | Expanded Term |
|---|---|
| TCP => | Transmission Control Protocol |
| IP => | Internet Protocol |
| DNS => | Dynamic Naming System |
| HTTP => | Hyper Text Transfer Protocol |
| FTP => | File Transfer Protocol |
| SMTP => | Simple Mail Transfer Protocol |
In the above example as you can see, we have used strings and not integers to determine the position of the data elements. So, if we query the array for the data element which is stored at the position of 'SMTP' (our key for the data element), the array will return 'Simple Mail Transfer Protocol'.
No comments:
Post a Comment