In how many ways we can retrieve data in the result set of mysql using php?How do you define a constant?How can you access a COM object from a PHP page?How can we know the count/number of elements of an array?How can we get the properties (size, type, width, height) of an image using php image functions?What does a special set of tags <?= and ?> do in PHP?How many ways can we get the value of current session id?How can we increase the execution time of a php script?How can we find the number of rows in a result set using PHP?What are the various methods to pass data from one web page to another web page?How many ways can we get the value of current session id?How to set cookies?How can we know that a session is started or not? ~ Interview Questions & Answers

Monday, June 23, 2008

In how many ways we can retrieve data in the result set of mysql using php?

mysql_fetch_array - Fetch a result row as an associative array, a numeric array, or both
mysql_fetch_assoc - Fetch a result row as an associative array
mysql_fetch_object - Fetch a result row as an object
mysql_fetch_row —- Get a result row as an enumerated array

Sunday, June 22, 2008

How do you define a constant?

Via define() directive, like define ("MYCONSTANT", 100);

How can you access a COM object from a PHP page?

By utilizing the com_load and the dotnet_load respectively
you can incorporate COM objects and .NET libraries into your
PHP code, thus anytime you see "library code" in a question,
make sure you remember these two functions.
com_load — Creates a new reference to a COM component [deprecated]
Deprecated, use the OO syntax instead.
<?php
// do this
$obj = new COM($module);
// instead of this:
$obj = com_load($module);
?>

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

2 ways:
a) sizeof($array_name) - This function is an alias of count()
b) count($array_name) - 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 1.

How can we get the properties (size, type, width, height) of an image using php image functions?

To know the image size use getimagesize() function
To know the image width use imagesx() function
To know the image height use imagesy() function

Wednesday, June 18, 2008

What does a special set of tags do in PHP?

The output is displayed directly to the browser.

Friday, June 13, 2008

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

Using session_id() function, the current value of the session can be found.
Syntax:
String session_id(string $id);

How can we increase the execution time of a php script?

By the use of void set_time_limit(int seconds)
Set the number of seconds a script is allowed to run. If this is reached, the script returns a fatal error. The default limit is 30 seconds or, if it exists, the max_execution_time value defined in the php.ini. If seconds is set to zero, no time limit is imposed.
When called, set_time_limit() restarts the timeout counter from zero. In other words, if the timeout is the default 30 seconds, and 25 seconds into script execution a call such as set_time_limit(20) is made, the script will run for a total of 45 seconds before timing out.

How can we find the number of rows in a result set using PHP?

Here is how can you find the number of rows in a result set in PHP:
$result = mysql_query($any_valid_sql, $database_link);
$num_rows = mysql_num_rows($result);
echo "$num_rows rows found";

Sunday, June 8, 2008

What are the various methods to pass data from one web page to another web page?

Different methods to pass data from one web page to another:
1. Store the data in a session variable. By storing the data, the data can be passed from one page to another.
2. Store data in a cookie: By storing data in a persistent cookie, data can be passed from one form to another.
3. Set the data in a hidden field and post the data using a submit button.

Thursday, June 5, 2008

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

Using session_id() function, the current value of the session can be found.
Syntax:
String session_id(string $id)

Tuesday, June 3, 2008

How to set cookies?

setcookie('variable','value','time');
variable - name of the cookie variable
value - value of the cookie variable
time - expiry time
Example: setcookie('Test',$i,time()+3600);
Test - cookie variable name
$i - value of the variable 'Test'
time()+3600 - denotes that the cookie will expire after an one hour

Syntax:
bool setcookie ( string $name [, string $value [, int $expire = 0 [, string $path [, string $domain [, bool $secure = false [, bool $httponly = false ]]]]]] )

How can we know that a session is started or not?

A session starts by session_start() function.
This session_start() is always declared in header portion. it always declares first. then we write session_register().