Wednesday, September 28, 2011

Difference between MySQL DELETE and MySQL TRUNCATE

DELETE deletes row by row, while TRUNCATE deletes all rows at once.

For example:
DELETE * FROM table WHERE status =0;
TRUNCATE table;

MySQL DB Engines.

List of MySQL DB engines,
MyISAM - Default database engine. Table-Level locking mechanism. Doesn't support transactions. consume less disk space. speedy read operations,so popular for Web development
InnoDB - Row level locking mechanism. Transaction-safe (commit, rollback, and crash recovery capabilities). consume more disk space. Slower than the MyISAM engines.
ISAM - ISAM performs very fast read operations. Doesn't support transactions. If your hard drive crashes, the data files will not be recovered.
Memory (Heap) - HEAP allows for temporary tables that reside only in memory. Residing in memory makes HEAP faster than ISAM or MyISAM. Its volatile and will be lost if it's not saved prior to shutdown.
Archive - Stores very large volumes of infrequently-or-never updated information
Merge - The MERGE engine type allows you to combine a number of identical tables into a single table.
Federated - Accesses data in tables of remote databases. No data is stored on the local tables
NDB Cluster - For distributed computing environment(running several MySQL servers in a cluster).
CSV - Data from any CSV engine file can easily be imported into any standard spreadsheet.
BDB (Berkeley DB) - Each BDB table is stored on disk in two files. The files have names that begin with the table name and have an extension to indicate the file type. An .frm file stores the table format, and a .db file contains the table data and indexes. To support transaction rollback, the BDB storage engine maintains log files

Mail function arguments in PHP

mail($to, $subject, $body);

States in Ajax

Ajax response having 0 to 4 states,
0 = uninitialized,
1 = loading,
2 = loaded,
3 = interactive,
4 = complete

Write conditional statement in CSS

We can insert CSS code based on browser version.


Line break in CSS

Use display:block style with span. For example,

Destroy a session in PHP

We can destroy session in php in two ways. If you wish to delete some session data, you can use the unset() or the session_destroy() function. The unset() function is used to free the specified session variable

XHTML Syntax Rules

Attribute names must be in lower case

Attribute values must be quoted

Attribute minimization is forbidden

The XHTML DTD defines mandatory elements

Inheritance in PHP

It doesn't support multiple inheritence.PHP supports Multi-level inheritance. But using interface we can achieve multiple inheritance in PHP

Tuesday, September 27, 2011

Advantages of InnoDB and MyISAM

Advantages of InnoDB over MyISAM:
Row-level locking, transactions, foreign key constraints and crash recovery

Advantages of MyISAM over InnoDB:
Disk space management
All data except for TEXT and BLOB can occupy 8,000 bytes at most
No full text indexing is available for InnoDB
COUNT(*)s execute slower than in MyISAM due to tablespace complexity

How to create a copy of the database in MySQL in command line?

You can create a copy of mysql database using mysqldump command line.
mysqldump -h mysqlhost -u username -p mydatabasename > dbdump.sql

Hook functions in Drupal 6.

hook_access->Define access restrictions.

hook_auth->Verify authentication of a user.

hook_block->Declare a block or set of blocks.

hook_comment ->Act on comments.

hook_cron->Perform periodic actions.

hook_db_rewrite_sql ->Add JOIN and WHERE statements to queries and decide whether the primary_field shall be made DISTINCT. For node objects, primary field is always called nid. For taxonomy terms, it is tid and for vocabularies it is vid. For comments, it is cid. Primary...

hook_delete->Respond to node deletion.

hook_elements->Allows modules to declare their own form element types and specify their default values.

hook_exit->Perform cleanup tasks.

hook_file_download ->Allow file downloads.

hook_filter->Define content filters.

hook_filter_tips->Provide tips for using filters.

hook_footer->Insert closing HTML.

hook_form->Display a node editing form.

hook_form_alter->Perform alterations before a form is rendered. One popular use of this hook is to add form elements to the node form.

hook_help->Provide online user help.

hook_info->Declare authentication scheme information.

hook_init->Perform setup tasks.

hook_insert->Respond to node insertion.

hook_install->Install the current version of the database schema.

hook_link->Define internal Drupal links.

hook_load->Load node-type-specific information.

hook_menu->Define menu items and page callbacks.

hook_nodeapi ->Act on nodes defined by other modules.

hook_node_grants->Grant access to nodes.

hook_node_info->Define the human-readable name of a node type.

hook_perm->Define user permissions.

hook_ping->Ping another server.

hook_prepare ->This is a hook used by node modules. It is called after load but before the node is shown on the add/edit form.

