示例#1
0
        if ($this->connection) {
            // Close the connection
            $this->connection->close();
            echo "Connection is release";
        }
    }
}
//end of class
// Create Connection
$obj = new Database("localhost", "root", "", "student_info");
// Assign table name
$tablename = "student";
// Create table query
$CreateTableSql = "CREATE TABLE {$tablename}(Roll INT,Name CHAR(50),Marks DOUBLE)";
//Call Create Table
$obj->CreateTable($CreateTableSql);
//Associative array for insert function
$InsColumnVal = array("Roll" => 4, "Name" => 'Zahan', "Marks" => 64.8);
//Call insert function to insert record
$obj->insert($tablename, $InsColumnVal);
//Associative array for delete function
$DelColumnVal = array("Roll" => 4, "Name" => 'Zahan');
//Call Delete function
$obj->delete($tablename, $DelColumnVal);
//Associative array to set query for update function
$set = array("Roll" => 5, "Marks" => 75.3);
//Associative array to condition query for update function
$condition = array("Roll" => 3, "Name" => 'Hatim');
//call update function
$obj->update($tablename, $set, $condition);
// Fetch data from the table
示例#2
0
文件: Module.php 项目: noix/qsprog
 function Install()
 {
     global $_JAM;
     // Make sure table has not already been installed
     if ($installedModules = Query::SimpleResults('_modules')) {
         $_JAM->installedModules = $installedModules;
         if (in_array($this->name, $_JAM->installedModules)) {
             return true;
         }
     }
     // Determine whether we need a table at all
     if ($this->schema) {
         foreach ($this->schema as $name => $info) {
             // Split fields between main table and localized table
             if ($info['localizable']) {
                 $localizedTableSchema[$name] = $info;
             } else {
                 $mainTableSchema[$name] = $info;
             }
             // Check whether we need to install other modules first
             if (($relatedModule = $info['relatedModule']) && !in_array($this->name, $_JAM->installedModules) && $relatedModule != $this->name) {
                 $module = Module::GetNewModule($relatedModule);
                 $module->Install();
             }
         }
         // Create main table
         if ($mainTableSchema) {
             if (!Database::CreateTable($this->name, $mainTableSchema)) {
                 trigger_error("Couldn't create table for module " . $this->name, E_USER_ERROR);
                 return false;
             }
             // If localized fields were found, we need a localized table
             if ($localizedTableSchema) {
                 $baseFields = IniFile::Parse('engine/database/localizedTableFields.ini', true);
                 $localizedTableSchema = $baseFields + $localizedTableSchema;
                 if (!Database::CreateTable($this->name . '_localized', $localizedTableSchema)) {
                     trigger_error("Couldn't create localized table for module " . $this->name, E_USER_ERROR);
                     return false;
                 }
             }
         }
     }
     // Add entry to _modules table
     $params = array('name' => $this->name);
     if (Database::Insert('_modules', $params)) {
         // Get ID of the row we just inserted
         $this->moduleID = Database::GetLastInsertID();
         // Add admin path to _paths table FIXME: Untested
         $adminModuleID = array_search('admin', $_JAM->installedModules);
         if (!Path::Insert('admin/' . $this->name, $adminModuleID, $this->moduleID)) {
             trigger_error("Couldn't add admin path for module " . $this->name, E_USER_ERROR);
             return false;
         }
         // Add paths to _paths table if needed
         if ($this->config['path']) {
             // Add paths for each language
             foreach ($this->config['path'] as $language => $path) {
                 if (!Path::Insert($path, $this->moduleID, 0, true, $language)) {
                     trigger_error("Could't add path for module " . $this->name, E_USER_ERROR);
                     return false;
                 }
             }
         }
         return true;
     } else {
         trigger_error("Couldn't install module " . $this->name, E_USER_ERROR);
         return false;
     }
 }
示例#3
0
文件: Jam.php 项目: etienne/jam
 function FirstRun()
 {
     // Load table structure for required tables
     $tables = IniFile::Parse('engine/database/tables.ini', true);
     // Create tables
     foreach ($tables as $name => $schema) {
         if (!Database::CreateTable($name, $schema)) {
             trigger_error("Couldn't create table " . $name, E_USER_ERROR);
         }
     }
     // Manually add admin module to _modules table
     if (Query::TableIsEmpty('_modules')) {
         $adminModule = array('name' => 'admin');
         if (!Database::Insert('_modules', $adminModule)) {
             trigger_error("Couldn't install core modules", E_USER_ERROR);
         }
     }
     // Install required modules
     $requiredModules = array('users', 'files');
     foreach ($requiredModules as $moduleName) {
         $module = Module::GetNewModule($moduleName);
         $module->Install();
     }
     // Add default admin user
     if (Query::TableIsEmpty('users')) {
         $adminUserParams = array('created' => $this->databaseTime, 'login' => 'admin', 'name' => 'Admin', 'password' => 'admin', 'status' => 3);
         if (!Database::Insert('users', $adminUserParams)) {
             trigger_error("Couldn't create admin user", E_USER_ERROR);
         }
     }
     // Add admin path
     $adminModuleId = Query::SingleValue('_modules', 'id', "name = 'admin'");
     if (!Path::Insert('admin', $adminModuleId, false)) {
         trigger_error("Couldn't add admin path", E_USER_ERROR);
     }
     // Redirect to admin interface
     HTTP::RedirectLocal('admin');
 }
示例#4
0
<?php

// Load table structure for required tables
$tables = IniFile::Parse('engine/database/tables.ini', true);
// Create tables
foreach ($tables as $name => $schema) {
    if (!Database::CreateTable($name, $schema)) {
        trigger_error("Couldn't create table " . $name, E_USER_ERROR);
    }
}
// Manually add admin module to _modules table
if (Query::TableIsEmpty('_modules')) {
    $adminModule = array('name' => 'admin');
    if (!Database::Insert('_modules', $adminModule)) {
        trigger_error("Couldn't install core modules", E_USER_ERROR);
    }
}
// Install required modules
$requiredModules = array('users', 'files');
foreach ($requiredModules as $moduleName) {
    $module = Module::GetNewModule($moduleName);
    $module->Install();
}
// Add default admin user
if (Query::TableIsEmpty('users')) {
    $adminUserParams = array('created' => $_JAM->databaseTime, 'login' => 'admin', 'name' => 'Admin', 'password' => 'admin', 'status' => 3);
    if (!Database::Insert('users', $adminUserParams)) {
        trigger_error("Couldn't create admin user", E_USER_ERROR);
    }
}
// Add admin path