コード例 #1
0
ファイル: edit.php プロジェクト: arjaneising/My-Movie-List
 public function Delete($get)
 {
     if (isset($get['id']) && is_numeric($get['id'])) {
         $db = new MDB();
         $result = $db->deleteMovie($get['id']);
         if ($result) {
             header('Location: ./?message=delete-success');
         } else {
             header('Location: ./?message=delete-error');
         }
         exit;
     } else {
         header('Location: ./?message=request-error');
         exit;
     }
 }
コード例 #2
0
 function Step2()
 {
     if (isset($_POST['movie-id']) && is_numeric($_POST['movie-id']) && isset($_POST['original-title']) && strlen($_POST['original-title']) > 1 && isset($_POST['english-title'])) {
         $db = new MDB();
         $success = $db->editTitles($_POST['movie-id'], $_POST['original-title'], $_POST['english-title']);
         if ($success) {
             header('Location: ' . WEB_ROOT . '?message=edit-titles-success');
         } else {
             header('Location: ' . WEB_ROOT . '?message=edit-titles-error');
         }
         exit;
     } else {
         header('Location: ' . WEB_ROOT . '?message=edit-titles-error');
         exit;
     }
 }
コード例 #3
0
ファイル: mdb.php プロジェクト: rhrn/apirn
 public static function gridFS()
 {
     if (self::$gridFS === null) {
         self::$gridFS = self::db()->getGridFS();
     }
     return self::$gridFS;
 }
コード例 #4
0
ファイル: users.php プロジェクト: rhrn/apirn
 public function token($token)
 {
     $id = Model::factory('v1_tokens')->user($token);
     if ($id) {
         self::$user_id = MDB::objectId($id);
         return $this->get();
     }
 }
コード例 #5
0
 function testSetDbInstanceDefault()
 {
     $db =& MDB::connect(DB_DSN, $GLOBALS['DB_OPTIONS']);
     $qt =& new MDB_QueryTool();
     $qt->setDbInstance($db);
     $dbActual =& $qt->getDbInstance();
     $this->assertEqual($db->fetchmode, $dbActual->fetchmode);
 }
コード例 #6
0
ファイル: SetDbInstance.php プロジェクト: laiello/coopcrucial
 /**
  * Check if the two instances are the same by comparing
  * the fetchMode, since this is the easiest to compare if
  * two objects are the same in PHP4.
  * We can do that since the querytool sets the fetch mode to
  * MDB_FETCHMODE_ASSOC.
  * Not very nice but it works.
  *
  */
 function test_default()
 {
     $db =& MDB::connect(DB_DSN);
     $qt =& new MDB_QueryTool();
     $qt->setDbInstance($db);
     $dbActual =& $qt->getDbInstance();
     $this->assertEquals($db->fetchmode, $dbActual->fetchmode);
 }
コード例 #7
0
ファイル: tags.php プロジェクト: rhrn/apirn
 public function remove($user, $id)
 {
     $remove = MDB::objectId($id);
     $remove['user_id'] = MDB::stringId($user);
     $x = $this->collection->remove($remove, array('safe' => true));
     if ($x['n']) {
         return $id;
     }
 }
コード例 #8
0
ファイル: tokens.php プロジェクト: rhrn/apirn
 public function gen(array $user)
 {
     $id = MDB::stringId($user);
     $tail = base64_encode(hash('sha256', date('Y-m-d') . $id . $user["_id"]->getTimestamp() . $user["_id"]->getInc() . microtime()));
     self::$user_id = MDB::stringId($user);
     self::$token = $id . Model_V1_Tokens::DELIMETER . $tail;
     if ($this->add()) {
         return self::$token;
     }
 }
コード例 #9
0
ファイル: MDB.php プロジェクト: vojtajina/sitellite
 /**
  * Connects to the db
  *
  * @return object DB The database object
  * @access private
  */
 function &_db_Connect($dsn)
 {
     $this->_debugMessage('_db_Connect($dsn)');
     if (is_object($this->db)) {
         return $this->db;
     }
     $db =& MDB::connect($dsn);
     $this->_testFatalAbort($db, __FILE__, __LINE__);
     return $db;
 }