hook_search->Define a custom search routine.

hook_search_preprocess->Preprocess text for the search index.

hook_settings->Declare administrative settings for a module.

hook_submit->This is a hook used by node modules. It is called after validation has succeeded and before insert/update. It is used to for actions which must happen only if the node is to be saved. Usually, $node is changed in some way and then the actual saving of...

hook_taxonomy->Act on taxonomy changes.

hook_update->Respond to node updating.

hook_update_index->Update Drupal's full-text index for this module.

hook_update_N->Perform a single update. For each patch which requires a database change add a new hook_update_N() which will be called by update.php.

hook_user->Act on user account actions.

hook_validate ->Verify a node editing form.

hook_view->Display a node.

hook_xmlrpc->Register XML-RPC callbacks.

module_hook->Determine whether a module implements a hook.

module_implements->Determine which modules are implementing a hook.

module_invoke->Invoke a hook in a particular module.

module_invoke_all->Invoke a hook in all enabled modules that implement it.

Default files in themes folder

List of the files have to create when we create a custom theme.

1.info file

2.style.css

3.page.tpl.php

4.node.tpl.php

5.block.tpl.php

6.logo.png

7.screenshot.png

Is CSS case sensitive?

Cascading Style Sheets (CSS) is not case sensitve. However, font families, URLs to images, and other direct references with the style sheet may be.
If your page having an XML declaration and an XHTML DOCTYPE then the CSS selectors will be case-sensitive for some browsers, if your page having a HTML DOCTYPE then your CSS selectors will be case-insensitive.
It is a good idea to avoid naming classes where the only difference is the case, for example:
div.myclass { ...}
div.myClass { ... }

What is XHTML?

XHTML stands for EXtensible HyperText Markup Language

XHTML is almost identical to HTML 4.01

XHTML is a stricter and cleaner version of HTML

XHTML is HTML defined as an XML application

XHTML is a W3C Recommendation

Can i have two or more actions in the same form?

No. A form must have exactly one action. However, the server-side (e.g., CGI) program that processes your form submissions can perform any number of tasks (e.g., updating a database, sending email, logging a transaction) in response to a single form submission.

Template function in Drupal

function phptemplate_body_class($left_top, $left_bottom, $right) - Sets the body-tag class attribute.

function phptemplate_comment_wrapper($content, $node) - Allow themable wrapping of all comments.

