當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Database::exec方法代碼示例

本文整理匯總了PHP中Database::exec方法的典型用法代碼示例。如果您正苦於以下問題:PHP Database::exec方法的具體用法?PHP Database::exec怎麽用?PHP Database::exec使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Database的用法示例。


在下文中一共展示了Database::exec方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: tearDown

 protected function tearDown()
 {
     try {
         $this->db->exec('DROP TABLE IF EXISTS test');
     } catch (Exception $e) {
         $this->fail($e->getMessage());
     }
 }
開發者ID:diego3,項目名稱:myframework-core,代碼行數:8,代碼來源:DataBaseTest.php

示例2: drop

 /**
  * Drop ThinkUp tables
  *
  * @TODO: Use PDO instead of deprecated Database class.
  * @param Database $db
  */
 public function drop($db)
 {
     global $TEST_DATABASE;
     //Delete test data by dropping all existing tables
     $q = "SHOW TABLES FROM " . $TEST_DATABASE;
     $result = $db->exec($q);
     while ($row = mysql_fetch_assoc($result)) {
         $q = "DROP TABLE " . $row['Tables_in_' . $TEST_DATABASE];
         $db->exec($q);
     }
 }
開發者ID:unruthless,項目名稱:ThinkUp,代碼行數:17,代碼來源:class.ThinkUpTestDatabaseHelper.php

示例3: insertTables

 public static function insertTables(Smarty $smarty)
 {
     if (ConfigurationChecks::getResult() != CheckResult::OK) {
         header('Location: index.php');
         exit;
     }
     $sql = file_get_contents(SYSTEM_ROOT . '/install/install.sql');
     try {
         $db = new Database('mysql:dbname=' . DATABASE_NAME . ';host=' . DATABASE_HOST, DATABASE_USER, DATABASE_PASS);
         $sql = $db->prepare('SHOW TABLES');
         $sql->execute();
         if ($sql->rowCount() == 0 || Utils::getGET('confirm', false) != false) {
             $insert = file_get_contents('./install.sql');
             $db->exec($insert);
             header('Location: index.php?action=user');
             exit;
         } else {
             $smarty->assign('heading', 'Database tables');
             $smarty->assign('curStep', 2);
             $smarty->display('confirm.tpl');
         }
     } catch (PDOException $e) {
         $smarty->assign('heading', 'Database tables');
         $smarty->assign('error', $e->getMessage());
         $smarty->assign('url', 'index.php?action=tables&confirm=yes');
         $smarty->assign('curStep', 2);
         $smarty->display('error.tpl');
     }
 }
開發者ID:nicefirework,項目名稱:sharecloud,代碼行數:29,代碼來源:index.php

示例4: finalDatabaseSetup

 /**
  * Set up the database tables, views, etc.
  *
  */
 protected function finalDatabaseSetup()
 {
     $this->db = $this->finalDatabasePrimary();
     // Let's iterate through the SQL files and run them all
     $driver = $this->db->getDriver();
     $files = \Airship\list_all_files(ROOT . '/Installer/sql/' . $driver, 'sql');
     \sort($files);
     foreach ($files as $file) {
         $query = \file_get_contents($file);
         try {
             $this->db->exec($query);
         } catch (\PDOException $e) {
             var_dump($e->getMessage());
             var_dump($query);
             exit(1);
         }
     }
     switch ($driver) {
         case 'pgsql':
             $this->databaseFinalPgsql();
             break;
         default:
             die('Unsupported primary database driver');
     }
 }
開發者ID:paragonie,項目名稱:airship,代碼行數:29,代碼來源:Install.php

