Friday, December 31, 2010

System Requirements for Drupal 7

Required: PHP version 4.4.0 or higher for Drupal 5 and Drupal 6, PHP 5.2.5 or higher for Drupal 7

Drupal 7 will only support MySQL 5.0.15 or higher, and requires the PDO database extension for PHP .

Enable PDO IN PHP ini file



Drupal has been deployed successfully on both Apache and IIS.



Apache (Recommended)



Drupal will work on Apache 1.3 or Apache 2.x hosted on UNIX/Linux, OS X, or Windows. The majority of Drupal development and deployment is done on Apache, so there is more community experience and testing performed on Apache than on other web servers.

You can use the Apache 'mod_rewrite' extension to allow for clean URLs.

Microsoft IIS



Drupal core will work using IIS 5, IIS 6, or IIS 7 if PHP is configured correctly.

To achieve clean URLs you may need to use a third party product. For IIS7 you can use the Microsoft URL Rewrite Module or a third party solution.

When using Drupal on IIS 7 with fastcgi you must install Hotfix kb954946, or wait until the hotfix appears in a package update (recommended). KB954946 was included in Windows 2008 Server SP2

Drupal is being developed to be web server independent, but we have limited or no reports of successful use on web servers not listed here.



The total file size of your Drupal installation will depend on what you add to your site, but Drupal core files alone will take up approximately 2 to 3 MB uncompressed. The exact size depends on the version of Drupal you have installed.

Sunday, December 12, 2010

Get the row count in Drupal 7

<?php

$querystring = db_select('table1')
->fields('users')
->execute()
->rowCount();

?>

Print query in Drupal 7 or Display query in drupal7

<?php

$querystring = db_select('table1')
->fields('table1')
->execute()
->getQueryString();
echo $querystring;

Or

$querystring = db_select('table1')
->fields('table1');
echo $querystring;

?>

Transaction & rollback query in Drupal 7



<?php
$transaction = db_transaction();
try{
//operation on a multiple table 
//blah blah
}catch (Exception $e) {
  $transaction->rollback('testtable', $e->getMessage(), array(), WATCHDOG_ERROR);
}
?>

Standardized Query to delete an record in Drupal 7


db_delete('table1')
->condition('uid', 1)
->execute();

?>

Standardized Query to update an record in Drupal 7

db_update('table1')
->fields(array(
'status' => 1,
'weight' => 1,
'region' => 'left',
))
->condition('module', 'table1')
->condition('delta', 1)
->condition('theme', 'Garland')
->execute(

Standardized Query to insert an record in Drupal 7

db_insert('tablename')
->fields(array(
'field1' => 'mystring',
'field2' => 5,
))
->execute();
?>

Standardized Query to select record with join in Drupal 7


$query = db_select('comment', 'c');
$query->innerJoin('node', 'n', 'n.nid = c.nid');
$query->innerJoin('node_comment_statistics', 'ncs', 'ncs.nid = c.nid');
$query->addTag('node_access');
$comments = $query
->fields('c')
->condition('ncs.comment_count', 0, '>')
->condition('c.status', COMMENT_PUBLISHED)
->condition('n.status', NODE_PUBLISHED)
->orderBy('ncs.last_comment_timestamp', 'DESC')
->orderBy('c.cid', 'DESC')
->range(0, $number)
->execute()
->fetchAll();

?>

Adds a tag to a query.
Tags are strings that identify a query. A query may have any number of tags. Tags are used to mark a query so that alter hooks may decide if they
wish to take action. Tags should be all lower-case and contain only letters,numbers, and underscore, and start with a letter. That is, they should follow the same rules as PHP identifiers in general.

Standardized Query to select record with condition & order by in Drupal 7


$users = db_select('users')
->fields('users')
->condition('name', db_like('admin'), 'LIKE')
->condition('status', 1)
->orderBy('name')
->execute()
->fetchAll();

foreach($users as $key=>$value){
echo $value->uid.",";
}

?>
outputs like(displays uid) : 1

Standardized Query to select all records from a table in Drupal 7


$users = db_select('users')
->fields('users')
->execute()
->fetchAll();

foreach($users as $key=>$value){
echo $value->uid.",";
}

?>
outputs like : 0,1,..

Basic Query to retrive,update & delete any records in Drupal 7

Retreive Record
--------------
$actions = db_query('SELECT * FROM {users}')->fetchAll();

foreach ($actions as $action) {
echo $action->uid;
}
?>
Displays uid

Update Record
---------------
Similar to Drupal6
db_query("UPDATE {node} SET title = 'Kumaresanfgh' WHERE nid =2");
?>

Delete Record
--------------
Similar to Drupal6
db_query("DELETE FROM {node} WHERE `nid` =2");
?>

Insert a Record
---------------
Similar to Drupal6
db_query("INSERT INTO {TABLE} (`source` ,`alias` ,`language`)VALUES ('sdsd', 'sdsd', 'dsdsd')");
?>

What databases does PDO support?

PDO supports many of the popular databases as seen on the list below.
DBLIB: FreeTDS / Microsoft SQL Server / Sybase
Firebird (http://firebird.sourceforge.net/): Firebird/Interbase 6
IBM (IBM DB2)
INFORMIX - IBM Informix Dynamic Server
MYSQL (http://www.mysql.com/): MySQL 3.x/4.0
OCI (http://www.oracle.com): Oracle Call Interface
ODBC: ODBC v3 (IBM DB2 and unixODBC)
PGSQL (http://www.postgresql.org/): PostgreSQL
SQLITE (http://sqlite.org/): SQLite 3.x

Drupal7 Database connection

Drupal7 has used PDO for database connection .PDO is noting but PHP data objects.
PDO is a PHP extension to formalise PHP's database connections by creating a uniform interface. This allows developers to create code which is portable across many databases and platforms. PDO is _not_ just another abstraction layer like PearDB although PearDB may use PDO as a backend. Those of you familiar with Perls DBI may find the syntax disturbingly familiar.

What is RDFa

RDFa (or Resource Description Framework – in – attributes) is a W3C Recommendation that adds a set of attribute level extensions to XHTML for embedding rich metadata within Web documents. The RDF data model mapping enables its use for embedding RDF triples within XHTML documents, it also enables the extraction of RDF model triples by compliant user agents.

DRUPAL 7 IN XHTML+RDFa1.0

DRUPAL 6 is based on XHTML Whereas Drupal 7 is in XHTML+RDFa1.0