function phptemplate_preprocess_page(&$vars) { - Override or insert PHPTemplate variables into the templates.

function phptemplate_breadcrumb($breadcrumb) {

function fastlivemail_menu_tree($tree) {

function fastlivemail_menu_item_link($link) {

function fastlivemail_menu_item($link, $has_children, $menu = '', $in_active_trail = FALSE, $extra_class = NULL) {

function fastlivemail_button($element) {

function fastlivemail_tablesort_indicator($style) {

function phptemplate_get_ie_styles() { - Generates IE CSS links for LTR and RTL languages.

Monday, September 26, 2011

Drupal AHAH Delete button not working properly

1) Click on create content
2) Upload an image
3) and press Delete button

This causes the form to submit, instead of doing the ajax call, and the item is not deleted.
Seems that when you upload an image, the image_upload_js function rebuilds the form, and the ahah of the Delete button does not work.
You can check this because after uploading an image the class of the Delete button isclass="form-submit" instead of class="form-submit ahah-processed".

When the form is fully submitted, then the Delete button class is class="form-submit ahah-processed" and it works.

Maybe the del button ahah content doesn't work if it hasn't been initialized in the $(document).ready because it didn't exists in the .ready event.
Perhaps loading initially the button as "hidden" may be a solution ?

Ans:

Before sending the response to JSON...Add the following lines...
==========
// AHAH is not being nice to us and doesn't know the "other" button (that is,
// either "Upload" or "Delete") yet. Which in turn causes it not to attach
// AHAH behaviours after replacing the element. So we need to tell it first.

// Loop through the JS settings and find the settings needed for our buttons.
$javascript = drupal_add_js(NULL, NULL);
$filefield_ahah_settings = array();
if (isset($javascript['setting'])) {
foreach ($javascript['setting'] as $settings) {
if (isset($settings['ahah'])) {
foreach ($settings['ahah'] as $id => $ahah_settings) {
if (strpos($id, 'ahah-more') || strpos($id, 'ahah-remove')) {
$filefield_ahah_settings[$id] = $ahah_settings;
}
}
}
}
}

// Add the AHAH settings needed for our new buttons.
if (!empty($filefield_ahah_settings)) {
$output_settings = 'jQuery.extend(Drupal.settings.ahah, '. drupal_to_js($filefield_ahah_settings) .');';
}

File field and AHAH button not working together in dynamic form

I faced some problem with file filed and AHAH button both together. But File field and AHAH button not working together.
For some reason, file uploads don't like drupal_json() with its manual setting of the text/javascript HTTP header. So use this one instead.

Solution:
==========
Instead of using
"drupal_json(array('status' => TRUE, 'data' => $output));"
need to use
" print drupal_to_js ( array ( 'status' => TRUE, 'data' => $output ) ); exit "

First uploaded picture not overwrite when resubmit the user picture

1. Upload a user picture
2. delete the picture
3. resubmit another picture.

Error: The first picture was not replaced.

delete all caching mechanisms (Website/browser) and retry.

Ans:

We can't change the core module(user.module). So we can change in hook_user. May be this will get error when we upgrade the version.

Another way to change the user picture.

Use hook_user function, in switch case, rename the file path with timestamp and update user table as same file path

Example:

function hook_user($op, &$edit, &$account, $category = NULL) {
switch($op){
case 'after_update':
case 'after_update':
$old_filename = $account->picture;
$filename = basename($account->picture);
$fileArray = explode('.', $filename);
$finalFilename = $fileArray[0].'-'.time().'.'.$fileArray[1];
$pictureArray = explode('/', $account->picture);
$pictureArray[count($pictureArray)-1]=$finalFilename;
$picturePath = implode('/', $pictureArray);
$account->picture = $picturePath;
rename($old_filename, $picturePath);
db_query("UPDATE users SET picture='$picturePath' WHERE uid=%d", $account->uid);
break;
}
}

This will work.

Safari CSS Hack code

I tried to fix safari CSS issue. I found one code,

body { margin-top: 15px; }
/* Safari Hack CSS */
@media screen and (-webkit-min-device-pixel-ratio:0) {body { margin-top: 10px; }}

This will affect the CSS style for only safari browsers.

Drupal 6 Schema

Drupal Schema API allows to declare their database tables in a structured array. And provides API functions for creating, dropping, and changing tables, columns, keys, and indexes in a table.


Create "module.install" file under the module.

Create the following hook function to add schema,

hook_schema()
hook_install()
hook_uninstall()

// Define a table
function hook_shema(){
// Define table array
For example:
$schema['node'] = array(
'fields' => array(
'nid' => array(
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
'description' => t('Primary Key'),
),
'status' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'description' => t('Status.'),
),
),
'primary key' => array('nid'),
);
}

// Install all the tables while enable the module form list
function hook_install() {
drupal_install_schema(hook);
}

// Drop the all tables while uninstall the module
function hook_uninstall() {
drupal_uninstall_schema(hook);
}

// Add one row to table
drupal_write_record(table_name, $record_object);

// Update a row in a table
drupal_write_record(table_name, $record_object, primary_key);

Show CSS Light Box Alert When Disable Javascript

Show the lightbox when browser disables javascript. This attachment includes HTML and CSS code.

Steps to Implement:

Copy styles and

Drupal 6 Installation Profile

Installation profiles combine provide site features and functions for a specific type of site as a single download containing Drupal core, contributed modules, themes, and pre-defined configuration. Once installed, installation profiles can be configured and customized the same as traditionally-built Drupal sites. It will help to create new drupal instance
with minimum requirements.

Profile folder name: root/profiles/new-profile

Create the following files/folders under profiles folder(new-profile):
modules - folder
themes - folder
new-profile.profile - file

Inside this new-profile.profile file , you will write the following hook_profile_funcs().

• new-profile_profile_modules() - Core, Contributed and customized modules
to be enabled when this profile is installed
• new-profile_profile_details() - description of the profile for the
initial installation screen
• new-profile_profile_tasks() - list of tasks that this profile supports
(functions, initial database changes).

List of Modules in Drupal 6

The following module list are using in Durpal 6.
1. Core - Mandatory
System
User
Node
Block
Filter
2. Core - Optional
Aggregator
Blog
Forums
Profile
Comments
Locale
Help
Throttle
Search
Upload
Update
etc.,
3. Contributed Modules
Image
CCk
Views
Date
Filefield
FCKEditor
Thickbox
etc.,
4. Custom modules
User can create custom modules and use.

Friday, September 23, 2011

How to configure php.ini file settings in PHP code?

You can use ini_set() function to change the php.ini file configuration variables. init_set(variable, value);

List of possible variable can change using ini_set() function.
SMTP
smtp_port
sendmail_from
max_execution_time
display_errors
memory_limit
upload_max_filesize
max_input_time
error_reporting
etc...

For example:
ini_set('max_execution_time', 120);