Sunday, December 12, 2010

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

Tuesday, November 30, 2010

How does drupal works?

1. The web server picks the PHP file to run based on the URL That PHP file is (almost) always Drupal core's index.php
2. The PHP file runs. (index.php). It includes a bunch of include files which define helper functions and settings, it connects to the database (which is required) and pulls more settings out of the database, it includes even more files (themes and modules) which define yet more helper functions and callbacks, and finally it decides which function, in all of the combined tens of included files that should be run
3. It calls that function, which is called a "menu callback". This "menu callback" is the first chance that you have to run your own code.
4. Your menu callback runs. It can optionally call PHP standard library functions, include other PHP files for extra functionality, or call any Drupal standard library functions.
5. As the menu callback runs, anything that it outputs is sent to the browser, just like in the raw PHP file case above.
6. But the Drupal Way is for the menu callback to return a string. That string then gets plugged into a template page for the site (which is one component of a theme), and the template page with the string plugged into the right spot gets sent back to the browser.

Advantages & disadvantages of drupal

Advantages of the Drupal way of doing things:

1. It's consistent. For example, if you always use the "correct" way to print out usernames, changing the style of those printed usernames in one place changes them across the entire site.
2. It's integrated.
3. It's convenient.

But there are some disadvantages:

1. It's slow(er).
2. It uses memory.