Insert and Update Record using drupal_write_record()

It saves a record to the database based upon the schema.

you can simply call the new drupal_write_record function telling it what database table to write to and the information to write and the function will do the rest. SO you'll find yourself writing less and less of those long db_query insert and update commands!

Insert Record To Table
This would insert all the data in the $node object into the node database table.

drupal_write_record('node', $node);

Example :
$objFile = new stdClass();
$objFile->uid = $uId;
$objFile->filemime = $arrFile['str_file_mime'];
$objFile->filesize = $arrFile['int_file_size'];
$objFile->status = FILE_STATUS_PERMANENT;
$objFile->timestamp = time();
drupal_write_record('files', $objFile);


Update Record In Table
This would update the node in the node database table with the data in the $node object 
where nid is equal to the $node->nid

drupal_write_record('node', $node, 'nid')


Example :
$strFileExtension = getFileExtension($arrFile['str_orgin_file_name']);
$strFileNewName = $objFile->fid.".".$strFileExtension;
$objFile->filename = $strFileNewName;
$objFile->filepath = $arrFile['str_rel_file_path'].$uId.DIRECTORY_SEPARATOR.$strFileNewName;
drupal_write_record('files', $objFile,'fid');

How to do saved Node and get that node Id

I was trying to create a new node programatically by inserting information in node, I used below snippet.

  Saved Node

  $objNode = new StdClass();
  $objNode->title = utf8_encode($strTitle);
  $objNode->type = 'album_image';
  $objNode->status = 1;
  $objNode->moderate = 0;
  $objNode->promote = 0;
  $objNode->sticky = 0;
  $objNode->revision = 0;
  $objNode->comment = 0;
  $objNode = node_submit($objNode);

  $intTimestamp = time();
  $objNode->uid = $uId;
  $objNode->created = $intTimestamp;
  $objNode->changed = $intTimestamp;
  node_save($objNode);
 

  How to get the nid after node_save() in drupal 6

  Previously node_save() returned the $nid but not anymore... so what do we do? 

  It's simple. You have just saved a variable as your node. in our case we use $objNode 

  intInsertedNodeID = $objNode->nid;

  It is easy to use 

Pass Finnish character to ajax request and get junk character (skandinavian charachters)

I have found some of character passes ajax through php file and get stange output (skandinavian charachters)

I pass data with escape() function [escape(output)]. see in bellow snippet

Passed such string to ajax call:
Klikkaa lisätäksesi
tekstiä

and get result of such string
Klikkaa lis�t�ksesi
teksti�

what's problem occure in this script

var callBackActUrl = "dvk.eirikvae.aum"
var textdata = "text="+escape(output);
jQuery.ajax({
type: "POST",
url: callBackActUrl,
data: textdata,
cache: false,
success:function(responseText){
alert(responseText);

}
});


Solution :
I had read lot of artical on google and find solution for. I passed data in ajax using escape function, we replaced escape() function with
encodeURIComponent() and it is working proper.

var textdata = "text="+encodeURIComponent(output);

This method will encode certain chars that would normally be recognized as special chars for URIs.

How to disable resizable textarea in drupal

I am using the profile module but I remove the resizable textarea on the frontend of website.

There doesn't seem to be an option to enable/disable in drupal or even profile module so I tried implementing this:

Snippet :

function mymodule_form_alter(&$form,$form_state, $form_id){
if (
$form_id == 'user_register'){
$form['account_information']['profile_address']['#resizable'] = false;
}
}


It should only point to the profile module. I Couldn't find any other the right code.

Magento - Add External Javascript in CMS Static block

Template tags can be used on CMS pages in static blocks and in email templates also

Template tag is special tag, it has text surrounded by double curly braces which has a special meaning to Magento,
for example {{store url=""}}.

Problem :
I have one javascript , "slide_home.js" and want to include in one cms Static Blocks
This javascript file is in root-directory/js/commmon/slide_home.js

Solution : (you can write this line at top of static blocks [tine mce editor] )
/*

*/

learn more from here
http://inchoo.net/ecommerce/magento/magento-cms-syntax-part1/

Magento – Write Sql query

Simple step to execute MySQL query in Magento.
(1) Select SQL :

$objCon = Mage::getSingleton('core/resource')->getConnection('core_write');
$result = $objCon->query('SELECT 'entity_id' FROM 'catalog_product_entity');

if(!$result) {
$rows = $result->fetch(PDO::FETCH_ASSOC);
if(!$rows) {
print_r($rows);
}
}


(2) Insert SQL :

$objCon = Mage::getSingleton('core/resource')->getConnection('core_write');
$objCon->query("insert into table name (fields) values (values) ");

Mage_Cms_Block_Widget_Interface not found

when I was developing Widget of magento in Magento EE version 1.6 . I have spent lot of time behind to fin it out that Mage_Cms_Block_Widget_Interface is not working with Magento EE 1.6 version and got like this "PHP Fatal error: Interface 'Mage_Cms_Block_Widget_Interface' not found."

After I got information about this interface that It moved Mage_Cms_Block_Widget_Interface to Mage_Widget_Block_Interface in Magento EE version 1.6