• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Drupal 7 database api
 

Drupal 7 database api

on

  • 4,455 views

Drupal 7 database API

Drupal 7 database API

Statistics

Views

Total Views
4,455
Views on SlideShare
3,866
Embed Views
589

Actions

Likes
1
Downloads
42
Comments
0

12 Embeds 589

http://druler.com 495
http://127.0.0.1 62
http://simbioz.ua 15
http://www.druler.com 3
http://erpua.net 3
http://www.simbioz.ua 3
http://drupal1710.rssing.com 2
http://simbioz.com.ua 2
url_unknown 1
http://translate.googleusercontent.com 1
http://www.slideshare.net 1
http://www.simbioz.com.ua 1
More...

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

CC Attribution-ShareAlike LicenseCC Attribution-ShareAlike License

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Drupal 7 database api Drupal 7 database api Presentation Transcript

    • Drupal 7Database API Andriy Podanenko a.podanenko@simbioz.com.ua
    • Server configurationPHP 5.0+ (5.3+ recommended)php5-pdophp5-pdo_mysqlphp5-pdo_pgsqlphp5-pdo_sqlitemysql, postgres…Apache1.3+ (or php cgi enabled web server)
    • The start…php.net/pdo<?phpabstract class DatabaseConnection extends PDO…// Drupal fun…// Because the other methods dont seem to work right.$driver_options[PDO::ATTR_ERRMODE] = PDO::ERRMODE_EXCEPTION;
    • Class Hierarhy abstract class DatabaseConnection extends PDO…DatabaseConnectionDatabaseConnection::select db_select (SelectQuery)DatabaseConnection::delete db_delete (DeleteQuery)DatabaseConnection::update db_update (UpdateQuery)DatabaseConnection::query db_query (DatabaseStatementInterface)DatabaseConnection::insert db_insert (InsertQuery)DatabaseConnection::merge db_merge (MergeQuery)…
    • DatabaseStatementInterface• execute ($args=array(), $options=array())• fetchAllAssoc ($key, $fetch=NULL)• fetchAllKeyed ($key_index=0, $value_index=1)• fetchAssoc ()• fetchCol ($index=0)• fetchField ($index=0)• getQueryString ()• rowCount () (UPDATE, DELETE, INSERT only)
    • Query interface hierarchy
    • db_selectSELECT name,description FROM taxonomy_term_data AS ttdWHERE tid LIKE 79<?php //Drupal$result = db_select(taxonomy_term_data, ttd);//returned SelectQuery$ret = $result -> fields(ttd, array(name, description));//returned SelectQueryInterface$ret = $result -> condition(tid, 79, like);// returned QueryConditionInterface$ret = $result -> execute(); // returned SelectQuery object$data = $ret -> fetchAll(); // fetched data as object from database
    • Other database (target)$result = db_select(taxonomy_term_data, ttd,array(target => slave));// adding other database at runtimeDatabase::addConnectionInfo(default, slave, array(database => ‘other_db,username => ‘name, password => pass,host => localhost, port => 5432,driver => pgsql));
    • DatabaseTransaction (innodb,pgsql)<?phpfunction demo_transaction()$temp = db_transaction();db_update… // charging account1 +100$db_update… // charging account2 -100$db_insert… // creating log entry for thatreturn TRUE; // automatically commit (no $temp)} //
    • $error->handle  try{} catch{}<?phpfunction demo_transaction()$temp = db_transaction();try {db_insert… // some ugly code here…return TRUE; }catch(Exception $e) { $temp->rollback();watchdog(‘demo error, print_r($e, TRUE)}
    • logging -> DatabaseLog$demo_log = new DatabaseLog;$demo_log->start(‘some_key’);db_update…db_select…// Calling functions or any…$demo_log->end(‘some_key’);print_r($demo_log->get(‘some_key’), TRUE);// printed indexed array for all queries…
    • Drupal 6 – dbtng module (backport) drupal.org/project/dbtngdbtng_* (full functions list in dbtng.module)dbtng_querydbtng_set_activedb_select• good for support old sites• multi database setup possibility for Drupal 6• preparing code for upgrade
    • Useful links• api.drupal.org/api/drupal/7• drupal.org/developing/api/database• upgrade.boombatower.com/tools/sql/inline• drupal.org/project/coder• php.net/pdo• drupal.org/project/dbtng• drupal.org/node/310069
    • Drupal DB api->executed();  twitter.com/podarok  facebook.com/podarok  vkontakte.ru/podarokua  a.podanenko@simbioz.com.ua  drupal.org/user/116002  drupal.ua/user/23 http://simbioz.ua