示例5: __construct

 public function __construct(API $base, Database $database, $key_prefix)
 {
     parent::__construct($key_prefix, $base);
     $this->database = $database;
     if ($database instanceof MySQL) {
         $sql = 'CREATE TABLE IF NOT EXISTS spindash_cache (item_key VARCHAR(255) NOT NULL, item_expires INT(11) UNSIGNED NOT NULL, item_value LONGTEXT NOT NULL, UNIQUE KEY (item_key)) ENGINE = InnoDB DEFAULT CHARSET=UTF8';
         $database->exec($sql);
     }
     if ($database instanceof SQLite) {
         $sql = 'CREATE TABLE IF NOT EXISTS spindash_cache (item_key TEXT, item_expires INTEGER, item_value TEXT, UNIQUE (item_key))';
         $database->exec($sql);
     }
     if ($database instanceof PostgreSQL) {
         $sql = 'CREATE TABLE IF NOT EXISTS spindash_cache (item_key VARCHAR(255) NOT NULL, item_expires INTEGER NOT NULL, item_value TEXT NOT NULL, UNIQUE (item_key))';
         $database->exec($sql);
     }
 }
開發者ID:wst,項目名稱:spindash,代碼行數:17,代碼來源:database-cache-engine.inc.php

示例6: install

 public function install()
 {
     Database::exec("\n\t\tCREATE TABLE IF NOT EXISTS `users`\n\t\t(\n\t\t\t`uni_id`\t\t\t\tint(10)\t\t\tunsigned\tNOT NULL\tDEFAULT '0',\n\t\t\t\n\t\t\t`role`\t\t\t\t\tvarchar(12)\t\t\t\t\tNOT NULL\tDEFAULT '',\n\t\t\t`flair`\t\t\t\t\tvarchar(22)\t\t\t\t\tNOT NULL\tDEFAULT '',\n\t\t\t`clearance`\t\t\t\ttinyint(1)\t\t\t\t\tNOT NULL\tDEFAULT '0',\n\t\t\t\n\t\t\t`handle`\t\t\t\tvarchar(22)\t\t\t\t\tNOT NULL\tDEFAULT '',\n\t\t\t`display_name`\t\t\tvarchar(22)\t\t\t\t\tNOT NULL\tDEFAULT '',\n\t\t\t\n\t\t\t`timezone`\t\t\t\tvarchar(22)\t\t\t\t\tNOT NULL\tDEFAULT '',\n\t\t\t\n\t\t\t`date_joined`\t\t\tint(10)\t\t\tunsigned\tNOT NULL\tDEFAULT '0',\n\t\t\t`date_lastLogin`\t\tint(10)\t\t\tunsigned\tNOT NULL\tDEFAULT '0',\n\t\t\t\n\t\t\t`auth_token`\t\t\tvarchar(22)\t\t\t\t\tNOT NULL\tDEFAULT '',\n\t\t\t\n\t\t\tUNIQUE (`uni_id`)\n\t\t) ENGINE=InnoDB DEFAULT CHARSET=utf8 PARTITION BY KEY(uni_id) PARTITIONS 7;\n\t\t");
     // Vertical partitioning of the user's table. This creates duplicate content, but will greatly speed up
     // lookup times for handles. There is overhead for two tables, but its a negligible impact compared to the
     // horizontal partitioning we gain on the user's table.
     Database::exec("\n\t\tCREATE TABLE IF NOT EXISTS `users_handles`\n\t\t(\n\t\t\t`handle`\t\t\t\tvarchar(22)\t\t\t\t\tNOT NULL\tDEFAULT '',\n\t\t\t`uni_id`\t\t\t\tint(10)\t\t\tunsigned\tNOT NULL\tDEFAULT '0',\n\t\t\t\n\t\t\tUNIQUE (`handle`, `uni_id`)\n\t\t) ENGINE=InnoDB DEFAULT CHARSET=utf8\n\t\t\n\t\tPARTITION BY RANGE COLUMNS(handle) (\n\t\t\tPARTITION p0 VALUES LESS THAN ('a'),\n\t\t\tPARTITION p1 VALUES LESS THAN ('e'),\n\t\t\tPARTITION p2 VALUES LESS THAN ('i'),\n\t\t\tPARTITION p3 VALUES LESS THAN ('m'),\n\t\t\tPARTITION p4 VALUES LESS THAN ('q'),\n\t\t\tPARTITION p5 VALUES LESS THAN ('u'),\n\t\t\tPARTITION p6 VALUES LESS THAN MAXVALUE\n\t\t);\n\t\t");
     return $this->isInstalled();
 }
開發者ID:SkysteedDevelopment,項目名稱:Deity,代碼行數:9,代碼來源:User.config.php