コード例 #10
0
ファイル: MDB.php プロジェクト: niczhangqiang/arserver
 public function __construct($dbName)
 {
     try {
         self::$db = new MongoClient();
         self::$db = self::$db->selectDB($dbName);
     } catch (MongoConnectionException $e) {
         echo '<p>Couldn\'t connect to mongodb</p>';
         exit;
     }
 }
コード例 #11
0
ファイル: MDBContainer.php プロジェクト: klofac/combros
 function &getContainer()
 {
     static $container;
     #print "In MDBContainer::getContainer {$this->skip_tests}\n";
     if (!isset($container)) {
         include 'auth_container_mdb_options.php';
         $container = new Auth_Container_MDB($options);
         // Catch if DB connection cannot be made
         $res = $container->_prepare();
     }
     if (!MDB::isConnection($container->db)) {
         $this->markTestSkipped("MDB is not a connection object, check dsn");
     }
     return $container;
 }
コード例 #12
0
 function &getContainer()
 {
     static $container;
     #print "In MDBContainer::getContainer {$this->skip_tests}\n";
     if (!isset($container)) {
         include './auth_container_mdb_options.php';
         $container = new Auth_Container_MDB($options);
         // Catch if DB connection cannot be made
         $res = $container->_prepare();
     }
     if (!MDB::isConnection($container->db)) {
         #print "In MDBContainer::getContainer container->db is error \n";
         $this->skip_tests = true;
         $this->skip_tests_message = "SKIP TEST:MDB is not a connection object, check dsn !!!";
     }
     return $container;
 }
コード例 #13
0
ファイル: test.php プロジェクト: rhrn/apirn
 public function action_mongo()
 {
     MDB::$config = Kohana::$config->load('database')->mongo;
     $config = MDB::config();
     #d::v($config);
     $mongo = MDB::mongo();
     d::v($mongo);
     $db = MDB::db();
     d::cl($db);
     $colle = MDB::collection('test');
     d::cl($colle);
     $data = array('data' => 'test');
     $insert = MDB::insert($data);
     d::v($insert);
     $find = MDB::find();
     d::cl($find);
     d::v(iterator_to_array($find));
     $gridFS = MDB::gridFS();
     d::cl($gridFS);
     $remove = MDB::remove();
     d::v($remove);
 }
