Wednesday, 7 April 2010

What are the different types of errors in PHP?

Here are three basic types of runtime errors in PHP:

1. Notices: These are trivial, 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 you can change this default behavior.

2. Warnings: These are more serious errors - for example, 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.


Cheers!

How do I find out the number of parameters passed into function?

PHP provides a function name func_num_args() which returns the number of parameters passed in.

for example:

<?phpfunction foo()
{
    
$numargs func_num_args();
    echo 
"Number of arguments: $numargs\n";
}
foo(123);    // Prints 'Number of arguments: 3'?>


Cheers!

How can we get the Uploaded File Information in the Receiving Script?

PHP script can get the uploaded file information through the predefined array called $_FILES. Uploaded file information is organized in $_FILES as a two-dimensional array like:
$_FILES[$fieldName]['name'] - The Original file name on the browser system.
$_FILES[$fieldName]['type'] - The file type determined by the browser.
$_FILES[$fieldName]['size'] - The Number of bytes of the file content.
$_FILES[$fieldName]['tmp_name'] - The temporary filename of the file in which the uploaded file was stored on the server.
$_FILES[$fieldName]['error'] - The error code associated with this file upload.

The $fieldName is the name used in the <INPUT TYPE=FILE, NAME=fieldName>.

Cheers!

What are the MySQL database files stored in system ?

There are 3 type of files stored in system whenever you create a database.

suppose you create a database name like necourse.db

then following files will be created:

Data is stored in newcourse.myd
Table structure is stored in newcourse.frm
Index is stored in newcourse.myi

cheers!

Tuesday, 6 April 2010

How __autoload() does?

Autoload is a new feature introduced in PHP5 that you don't have to explicitly require or include a PHP script file that contains the class being used any more but it will be automatically loaded or included when needed.

For example, with PHP4 you would have to write something like this:

require_once("foo.php"); // foo.php contains the class Foo
myFoo = new Foo();

Every time you need to create an object of some class you have to include/require the particular PHP file
that contains that class.
It can be a challenge to manage the whole lot of include or require lines as well.
That's where the autoload feature of PHP5 kicks in.

Instead of including a particular PHP script every time we need it, we create a very simple function at the beginning of the current file so that PHP automatically knows what file to include when we need a particular class.
For example:
function __autoload($className)
{
    require_once 'includes/classes/'. $className. '.php';
}

$obj1 = new MyNewClass1(); // PHP automatically requires 'includes/classes/MyNewClass1.php'
$obj2 = new MyNewClass2(); // PHP automatically requires 'includes/classes/MyNewClass2.php'

Thursday, 1 April 2010

How to add CSS in drupal?

<?php
 // Repeat this line for every CSS file added. 
drupal_add_css(path_to_theme() . '/example.css', 'theme', 'all', TRUE); 
 // Reassemble the $styles snippet to include the new files. 
$styles = drupal_get_css(); 
?>
Enjoy Drupaling.
Cheers!

What are the Pre-Defined Variables that drupal provides?

Available variables

$base_path:
Returns the base URL path of the Drupal installation. At the very least, this will always default to /.
$breadcrumb:
HTML for displaying the breadcrumbs at the top of the page.
$closure:
Needs to be displayed at the bottom of the page, for any dynamic javascript that needs to be called once the page has already been displayed.
$content:
The HTML content generated by Drupal to be displayed.
$css:
An array of all the CSS files for the current page.
$directory:
The directory the theme is located in, e.g.
themes/garland or themes/garland/minelli.
$feed_icons:
A string of all feed icons for the current page.
$footer_message:
The footer message as defined in the admin settings, also the HTML for the footer region.
$head:
HTML as generated by drupal_get_html_head().
$head_title:
The text to be displayed in the page title.
$header:
HTML for the header region.
$help:
Dynamic help text, mostly for admin pages.
$is_front:
True if the front page is currently being displayed. Used to toggle the mission.
$language:
The language the site is being displayed in.
$layout:
This setting allows you to style different types of layout ('none', 'left', 'right' or 'both') differently, depending on how many sidebars are enabled.
$logo:
The path to the logo image, as defined in theme configuration.
$messages:
HTML for status and error messages, to be displayed at the top of the page.
$mission:
The text of the site mission, empty when display has been disabled in theme settings.
$node
(5.x and after only) If you are in page.tpl.php displaying a node in full page view then $node is available to your template.
$onload_attribute:
(4.7 and older only) Onload tags to be added to the head tag, to allow for autoexecution of attached scripts.
$primary_links (array)
An array containing the links as they have been defined in the phptemplate specific configuration block.
$scripts:
(5.x and after only) HTML to load the JavaScript files and make the JS settings available. Previously, javascript files are hardcoded into the page.tpl.php
$search_box:
True(1) if the search box has been enabled.
$search_button_text:
(4.7 and older only)Translated text on the search button.
$search_description:
(4.7 and older only)Translated description for the search button.
$search_url:
(4.7 and older only)URL the search form is submitted to.
$secondary_links (array):
An array containing the links as they have been defined in the phptemplate specific configuration block.
$sidebar_left:
The HTML for the left sidebar.
$sidebar_right:
The HTML for the right sidebar.
$site_name
The name of the site, empty when display has been disabled in theme settings.
$site_slogan:
The slogan of the site, empty when display has been disabled in theme settings.
$styles:
Required for stylesheet switching to work. This prints out the style tags required.
$tabs:
HTML for displaying tabs at the top of the page.
$title:
Title, different from head_title, as this is just the node title most of the time. Enjoy Drupaling. Cheers!