示例7: Database

 function testExecutingSQLWithUnSetTablePrefixShouldFail()
 {
     global $TWITALYTIC_CFG;
     $TWITALYTIC_CFG['table_prefix'] = 'tw_';
     $this->expectException();
     $db = new Database($TWITALYTIC_CFG);
     $conn = $db->getConnection();
     $sql_result = $db->exec("SELECT \n\t\t\t\tuser_id \n\t\t\tFROM \n\t\t\t\t%prefix%users \n\t\t\tWHERE \n\t\t\t\tuser_id = 930061");
     $db->closeConnection($conn);
 }
開發者ID:karbassi,項目名稱:twitalytic,代碼行數:10,代碼來源:database_test.php

示例8: uploadData

function uploadData($name, $username, $password, $email)
{
    $db = new Database();
    $db->exec("CREATE TABLE IF NOT EXISTS recipes (username TEXT PRIMARY KEY, password TEXT, email TEXT, name TEXT)");
    $stmt = $db->prepare("INSERT INTO recipes VALUES (:us, :ps, :em, :n)");
    $stmt->bindValue(':us', $username);
    $stmt->bindValue(':ps', $password);
    $stmt->bindValue(':em', $email);
    $stmt->bindValue(':n', $name);
    $stmt->execute();
}
開發者ID:Abhilaash,項目名稱:Planner,代碼行數:11,代碼來源:registration.php

示例9: archiveTodo

 public function archiveTodo($item_id)
 {
     $db_link = new Database();
     $sql = 'SELECT todo_archived FROM todos WHERE todo_id = "' . (int) $item_id . '"';
     $toggle = 1;
     if ($db_link->query($sql)->fetch()->todo_archived == 1) {
         $toggle = 0;
     }
     $sql = 'UPDATE todos SET todo_archived = ' . $toggle . ' WHERE todo_id = "' . (int) $item_id . '"';
     $db_link->exec($sql);
 }
開發者ID:hoverlord,項目名稱:ff2do,代碼行數:11,代碼來源:todo_mapper.php

示例10: archiveProject

 public function archiveProject($id)
 {
     $db_link = new Database();
     $sql = 'SELECT project_archived FROM projects WHERE project_id = "' . (int) $id . '"';
     $toggle = 1;
     if ($db_link->query($sql)->fetch()->project_archived == 1) {
         $toggle = 0;
     }
     $sql = 'UPDATE projects SET project_archived = ' . $toggle . ' WHERE project_id = "' . (int) $id . '"';
     $db_link->exec($sql);
 }
開發者ID:hoverlord,項目名稱:ff2do,代碼行數:11,代碼來源:project_mapper.php

示例11: exec

 public function exec($sql, array $params = null)
 {
     try {
         return parent::exec($sql, $params);
     } catch (PDOException $e) {
         $info = $this->errorInfo();
         switch ($info[1]) {
             case 8:
                 throw new ReadOnlyDatabaseException();
             default:
                 throw $e;
         }
     }
 }
開發者ID:umonkey,項目名稱:molinos-cms,代碼行數:14,代碼來源:class.mcms_sqlite_driver.php

示例12: Database

 function testExecutingSQLWithUnSetTablePrefixShouldFail()
 {
     global $THINKTANK_CFG;
     $THINKTANK_TEST_CFG['table_prefix'] = 'tw_';
     $THINKTANK_TEST_CFG['db_password'] = $THINKTANK_CFG['db_password'];
     $THINKTANK_TEST_CFG['db_host'] = $THINKTANK_CFG['db_host'];
     $THINKTANK_TEST_CFG['db_name'] = $THINKTANK_CFG['db_name'];
     $THINKTANK_TEST_CFG['db_user'] = $THINKTANK_CFG['db_user'];
     $this->expectException();
     $db = new Database($THINKTANK_TEST_CFG);
     $conn = $db->getConnection();
     $sql_result = $db->exec("SELECT\n\t\t\t\tuser_id \n\t\t\tFROM \n\t\t\t\t%prefix%users \n\t\t\tWHERE \n\t\t\t\tuser_id = 930061");
     $db->closeConnection($conn);
 }
