コード例 #1
0
ファイル: ops.php プロジェクト: joshuamorse/flava_framework
function build($argv)
{
    global $_plugin;
    global $success;
    global $error;
    global $errors;
    prompt('WARNING: Building fixtures clear all data from your table; are you sure you want to do this?') or $error = $errors['aborted'];
    if (!$error) {
        require_once $_plugin['dir']['fixtures'] . $argv[3] . '.php';
        # Let's get connected!
        db_connect();
        use_db();
        # Truncate table.
        echo 'Truncating ' . $argv[3] . ' table...' . "\n\n";
        $query = mysql_query('TRUNCATE ' . $argv[3]);
        foreach ($_fixtures as $_fixture) {
            $query = ' 
        INSERT INTO ' . $argv[3] . ' (' . implode(',', array_keys($_fixture)) . ') 
        VALUES (' . implode(',', array_values(enquote($_fixture))) . ')
      ';
            //add option to display this?
            echo 'Running the following query:';
            echo "\n" . $query . "\n\n";
            if (mysql_query($query)) {
                $success = 'fixtures for the table: ' . $argv[3] . ' have been succesfully built!';
            } else {
                $error = mysql_error();
            }
        }
    }
}
コード例 #2
0
function build($argv)
{
    global $_plugin;
    global $success;
    global $error;
    global $errors;
    plugin_is_installed($_plugin['name']) or $error = $error['not_installed'];
    isset($argv[3]) or $error = $errors['usage'];
    prompt('WARNING: Building a table from a definition will clear all data from your table; are you sure you want to do this?') or $error = $errors['aborted'];
    if (!$error) {
        # Let's get connected!
        db_connect();
        use_db();
        # Get definition config.
        $_definition = get_plugin_config('definitions');
        # At this point, $_definition is overwritten with the defined $_definition in the require.
        require $_definition['dir']['definitions'] . $argv[3] . '.php';
        # Drop the current table. Should really be its own script, no?
        # Check for table existence.
        if (mysql_query('SELECT * FROM ' . $_definition['name'])) {
            mysql_query('DROP TABLE ' . $_definition['name']);
        }
        # Let's build this noise!
        $query = 'CREATE TABLE ' . $_definition['name'] . '(' . "\n";
        # We'll foreach through the table def and build the SQL string as needed.
        foreach ($_definition['fields'] as $field => $data) {
            $query .= $field . ' ' . strtoupper($data['type']);
            if ($data['length']) {
                $query .= '(' . $data['length'] . ')';
            }
            if (!$data['null']) {
                $query .= ' NOT NULL';
            }
            if ($data['auto_inc']) {
                $query .= ' AUTO_INCREMENT';
            }
            # Add a comma and line break.
            $query .= ",\n";
            # Output relational data.
            if (isset($data['relation'])) {
                $query .= 'INDEX ' . $data['relation']['name'] . '_rel(' . $data['relation']['name'] . '_id)';
                $query .= ',' . "\n" . 'FOREIGN KEY(' . $data['relation']['name'] . '_id) REFERENCES ' . $data['relation']['name'] . '(id) ON DELETE CASCADE';
                $query .= ",\n";
            }
        }
        if ($_definition['primary']) {
            $query .= 'PRIMARY KEY(' . $_definition['primary'] . ')';
        }
        # End query here.
        $query .= "\n" . ')';
        //add option to display this!
        echo 'Executing the following query:' . "\n" . $query . "\n\n";
        if (mysql_query($query)) {
            //$success = 'Created ' . $_definition['name'] . ' with the following query: ' . "\n" . $query;
            $success = 'Created "' . $_definition['name'] . '"';
        } else {
            $error = mysql_error();
        }
    }
}
コード例 #3
0
<?php

require 'lib/system.config.php';
require 'lib/system.functions.php';
require 'user/plugins/functions/base/user.php';
db_connect();
use_db();
$user = new user_base(1);
//echo $user->get_name();
//echo "\n\n";
//echo $user->get_clan()->name;
//echo "\n\n";
echo "\n\n";
$comments = $user->get_comments();
echo $comments[1]['comment'];
echo "\n\n";
//print_r($clan);
//echo $clan->name;