コード例 #14
0
ファイル: search.php プロジェクト: verdurin/mrbs-mcr
    include "trailer.inc";
    exit;
}
if (!isset($search_pos) || $search_pos <= 0) {
    $search_pos = 0;
} elseif ($search_pos >= $total) {
    $search_pos = $total - $total % $search["count"];
}
# Now we set up the "real" query using LIMIT to just get the stuff we want.
$sql = "SELECT E.id, E.create_by, E.name, E.description, E.start_time, R.area_id\n        FROM mrbs_entry E, mrbs_room R\n        WHERE {$sql_pred}\n        AND E.room_id = R.id\n        ORDER BY E.start_time asc";
if ($debug_flag) {
    echo "<p>DEBUG: SQL: <tt> {$sql} </tt><BR>";
}
$types = array('integer', 'text', 'text', 'text', 'integer', 'integer');
$result = $mdb->limitQuery($sql, $types, $search_pos, $search["count"]);
if (MDB::isError($mdb)) {
    fatal_error(0, $result->getMessage() . "\n" . $result->getUserInfo() . "\n");
}
$num_records = $mdb->numRows($result);
$has_prev = $search_pos > 0;
$has_next = $search_pos < $total - $search["count"];
if ($has_prev || $has_next) {
    echo "<B>" . get_vocab("records") . ($search_pos + 1) . get_vocab("through") . ($search_pos + $num_records) . get_vocab("of") . $total . "</B><BR>";
    # display a "Previous" button if necessary
    if ($has_prev) {
        echo "<A HREF=\"search.php?search_str={$search_url}&search_pos=";
        echo max(0, $search_pos - $search["count"]);
        echo "&total={$total}&year={$year}&month={$month}&day={$day}\">";
    }
    echo "<B>" . get_vocab("previous") . "</B>";
    if ($has_prev) {
コード例 #15
0
ファイル: MDB.php プロジェクト: altesien/FinalProject
 /**
  * Change password for user in the storage container
  *
  * @param string Username
  * @param string The new password (plain text)
  */
 function changePassword($username, $password)
 {
     $this->log('Auth_Container_MDB::changePassword() called.', AUTH_LOG_DEBUG);
     $err = $this->_prepare();
     if ($err !== true) {
         return PEAR::raiseError($err->getMessage(), $err->getCode());
     }
     if (isset($this->options['cryptType']) && $this->options['cryptType'] == 'none') {
         $cryptFunction = 'strval';
     } elseif (isset($this->options['cryptType']) && function_exists($this->options['cryptType'])) {
         $cryptFunction = $this->options['cryptType'];
     } else {
         $cryptFunction = 'md5';
     }
     $password = $cryptFunction($password);
     $query = sprintf("UPDATE %s SET %s = %s WHERE %s = %s", $this->options['final_table'], $this->options['final_passwordcol'], $this->db->getTextValue($password), $this->options['final_usernamecol'], $this->db->getTextValue($username));
     // check if there is an optional parameter db_where
     if ($this->options['db_where'] != '') {
         // there is one, so add it to the query
         $query .= " AND " . $this->options['db_where'];
     }
     $this->log('Running SQL against MDB: ' . $query, AUTH_LOG_DEBUG);
     $res = $this->query($query);
     if (MDB::isError($res)) {
         return PEAR::raiseError($res->getMessage(), $res->code);
     }
     return true;
 }
コード例 #16
0
ファイル: index.php プロジェクト: laiello/coopcrucial
require_once 'PHPUnit/GUI/HTML.php';
define('DB_DSN', 'mysql://root@localhost/mdb_qt');
define('TABLE_USER', 'QueryTool_user');
define('TABLE_ADDRESS', 'QueryTool_address');
define('TABLE_QUESTION', 'question');
define('TABLE_ANSWER', 'answer');
$allTables = array(TABLE_USER, TABLE_ADDRESS, TABLE_QUESTION, TABLE_ANSWER);
require_once 'sql.php';
require_once 'UnitTest.php';
require_once 'Common.php';
//
//  common setup (this actually also does the tearDown, since we have the DROP TABLE queries in the setup too
//
$querytool = new tests_Common();
foreach ($dbStructure[$querytool->db->phptype]['setup'] as $aQuery) {
    if (MDB::isError($ret = $querytool->db->query($aQuery))) {
        //include_once 'Var_Dump.php';
        //var_dump::display($ret);
        die($ret->getUserInfo());
    }
}
//
//  run the test suite
//
require_once 'PHPUnit/GUI/SetupDecorator.php';
$gui = new PHPUnit_GUI_SetupDecorator(new PHPUnit_GUI_HTML());
$gui->getSuitesFromDir(dirname(__FILE__), '.*\\.php', array('UnitTest.php', 'Common.php', 'sql.php', 'index.php'));
$gui->show();
/*
require_once 'Get.php';
require_once 'GetAll.php';
コード例 #17
0
ファイル: Model.php プロジェクト: alegalliard/aug
 public static function ExecuteQuery($sql)
 {
     $connection = DBConnectionManager::get_connection(DATABASE_HOST, DATABASE_USER, DATABASE_PASSWORD, DATABASE_NAME);
     $db = MDB::cursor($connection, '');
     return $db->fetchObject($db->query($sql));
 }
コード例 #18
0
<?php

header("Content-type: text/javascript");
require_once '../_includes/main.php';
$db = new MDB();
$imdbIds = $db->getImdbIds();
echo 'Movies.config.imdbIds = "|';
if (isset($imdbIds) && !empty($imdbIds)) {
    foreach ($imdbIds as $id) {
        echo str_pad($id['id'], 7, '0', STR_PAD_LEFT) . '|';
    }
}
echo '";';
コード例 #19
0
ファイル: MDB.php プロジェクト: BackupTheBerlios/flushcms
 /**
  * Initialize the storage container
  *
  * @param array Array with the storage configuration
  * @return bool true on success, false on failure.
  *
  * @access public
  */
 function init($storageConf)
 {
     parent::init($storageConf);
     if (!MDB::isConnection($this->dbc) && !is_null($this->dsn)) {
         $this->options['optimize'] = 'portability';
         if ($this->function == 'singleton') {
             $dbc =& MDB::singleton($this->dsn, $this->options);
         } else {
             $dbc =& MDB::connect($this->dsn, $this->options);
         }
         if (PEAR::isError($dbc)) {
             $this->stack->push(LIVEUSER_ERROR_INIT_ERROR, 'error', array('container' => 'could not connect: ' . $dbc->getMessage(), 'debug' => $dbc->getUserInfo()));
             return false;
         }
         $this->dbc =& $dbc;
     }
     if (!MDB::isConnection($this->dbc)) {
         $this->stack->push(LIVEUSER_ERROR_INIT_ERROR, 'error', array('container' => 'storage layer configuration missing'));
         return false;
     }
     return true;
 }
コード例 #20
0
 /**
  * Garbage collector.
  *
  * @param    int maxlifetime
  */
 function garbageCollection($maxlifetime)
 {
     $this->flushPreload();
     $query = 'DELETE FROM ' . $this->cache_table . ' WHERE (expires <= ' . time() . ' AND expires > 0) OR changed <= ' . time() - $maxlifetime;
     $res = $this->db->query($query);
     $query = 'SELECT sum(length(cachedata)) as CacheSize FROM ' . $this->cache_table;
     $cachesize = $this->db->getOne($query);
     if (MDB::isError($cachesize)) {
         return new Cache_Error('MDB::query failed: ' . $this->db->errorMessage($cachesize), __FILE__, __LINE__);
     }
     //if cache is to big.
     if ($cachesize > $this->highwater) {
         //find the lowwater mark.
         $query = 'SELECT length(cachedata) as size, changed FROM ' . $this->cache_table . ' ORDER BY changed DESC';
         $res = $this->db->query($query);
         if (MDB::isError($res)) {
             return new Cache_Error('MDB::query failed: ' . $this->db->errorMessage($res), __FILE__, __LINE__);
         }
         $numrows = $this->db->numRows($res);
         $keep_size = 0;
         while ($keep_size < $this->lowwater && $numrows--) {
             $entry = $this->db->fetchInto($res, MDB_FETCHMODE_ASSOC);
             $keep_size += $entry['size'];
         }
         //delete all entries, which were changed before the "lowwater mark"
         $query = 'DELETE FROM ' . $this->cache_table . ' WHERE changed<=' . ($entry['changed'] ? $entry['changed'] : 0);
         $res = $this->db->query($query);
         if (MDB::isError($res)) {
             return new Cache_Error('MDB::query failed: ' . $this->db->errorMessage($res), __FILE__, __LINE__);
         }
     }
 }
コード例 #21
0
ファイル: report.php プロジェクト: verdurin/mrbs-mcr
 if (!empty($creatormatch)) {
     $sql .= " AND" . sql_syntax_caseless_contains("e.create_by", $creatormatch);
 }
 if ($sortby == "r") {
     # Order by Area, Room, Start date/time
     $sql .= " ORDER BY 9,10,2";
 } else {
     # Order by Start date/time, Area, Room
     $sql .= " ORDER BY 2,9,10";
 }
 if ($debug_flag) {
     echo "<p>DEBUG: SQL: <tt> {$sql} </tt>\n";
 }
 $types = array('integer', 'integer', 'integer', 'text', 'text', 'text', 'text', 'timestamp', 'text', 'text');
 $res = $mdb->query($sql, $types);
 if (MDB::isError($res)) {
     fatal_error(0, $res->getMessage() . "\n" . $res->getUserInfo() . "\n");
 }
 $nmatch = $mdb->numRows($res);
 if ($nmatch == 0) {
     echo "<P><B>" . get_vocab("nothing_found") . "</B>\n";
     $mdb->freeResult($res);
 } else {
     $last_area_room = "";
     $last_date = "";
     echo "<P><B>" . $nmatch . " " . ($nmatch == 1 ? get_vocab("entry_found") : get_vocab("entries_found")) . "</B>\n";
     while ($row = $mdb->fetchInto($res)) {
         if ($summarize & 1) {
             reporton($row, $last_area_room, $last_date, $sortby, $display);
         }
         if ($summarize & 2) {
コード例 #22
0
ファイル: mrbs_create.php プロジェクト: verdurin/mrbs-mcr
// Set $db_create to 0 to NOT create the database.
$db_create = 1;
// Communication protocol tu use. For pgsql, you can use 'unix' instead of
// 'tcp' to use Unix Domain Sockets instead of TCP/IP.
$db_protocol = "tcp";
/**************************
* DBMS specific options
***************************/
//****ORACLE*****
// Home directory path where Oracle is installed if it is running in the local machine.
// Default value: value of the environment variable ORACLE_HOME
$oci8_home = "";
/**************************
* End of database settings
***************************/
include_once "MDB.php";
MDB::loadFile("Manager");
$schema_file = "mrbs.schema.xml";
$variables = array("database_name" => $db_database, "database_create" => $db_create);
$dsn = array("phptype" => $dbsys, "username" => $db_login, "password" => $db_password, "hostspec" => $db_host, "protocol" => $db_protocol, "port" => $db_port);
$options = array("HOME" => $oci8_home, "optimize" => 'portability');
$manager = new MDB_manager();
$manager->connect($dsn, $options);
$success = $manager->updateDatabase($schema_file, $schema_file . ".before", $variables);
if (MDB::isError($success)) {
    echo "Error: " . $success->getMessage() . "<BR>";
    echo "Error: " . $success->getUserInfo() . "<BR>";
}
if (count($manager->warnings) > 0) {
    echo "WARNING:<BR>", implode($manager->getWarnings(), "!\n"), "\n";
}
コード例 #23
0
ファイル: MDB.php プロジェクト: BackupTheBerlios/hem
 /**
  * Changes user data in auth table.
  *
  * @access  public
  * @param   string   Auth user ID.
  * @param   string   Handle (username) (optional).
  * @param   string   Password (optional).
  * @param   boolean  Sets the user active (1) or not (0) (optional).
  * @param   integer  ID of the owning user.
  * @param   integer  ID of the owning group.
  * @param   array    Array of custom fields to be updated
  * @return  mixed    True on success, DB error if not.
  */
 function updateUser($authId, $handle = '', $password = '', $active = null, $owner_user_id = null, $owner_group_id = null, $customFields = array())
 {
     if (!$this->init_ok) {
         return false;
     }
     $updateValues = array();
     // Create query.
     $query = '
         UPDATE
             ' . $this->authTable . '
         SET ';
     if (!empty($handle)) {
         $updateValues[] = $this->authTableCols['handle']['name'] . ' = ' . $this->dbc->getValue($this->authTableCols['handle']['type'], $handle);
     }
     if (!empty($password)) {
         $updateValues[] = $this->authTableCols['passwd']['name'] . ' = ' . $this->dbc->getValue($this->authTableCols['passwd']['type'], $this->encryptPW($password));
     }
     if (isset($active)) {
         $updateValues[] = $this->authTableCols['is_active']['name'] . ' = ' . $this->dbc->getValue($this->authTableCols['is_active']['type'], $active);
     }
     if (isset($owner_user_id)) {
         $updateValues[] = $this->authTableCols['owner_user_id'] . ' = ' . $this->dbc->getValue($this->authTableCols['owner_user_id']['type'], $owner_user_id);
     }
     if (isset($owner_group_id)) {
         $updateValues[] = $this->authTableCols['owner_group_id'] . ' = ' . $this->dbc->getValue($this->authTableCols['owner_group_id']['type'], $owner_group_id);
     }
     if (sizeof($customFields) > 0) {
         foreach ($customFields as $k => $v) {
             $updateValues[] = $v['name'] . ' = ' . $this->dbc->getValue($v['type'], $v['value']);
         }
     }
     if (count($updateValues) >= 1) {
         $query .= implode(', ', $updateValues);
     } else {
         return false;
     }
     $query .= ' WHERE
         ' . $this->authTableCols['user_id']['name'] . '=' . $this->dbc->getValue($this->authTableCols['user_id']['type'], $authId);
     $result = $this->dbc->query($query);
     if (MDB::isError($result)) {
         return $result;
     }
     return true;
 }
コード例 #24
0
<?php

header("Content-type: text/javascript;charset=utf-8\n");
require_once '_includes/main.php';
$db = new MDB();
$movies = $db->getMovies();
$tpl = new Template(DOCUMENT_ROOT . '_templates/compare.tpl');
$tpl->set('movies', $movies);
echo $tpl->fetch();
コード例 #25
0
 /**
  * Change password for user in the storage container
  *
  * @param string Username
  * @param string The new password (plain text)
  */
 function changePassword($username, $password)
 {
     $err = $this->_prepare();
     if ($err !== true) {
         return PEAR::raiseError($err->getMessage(), $err->getCode());
     }
     if (isset($this->options['cryptType']) && $this->options['cryptType'] == 'none') {
         $cryptFunction = 'strval';
     } elseif (isset($this->options['cryptType']) && function_exists($this->options['cryptType'])) {
         $cryptFunction = $this->options['cryptType'];
     } else {
         $cryptFunction = 'md5';
     }
     $password = $cryptFunction($password);
     $query = sprintf("UPDATE %s SET %s = %s WHERE %s = %s", $this->options['table'], $this->options['passwordcol'], $this->db->getTextValue($password), $this->options['usernamecol'], $this->db->getTextValue($username));
     $res = $this->query($query);
     if (MDB::isError($res)) {
         return PEAR::raiseError($res->getMessage(), $res->code);
     }
     return true;
 }
コード例 #26
0
 /**
  * get the stucture of a field into an array
  *
  * @param object    $db        database object that is extended by this class
  * @param string    $table         name of table that should be used in method
  * @param string    $field_name     name of field that should be used in method
  * @return mixed data array on success, a MDB error on failure
  * @access public
  */
 function getTableFieldDefinition(&$db, $table, $field_name)
 {
     $result = $db->query("SELECT \n                    attnum,attname,typname,attlen,attnotnull,\n                    atttypmod,usename,usesysid,pg_class.oid,relpages,\n                    reltuples,relhaspkey,relhasrules,relacl,adsrc\n                    FROM pg_class,pg_user,pg_type,\n                         pg_attribute left outer join pg_attrdef on\n                         pg_attribute.attrelid=pg_attrdef.adrelid \n                    WHERE (pg_class.relname='{$table}') \n                        and (pg_class.oid=pg_attribute.attrelid) \n                        and (pg_class.relowner=pg_user.usesysid) \n                        and (pg_attribute.atttypid=pg_type.oid)\n                        and attnum > 0\n                        and attname = '{$field_name}'\n                        ORDER BY attnum\n                        ");
     if (MDB::isError($result)) {
         return $result;
     }
     $columns = $db->fetchInto($result, MDB_FETCHMODE_ASSOC);
     $field_column = $columns['attname'];
     $type_column = $columns['typname'];
     $db_type = preg_replace('/\\d/', '', strtolower($type_column));
     $length = $columns['attlen'];
     if ($length == -1) {
         $length = $columns['atttypmod'] - 4;
     }
     //$decimal = strtok('(), '); = eh?
     $type = array();
     switch ($db_type) {
         case 'int':
             $type[0] = 'integer';
             if ($length == '1') {
                 $type[1] = 'boolean';
             }
             break;
         case 'text':
         case 'char':
         case 'varchar':
         case 'bpchar':
             $type[0] = 'text';
             if ($length == '1') {
                 $type[1] = 'boolean';
             } elseif (strstr($db_type, 'text')) {
                 $type[1] = 'clob';
             }
             break;
             /*                        
                         case 'enum':
                             preg_match_all('/\'.+\'/U',$row[$type_column], $matches);
                             $length = 0;
                             if(is_array($matches)) {
                                 foreach($matches[0] as $value) {
                                     $length = max($length, strlen($value)-2);
                                 }
                             }
                             unset($decimal);
                         case 'set':
                             $type[0] = 'text';
                             $type[1] = 'integer';
                             break;
             */
         /*                        
                     case 'enum':
                         preg_match_all('/\'.+\'/U',$row[$type_column], $matches);
                         $length = 0;
                         if(is_array($matches)) {
                             foreach($matches[0] as $value) {
                                 $length = max($length, strlen($value)-2);
                             }
                         }
                         unset($decimal);
                     case 'set':
                         $type[0] = 'text';
                         $type[1] = 'integer';
                         break;
         */
         case 'date':
             $type[0] = 'date';
             break;
         case 'datetime':
         case 'timestamp':
             $type[0] = 'timestamp';
             break;
         case 'time':
             $type[0] = 'time';
             break;
         case 'float':
         case 'double':
         case 'real':
             $type[0] = 'float';
             break;
         case 'decimal':
         case 'money':
         case 'numeric':
             $type[0] = 'decimal';
             break;
         case 'oid':
         case 'tinyblob':
         case 'mediumblob':
         case 'longblob':
         case 'blob':
             $type[0] = 'blob';
             $type[1] = 'text';
             break;
         case 'year':
             $type[0] = 'integer';
             $type[1] = 'date';
             break;
         default:
             return $db->raiseError(MDB_ERROR_MANAGER, NULL, NULL, 'List table fields: unknown database attribute type');
     }
     if ($columns['attnotnull'] == 'f') {
         $notnull = 1;
     }
     if (!preg_match("/nextval\\('([^']+)'/", $columns['adsrc'])) {
         $default = substr($columns['adsrc'], 1, -1);
     }
     $definition = array();
     for ($field_choices = array(), $datatype = 0; $datatype < count($type); $datatype++) {
         $field_choices[$datatype] = array('type' => $type[$datatype]);
         if (isset($notnull)) {
             $field_choices[$datatype]['notnull'] = 1;
         }
         if (isset($default)) {
             $field_choices[$datatype]['default'] = $default;
         }
         if ($type[$datatype] != 'boolean' && $type[$datatype] != 'time' && $type[$datatype] != 'date' && $type[$datatype] != 'timestamp') {
             if (strlen($length)) {
                 $field_choices[$datatype]['length'] = $length;
             }
         }
     }
     $definition[0] = $field_choices;
     if (preg_match("/nextval\\('([^']+)'/", $columns['adsrc'], $nextvals)) {
         $implicit_sequence = array();
         $implicit_sequence['on'] = array();
         $implicit_sequence['on']['table'] = $table;
         $implicit_sequence['on']['field'] = $field_name;
         $definition[1]['name'] = $nextvals[1];
         $definition[1]['definition'] = $implicit_sequence;
     }
     // check that its not just a unique field
     if (MDB::isError($indexes = $db->queryAll("SELECT \n                oid,indexrelid,indrelid,indkey,indisunique,indisprimary \n                FROm pg_index, pg_class \n                WHERE (pg_class.relname='{$table}') \n                    AND (pg_class.oid=pg_index.indrelid)", NULL, MDB_FETCHMODE_ASSOC))) {
         return $indexes;
     }
     $indkeys = explode(' ', $indexes['indkey']);
     if (in_array($columns['attnum'], $indkeys)) {
         if (MDB::isError($indexname = $db->queryAll("SELECT \n                    relname FROM pg_class WHERE oid={$columns['indexrelid']}"))) {
             return $indexname;
         }
         $is_primary = $indexes['isdisprimary'] == 't';
         $is_unique = $indexes['isdisunique'] == 't';
         $implicit_index = array();
         $implicit_index['unique'] = 1;
         $implicit_index['FIELDS'][$field_name] = $indexname['relname'];
         $definition[2]['name'] = $field_name;
         $definition[2]['definition'] = $implicit_index;
     }
     $db->freeResult($result);
     return $definition;
 }
コード例 #27
0
<?php

require_once 'MDB.php';
require_once 'LiveUser.php';
// Plase configure the following file according to your environment
$db_user = '******';
$db_pass = '******';
$db_host = 'localhost';
$db_name = 'pear_test';
$dsn = "mysql://{$db_user}:{$db_pass}@{$db_host}/{$db_name}";
$db = MDB::connect($dsn, array('sequence_col_name' => 'id'));
if (MDB::isError($db)) {
    echo $db->getMessage() . ' ' . $db->getUserInfo();
}
$db->setFetchMode(MDB_FETCHMODE_ASSOC);
$conf = array('autoInit' => true, 'session' => array('name' => 'PHPSESSION', 'varname' => 'ludata'), 'login' => array('method' => 'post', 'username' => 'handle', 'password' => 'passwd', 'force' => false, 'function' => '', 'remember' => 'rememberMe'), 'logout' => array('trigger' => 'logout', 'redirect' => 'home.php', 'destroy' => true, 'method' => 'get', 'function' => ''), 'authContainers' => array(array('type' => 'MDB', 'name' => 'MDB_Local', 'loginTimeout' => 0, 'expireTime' => 3600, 'idleTime' => 1800, 'dsn' => $dsn, 'allowDuplicateHandles' => 0, 'authTable' => 'liveuser_users', 'authTableCols' => array('user_id' => array('name' => 'auth_user_id', 'type' => 'text'), 'handle' => array('name' => 'handle', 'type' => 'text'), 'passwd' => array('name' => 'passwd', 'type' => 'text'), 'lastlogin' => array('name' => 'lastlogin', 'type' => 'timestamp'), 'is_active' => array('name' => 'is_active', 'type' => 'boolean'), 'owner_user_id' => array('name' => 'owner_user_id', 'type' => 'integer'), 'owner_group_id' => array('name' => 'owner_group_id', 'type' => 'integer')))), 'permContainer' => array('dsn' => $dsn, 'type' => 'MDB_Medium', 'prefix' => 'liveuser_'));
function logOut()
{
}
function logIn()
{
}
PEAR::setErrorHandling(PEAR_ERROR_RETURN);
$usr = LiveUser::singleton($conf);
$usr->setLoginFunction('logIn');
$usr->setLogOutFunction('logOut');
$e = $usr->init();
if (PEAR::isError($e)) {
    //var_dump($usr);
    die($e->getMessage() . ' ' . $e->getUserinfo());
}
コード例 #28
0
 function testUpdateDatabase()
 {
     if (!$this->methodExists($this->manager, 'updateDatabase')) {
         return;
     }
     $backup_file = $this->driver_input_file . $this->backup_extension;
     if (!file_exists($backup_file)) {
         copy($this->driver_input_file, $backup_file);
     }
     $result = $this->manager->updateDatabase($this->driver_input_file, $backup_file, array('create' => '0', 'name' => $this->database));
     if (!MDB::isError($result)) {
         $backup_file = $this->lob_input_file . $this->backup_extension;
         if (!file_exists($backup_file)) {
             copy($this->lob_input_file, $backup_file);
         }
         $result = $this->manager->updateDatabase($this->lob_input_file, $backup_file, array('create' => '0', 'name' => $this->database));
     }
     $this->assertFalse(MDB::isError($result), 'Error updating database');
 }
コード例 #29
0
 /**
  * use this method if you want to connect manually
  *
  * @param mixed   $dsn        DSN string, DSN array or MDB object
  * @param array   $options    db options
  * @param integer $MDBversion MDB version (1=MDB, 2=MDB2)
  *
  * @return void
  */
 function connect($dsn, $options = array(), $MDBversion = 1)
 {
     if (is_object($dsn)) {
         $res =& $dsn;
     } elseif ($MDBversion == 2) {
         include_once 'MDB2.php';
         if (!isset($options['idxname_format'])) {
             $options['idxname_format'] = '%s';
         }
         $res =& MDB2::connect($dsn, $options);
     } else {
         include_once 'MDB.php';
         $res =& MDB::connect($dsn, $options);
     }
     if (PEAR::isError($res)) {
         // FIXXME what shall we do here?
         $this->_errorLog($res->getUserInfo());
         return;
     }
     $this->setDbInstance($res);
 }
コード例 #30
0
ファイル: MDB.php プロジェクト: nahakiole/cloudrexx
 function _isDBError($err)
 {
     if (!MDB::isError($err)) {
         return false;
     }
     return true;
 }