開發者ID:BenBtg,項目名稱:thinktank,代碼行數:14,代碼來源:database_test.php

示例13: copy

 public static function copy($sourceTable, $destinationTable, $sqlWhere = "", $sqlArray = array(), $limit = 1000, $move = false)
 {
     // Protect Tables
     if (!IsSanitized::variable($destinationTable) or !IsSanitized::variable($sourceTable)) {
         return false;
     }
     // Make sure the backup table exists
     Database::exec("CREATE TABLE IF NOT EXISTS " . $destinationTable . " LIKE " . $sourceTable);
     // Begin the Database_Transfer
     Database::startTransaction();
     // Insert Rows into Database_Transfer Table
     Database::query("INSERT INTO " . $destinationTable . " SELECT * FROM " . $sourceTable . ($sqlWhere != "" ? " WHERE " . Sanitize::variable($sqlWhere, " ,`!=<>?()") : "") . ($limit ? ' LIMIT ' . (int) $limit : ''), $sqlArray);
     $newCount = Database::$rowsAffected;
     if ($move === true) {
         // Delete Rows from Original Table (if applicable)
         Database::query("DELETE FROM " . $sourceTable . ($sqlWhere != "" ? " WHERE " . Sanitize::variable($sqlWhere, " ,`!=<>?()") : ""), $sqlArray);
         // If the number of inserts matches the number of deletions, commit the transaction
         return Database::endTransaction($newCount == Database::$rowsAffected);
     }
     return Database::endTransaction();
 }
開發者ID:SkysteedDevelopment,項目名稱:Deity,代碼行數:21,代碼來源:Database_Transfer.php

示例14: atualizar

 /**
  * atualiza os dados no BD
  *
  * @param Pessoa $pessoa
  * @return int pessoa id
  */
 public function atualizar(Pessoa $pessoa)
 {
     try {
         self::valida($pessoa, "atualizar");
         $this->values = $pessoa->getPessoaValores();
         $this->fields = array_keys($pessoa->getPessoaValores());
         $this->sql = "UPDATE pessoa SET\n\t\t\t\t\t  nome = ?\n\t\t\t\t\t, email=? \n\t\t\t\t\t, endereco=?\n\t\t\t\t\t, complemento=?\n\t\t\t\t\t, numero=?\n\t\t\t\t\t, cep=?\n\t\t\t\t\t, UF = ?\n\t\t\t\t\t, cidade = ?\n\t\t\t\t\t, bairro =?\n\t\t\t\t\t, idresiduo =?\n\t\t\t\t\t, limitecredito =?\n\t\t\t\t\t, inadimplente =?\n\t\t\t\t\t, idempresa =?\n                                        , idcontato = ?\n\t\t\t\t\tWHERE id=?";
         $this->values = array();
         $this->values = array($pessoa->nome, $pessoa->email, $pessoa->endereco, $pessoa->complemento, $pessoa->numero, $pessoa->cep, $pessoa->UF, $pessoa->cidade, $pessoa->bairro, $pessoa->idresiduo, $pessoa->limitecredito, $pessoa->inadimplente, $pessoa->idempresa, $pessoa->idcontato, $pessoa->id);
         parent::exec();
         $telefoneDAO = new TelefoneDAO();
         $telefoneDAO->atualizarTelefones($pessoa->id, $pessoa->telefones);
         $telefoneDAO->apagarTelefones($pessoa->id, explode(",", $_POST['removerTels']));
         $enderecoDAO = new EnderecoDAO();
         $enderecoDAO->atualizarEnderecos($pessoa->id, $pessoa->enderecos);
     } catch (Exception $e) {
         $erro = new FormException();
         $erro->addError($e->getMessage());
         throw $erro;
     }
     return $pessoa->id;
 }
開發者ID:tricardo,項目名稱:CartorioPostal_old,代碼行數:28,代碼來源:PessoaDAO.php

示例15: clear

 public function clear()
 {
     Database::exec('TRUNCATE TABLE ' . $this->name . ';');
 }
開發者ID:amineabri,項目名稱:Fiesta,代碼行數:4,代碼來源:DBTable.php


注:本文中的Database::exec方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。