What are the different functions in sorting an array?How To Read the Entire File into a Single String?How To Turn On the Session Support?How can we create a database using PHP and MySQL ?How can I execute a PHP script using command line?How To Upload the Files to a Table?Explain when to use GET or POST. Provide example for both the ways.Explain the purpose of isset() functions by illustrating an example.What are the different types of Errors in PHP?What are the differences between require and include, include_once?How can we destroy the cookie?What is DDL, DML and DCL ?What are hooks in Drupal ?Can I use Drupal on the command line?What is Drupal ?Which are commonly used PHP based CMSs ?What is a CMS?How can we destroy the cookie?What is MySQL?What is the difference between PHP4 and PHP5? ~ Interview Questions & Answers

Saturday, September 8, 2007

What are the different functions in sorting an array?

Array sorting functions in PHP:
asort()
arsort()
ksort()
krsort()
uksort()
sort()
natsort()
rsort()

Sunday, August 12, 2007

How To Read the Entire File into a Single String?

If you have a file, and you want to read the entire file into a single string, you can use the file_get_contents() function. It opens the specified file, reads all characters in the file, and returns them in a single string.

Friday, August 3, 2007

How To Turn On the Session Support?

The session support can be turned on automatically at the site level, or manually in each PHP page script:
* Turning on session support automatically at the site level: Set session.auto_start = 1 in php.ini.
* Turning on session support manually in each page script: Call session_start() function.

Friday, June 22, 2007

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.

Wednesday, June 13, 2007

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.

How To Upload the Files to a Table?

To store uploaded files to MySQL database, you can use the normal SELECT statement as shown below:
<?php
$con = mysql_connect("localhost", "", "");
mysql_select_db("fyi");
$error = $_FILES['fyicenter_logo']['error'];
$tmp_name = $_FILES['fyicenter_logo']['tmp_name'];
$size = $_FILES['fyicenter_logo']['size'];
$name = $_FILES['fyicenter_logo']['name'];
$type = $_FILES['fyicenter_logo']['type'];
print("
\n");
if ($error == UPLOAD_ERR_OK && $size > 0) {
$fp = fopen($tmp_name, 'r');
$content = fread($fp, $size);
fclose($fp);
$content = addslashes($content);
$sql = "INSERT INTO fyi_files (name, type, size, content)"
. " VALUES ('$name', '$type', $size, '$content')";
mysql_query($sql, $con);
print("File stored.\n");
} else {
print("Upload faield.\n");
}
print("
\n");
mysql_close($con);
?>
Note that addslashes() is used to add backslashes to special characters that need to be protected in SQL statements.

Explain when to use GET or POST. Provide example for both the ways.

Both GET and POST are used to collect data from a form. However, when security is desired $_POST should be used. When the $_ POST variable is used, all variables used are NOT displayed in the URL. Also, they have no restrictions to the length of the variables. GET should be used when the interaction with the form is more like a question. For e.g. firing a query etc. POST should be used more often when the interaction is more like an order or the interaction changes the state of the resource.
POST example:
Name:
Age:
On clicking submit the URL resembles to: http://www.mysamplesite.com/sample.php
The sample.php file can be used for catching the form data using $_POST
Hello <?php echo $_POST["name"]; ?>.
You are <?php echo $_POST["age"]; ?> years old!
GET EXAMPLE
Name:
Age:
On clicking submit the URL resembles to : http://www.mysamplesite.com/sample.php?name=jim&age=37
The sample.php file can be used for catching the form data using $_GET
Hello <?php echo $_GET["name"]; ?>.
You are <?php echo $_GET["age"]; ?> years old!

Explain the purpose of isset() functions by illustrating an example.

isset() function is used to determine if a variable is set or not. It returns true if the variable exists. If multiple parameters are supplied then isset() will return TRUE only if all of the parameters are set.
Example:
$a =”sample”;
var_dump(isset($a)); //true;

Friday, June 8, 2007

What are the different types of Errors in PHP?

There are three basic types of run time errors in PHP:
1. Notices: These are small, 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 the default behavior can be changed.
2. Warnings: Warnings are more severe errors like 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.

Wednesday, June 6, 2007

What are the differences between require and include, include_once?

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.

Sunday, June 3, 2007

How can we destroy the cookie?

Set the cookie time in past.

Monday, March 19, 2007

What is DDL, DML and DCL ?

If you look at the large variety of SQL commands, they can be divided into three large subgroups.

Data Definition Language deals with database schema and descriptions of how the data should reside in the database, therefore language statements like CREATE TABLE or ALTER TABLE belong to DDL.

DML deals with data manipulation, and therefore includes most common SQL statements such SELECT, INSERT, etc.

Data Control Language includes commands such as GRANT, and mostly concerns with rights, permissions and other controls of the database system.

Tuesday, March 6, 2007

What are hooks in Drupal ?

Allow modules to interact with the Drupal core.
Drupal's module system is based on the concept of "hooks". A hook is a PHP function that is named foo_bar(), where "foo" is the name of the module (whose filename is thus foo.module) and "bar" is the name of the hook. Each hook has a defined set of parameters and a specified result type.

To extend Drupal, a module need simply implement a hook. When Drupal wishes to allow intervention from modules, it determines which modules implement a hook and calls that hook in all enabled modules that implement it.

Can I use Drupal on the command line?

Yes, you can use drush –
drush is a command line shell and Unix scripting interface for Drupal

Monday, March 5, 2007

What is Drupal ?

Drupal is an open-source platform and content management system for building dynamic web sites offering a broad range of features and services including user administration, publishing workflow, discussion capabilities, news aggregation, metadata functionalities using controlled vocabularies and XML publishing for content sharing purposes. Equipped with a powerful blend of features and configurability, Drupal can support a diverse range of web projects ranging from personal weblogs to large community-driven sites.

Which are commonly used PHP based CMSs ?

Drupal, Joomla, Wordpress, TYPO3

What is a CMS?

A content management system (CMS) is a collection of procedures used to manage work flow in a collaborative environment. These procedures can be manual or computer-based.
The procedures are designed to:
Allow for a large number of people to contribute to and share stored data
Control access to data, based on user roles. User roles define what information each user can view or edit
Aid in easy storage and retrieval of data
Reduce repetitive duplicate input
Improve the ease of report writing
Improve communication between users
In a CMS, data can be defined as almost anything - documents, movies, pictures, phone numbers, scientific data, etc. CMSs are frequently used for storing, controlling, revising, semantically enriching, and publishing documentation. Content that is controlled is industry-specific. For example, entertainment content differs from the design documents for a fighter jet. There are various terms for systems (related processes) that do this. Examples are web content management, digital asset management, digital records management and electronic content management. Synchronization of intermediate steps, and collation into a final product are common goals of each.

Tuesday, February 13, 2007

How can we destroy the cookie?

Set the cookie time in past.
Example: setcookie('Test',$i,time()-3600); // already expired time

Saturday, February 10, 2007

What is MySQL?

MySQL is a relational database management system (RDBMS) that runs as a server providing multi-user access to a number of databases.

Friday, February 9, 2007

What is the difference between PHP4 and PHP5?

There are several differences between PHP4 and PHP5.
1.Unified constructor and Destructor.
2.Exception has been introduced.
3.New error level named E_STRICT has been introduced.
4.Now we can define full method definitions for an abstract class.
4.Within a class we can define class constants.
5.we can use the final keyword to indicate that a method cannot be overridden by a child
Added features in PHP 5 are the inclusions of visibility, abstract and final classes and methods, additional magic methods, interfaces, cloning and typehinting.