当前位置: 首页>>代码示例>>PHP>>正文


PHP SQL::error方法代码示例

本文整理汇总了PHP中SQL::error方法的典型用法代码示例。如果您正苦于以下问题:PHP SQL::error方法的具体用法?PHP SQL::error怎么用?PHP SQL::error使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SQL的用法示例。


在下文中一共展示了SQL::error方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: connect

 public static function connect($server = 'localhost:3306', $username = 'root', $password = '', $database = '')
 {
     //microtime(get_as_float)
     //参数	描述
     //get_as_float 如果给出了 get_as_float 参数并且其值等价于 TRUE,该函数将返回一个浮点数。
     $timestamp = microtime(true);
     SQL::$connection = mysqli_connect($server, $username, $password, $database);
     //mysqli_connect(host,username,password,dbname,port,socket);
     //参数	描述
     //host	可选。规定主机名或 IP 地址。
     //username	可选。规定 MySQL 用户名。
     //password	可选。规定 MySQL 密码。
     //dbname	可选。规定默认使用的数据库。
     //port	可选。规定尝试连接到 MySQL 服务器的端口号。
     //socket	可选。规定 socket 或要使用的已命名 pipe。
     //round(x,prec)
     //参数	描述
     //x	可选。规定要舍入的数字。
     //prec	可选。规定小数点后的位数。
     //说明
     //返回将 x 根据指定精度 prec (十进制小数点后数字的数目)进行四舍五入的结果。prec 也可以是负数或零(默认值)。
     DEBUG::put('Connected: ' . $username . '@' . $server . ' spent: ' . round((microtime(true) - $timestamp) * 1000, 3) . 'ms', 'MySQL');
     $err = SQL::error();
     if ($err['id'] > 0) {
         DEBUG::put('  - Error: #' . $err['id'] . ' ' . $err['error'], 'MySQL');
     }
     return SQL::$connection;
 }
开发者ID:sjclijie,项目名称:SlimPHP,代码行数:28,代码来源:sql.php

示例2: execute_reader

 /**
  * execute query and return all data in a reader
  *
  * @return SQLDataReader
  */
 public function execute_reader()
 {
     $this->parse_query();
     if (empty($this->queryParsed)) {
         return new SQLDataReader();
     }
     $close = $this->conn->status() == 'closed';
     $this->conn->open();
     $res = $this->conn->query($this->queryParsed);
     $data = array();
     while ($row = $this->conn->fetch_array($res)) {
         $data[] = $row;
     }
     // SQLite causes 'unknown error' after successful fetch of all data.
     // Don't have a clue why...
     $ret = empty($this->conn->error()) || $this->conn->error() == 'unknown error';
     if ($close) {
         $this->conn->close();
     }
     return $ret ? new SQLDataReader($data) : new SQLDataReader();
 }
开发者ID:BlackyPanther,项目名称:SQL-Class,代码行数:26,代码来源:SQLCommand.class.php

示例3: run_sql_script

function run_sql_script($dbhost, $dbuser, $dbpass, $dbname, $path, $unlink)
{
    global $lang_global;
    $fp = fopen($path, 'r') or die(error("Couldn't Open File!"));
    $sql_1 = new SQL();
    $sql_1->connect($dbhost, $dbuser, $dbpass, $dbname);
    $query = "";
    $queries = 0;
    $linenumber = 0;
    $inparents = false;
    while (!feof($fp)) {
        $dumpline = "";
        while (!feof($fp) && substr($dumpline, -1) != "\n") {
            $dumpline .= fgets($fp, 16384);
        }
        $dumpline = ereg_replace("\r\n\$", "\n", $dumpline);
        $dumpline = ereg_replace("\r\$", "\n", $dumpline);
        if (!$inparents) {
            $skipline = false;
            if (!$inparents && (trim($dumpline) == "" || strpos($dumpline, '#') === 0 || strpos($dumpline, '-- ') === 0)) {
                $skipline = true;
            }
            if ($skipline) {
                $linenumber++;
                continue;
            }
        }
        $dumpline_deslashed = str_replace("\\\\", "", $dumpline);
        $parents = substr_count($dumpline_deslashed, "'") - substr_count($dumpline_deslashed, "\\'");
        if ($parents % 2 != 0) {
            $inparents = !$inparents;
        }
        $query .= $dumpline;
        if (ereg(";\$", trim($dumpline)) && !$inparents) {
            if (!$sql_1->query(trim($query))) {
                fclose($fp);
                if ($unlink) {
                    unlink($path);
                }
                $err = ereg_replace("\n", "", $sql_1->error());
                $err = ereg_replace("\r\n\$", "", $err);
                $err = ereg_replace("\r\$", "", $err);
                error("SQL Error at the line: {$linenumber} in {$path} <br /> {$err}");
                break;
            }
            $queries++;
            $query = "";
        }
        $linenumber++;
    }
    $sql_1->close();
    fclose($fp);
    return $queries;
}
开发者ID:BACKUPLIB,项目名称:minimanager-1,代码行数:54,代码来源:sql_lib.php

示例4: connect

 /**
  * 连接到数据库
  * 成功返回true, 失败返回false
  *
  * @param string $server
  * @param string $username
  * @param string $password
  * @param string $database
  * @return bool
  */
 public static function connect($server = 'localhost:3306', $username = 'root', $password = '', $database = '')
 {
     $timestamp = microtime(true);
     SQL::$connection = mysqli_connect($server, $username, $password, $database);
     DEBUG::put('Connected: ' . $username . '@' . $server . ' spent: ' . round((microtime(true) - $timestamp) * 1000, 3) . 'ms', 'MySQL');
     $err = SQL::error();
     if ($err['id'] > 0) {
         DEBUG::put('  - Error: #' . $err['id'] . ' ' . $err['error'], 'MySQL');
     }
     return SQL::$connection;
 }
开发者ID:AutumnsWindsGoodBye,项目名称:leiphp,代码行数:21,代码来源:leiphp.php

示例5: build

 /**
  * build one table
  *
  * Accept following variants:
  * - csv - to provide a downloadable csv page
  * - json - to provide all values in one column
  * - inline - to render tables within articles
  * - simple - the legacy fixed table
  * - sortable - click on column to sort the row
  *
  * @param the id of the table to build
  * @param string the variant to provide - default is 'simple'
  * @return a displayable string
  */
 public static function build($id, $variant = 'simple')
 {
     global $context;
     // split parameters
     $attributes = preg_split("/\\s*,\\s*/", $id, 3);
     $id = $attributes[0];
     // get the table object
     if (!($table = Tables::get($id))) {
         return NULL;
     }
     // do the SELECT statement
     if (!($rows = SQL::query($table['query']))) {
         Logger::error(sprintf(i18n::s('Error in table query %s'), $id) . BR . htmlspecialchars($table['query']) . BR . SQL::error());
         return NULL;
     }
     // build the resulting string
     $text = '';
     switch ($variant) {
         // produce a table readable into MS-Excel
         case 'csv':
             // comma separated values
             $separator = ",";
             // one row for the title
             if ($table['title']) {
                 $label = preg_replace('/\\s/', ' ', $table['title']);
                 // encode to ASCII
                 $label = utf8::to_ascii($label, PRINTABLE_SAFE_ALPHABET);
                 // escape quotes to preserve them in the data
                 $label = str_replace('"', '""', $label);
                 $text .= '"' . $label . '"';
                 $text .= "\n";
             }
             // one row for header fields
             $index = 0;
             while ($field = SQL::fetch_field($rows)) {
                 if ($index++) {
                     $text .= $separator;
                 }
                 $label = trim(preg_replace('/\\s/', ' ', ucfirst($field->name)));
                 // encode
                 $label = utf8::to_ascii($label, PRINTABLE_SAFE_ALPHABET);
                 // escape quotes to preserve them in the data
                 $label = str_replace('"', '""', $label);
                 $text .= '"' . $label . '"';
             }
             $text .= "\n";
             // process every table row
             $row_index = 0;
             while ($row = SQL::fetch($rows)) {
                 // one cell at a time
                 $index = 0;
                 foreach ($row as $name => $value) {
                     // glue cells
                     if ($index++) {
                         $text .= $separator;
                     }
                     // remove HTML tags
                     $value = strip_tags(str_replace('</', ' </', str_replace(BR, ' / ', $value)));
                     // clean spaces
                     $label = trim(preg_replace('/\\s+/', ' ', $value));
                     // encode
                     $label = utf8::to_ascii($label, PRINTABLE_SAFE_ALPHABET);
                     // escape quotes to preserve them in the data
                     $label = str_replace('"', '""', $label);
                     // make a link if this is a reference
                     if ($index == 1 && $table['with_zoom'] == 'Y') {
                         $label = $context['url_to_home'] . $context['url_to_root'] . $label;
                     }
                     // quote data
                     $text .= '"' . $label . '"';
                 }
                 // new line
                 $text .= "\n";
             }
             return $text;
             // a JSON set of values
         // a JSON set of values
         case 'json':
             // get header labels
             $labels = array();
             while ($field = SQL::fetch_field($rows)) {
                 $labels[] = trim(preg_replace('/[^\\w]+/', '', ucfirst($field->name)));
             }
             // all items
             $data = array();
             $data['items'] = array();
//.........这里部分代码省略.........
开发者ID:rair,项目名称:yacs,代码行数:101,代码来源:tables.php

示例6: update_jc_ticket_sp

 /**
  * 更新moreinfo
  * @param unknown_type $id
  * @param unknown_type $play_method
  * @param unknown_type $codes
  * @param unknown_type $ticket_type
  */
 public function update_jc_ticket_sp($id, $play_method, $codes, $ticket_type = 1)
 {
     require_once WEBROOT . 'cron_script/SQL.php';
     $sql_obj = new SQL();
     $return = array();
     $code_a = explode(';', $codes);
     $code = $code_a[0];
     $match_detail = explode('/', $code);
     for ($i = 0; $i < count($match_detail); $i++) {
         $match_info = explode('|', $match_detail[$i]);
         $match_id = $match_info[0];
         preg_match_all("/\\[(.*)\\]/", $match_info[1], $match_result, PREG_SET_ORDER);
         $match_results = $match_result[0][1];
         $match_results_a = explode(',', $match_results);
         $match_result_sp = array();
         $select_match_query = 'select comb,goalline from match_datas where ticket_type="' . $ticket_type . '" and play_type="' . $play_method . '" and match_id="' . $match_id . '" limit 1';
         $sql_obj->query($select_match_query);
         $match_data = $sql_obj->fetch_array();
         $sp = $match_data['comb'];
         $goalline = $match_data['goalline'];
         //var_dump($sp);
         $play_config = array();
         if ($ticket_type == 1) {
             switch ($play_method) {
                 case 1:
                     $play_config = array('3' => 'H', '1' => 'D', '0' => 'A');
                     break;
                 case 2:
                     $play_config = array('0' => '0', '1' => '1', '2' => '2', '3' => '3', '4' => '4', '5' => '5', '6' => '6', '7' => '7');
                     break;
                 case 3:
                     $play_config = array('负其它' => '-1:-A', '胜其它' => '-1:-H', '平其它' => '-1:-D', '0:0' => '00:00', '0:1' => '00:01', '0:2' => '00:02', '0:3' => '00:03', '0:4' => '00:04', '0:5' => '00:05', '1:0' => '01:00', '1:1' => '01:01', '1:2' => '01:02', '1:3' => '01:03', '1:4' => '01:04', '1:5' => '01:05', '2:0' => '02:00', '2:1' => '02:01', '2:2' => '02:02', '2:3' => '02:03', '2:4' => '02:04', '2:5' => '02:05', '3:0' => '03:00', '3:1' => '03:01', '3:2' => '03:02', '3:3' => '03:03', '4:0' => '04:00', '4:1' => '04:01', '4:2' => '04:02', '5:0' => '05:00', '5:1' => '05:01', '5:2' => '05:02');
                     break;
                 case 4:
                     $play_config = array('0-0' => 'cc', '0-1' => 'cb', '0-3' => 'ca', '1-0' => 'bc', '1-1' => 'bb', '1-3' => 'ba', '3-0' => 'ac', '3-1' => 'ab', '3-3' => 'aa');
                     break;
                 default:
                     break;
             }
         }
         if ($ticket_type == 6) {
             switch ($play_method) {
                 case 1:
                     $play_config = array('2' => 'H', '1' => 'D');
                     break;
                 case 2:
                     $play_config = array('2' => 'H', '1' => 'D');
                     break;
                 case 3:
                     $play_config = array('01' => 'u4e3bu80dc1-5', '02' => 'u4e3bu80dc6-10', '03' => 'u4e3bu80dc11-15', '04' => 'u4e3bu80dc16-20', '05' => 'u4e3bu80dc21-25', '06' => 'u4e3bu80dc26+', '11' => 'u5ba2u80dc1-5', '12' => 'u5ba2u80dc6-10', '13' => 'u5ba2u80dc11-15', '14' => 'u5ba2u80dc16-20', '15' => 'u5ba2u80dc21-25', '16' => 'u5ba2u80dc26+');
                     break;
                 case 4:
                     $play_config = array('1' => 'H', '2' => 'D');
                     break;
                 default:
                     break;
             }
         }
         //$sp = '{"cc":{"c":"cc","v":"4.30","s":"1","d":"2011-09-06","t":"05:59:00"},"cb":{"c":"cb","v":"15.00","s":"1","d":"2011-09-06","t":"05:59:00"},"ca":{"c":"ca","v":"28.00","s":"1","d":"2011-09-06","t":"05:59:00"},"bc":{"c":"bc","v":"6.50","s":"1","d":"2011-09-06","t":"05:59:00"},"bb":{"c":"bb","v":"4.50","s":"1","d":"2011-09-06","t":"05:59:00"},"ba":{"c":"ba","v":"5.40","s":"1","d":"2011-09-06","t":"05:59:00"},"ac":{"c":"ac","v":"34.00","s":"1","d":"2011-09-06","t":"05:59:00"},"ab":{"c":"ab","v":"15.00","s":"1","d":"2011-09-06","t":"05:59:00"},"aa":{"c":"aa","v":"3.85","s":"1","d":"2011-09-06","t":"05:59:00"}}';
         $sp = json_decode($sp);
         $result_sp = array();
         foreach ($sp as $key => $val) {
             if (isset($val->c)) {
                 $result_sp[$val->c] = $val->v;
             } else {
                 $result_sp[] = $val->v;
             }
         }
         //var_dump($result_sp);
         for ($j = 0; $j < count($match_results_a); $j++) {
             $key = $play_config[$match_results_a[$j]];
             if (array_key_exists($key, $result_sp)) {
                 $match_result_sp[] = $result_sp[$key];
             }
         }
         $match_result_sp = implode(',', $match_result_sp);
         //$return[] = $match_id.':'.$match_result_sp;
         if ($ticket_type == 6 && ($play_method == 2 || $play_method == 4)) {
             if ($play_method == 2 && $goalline > 0) {
                 $goalline = '+' . $goalline;
             }
             $return[] = $match_id . '(' . $goalline . '):' . $match_result_sp;
         } else {
             $return[] = $match_id . ':' . $match_result_sp;
         }
         //var_dump($return);
         //echo $i;
     }
     $return = implode('|', $return);
     //var_dump($return);
     $sql_obj->query('update ticket_nums set moreinfo="' . $return . '" where id="' . $id . '"');
     if (!$sql_obj->error()) {
         return true;
//.........这里部分代码省略.........
开发者ID:RenzcPHP,项目名称:3dproduct,代码行数:101,代码来源:ticket.php

示例7: post

 /**
  * post a new server or an updated server
  *
  * @see servers/edit.php
  * @see servers/populate.php
  *
  * @param array an array of fields
  * @return string either a null string, or some text describing an error to be inserted into the html response
  **/
 public static function post(&$fields)
 {
     global $context;
     // no title
     if (!$fields['title']) {
         return i18n::s('No title has been provided.');
     }
     // clear the cache for servers
     Cache::clear('servers');
     if (isset($fields['id'])) {
         Cache::clear('server:' . $fields['id']);
     }
     // protect from hackers
     if (isset($fields['main_url'])) {
         $fields['main_url'] = encode_link($fields['main_url']);
     }
     if (isset($fields['feed_url'])) {
         $fields['feed_url'] = encode_link($fields['feed_url']);
     }
     if (isset($fields['ping_url'])) {
         $fields['ping_url'] = encode_link($fields['ping_url']);
     }
     if (isset($fields['search_url'])) {
         $fields['search_url'] = encode_link($fields['search_url']);
     }
     if (isset($fields['monitor_url'])) {
         $fields['monitor_url'] = encode_link($fields['monitor_url']);
     }
     // make a host name
     if (!isset($fields['host_name'])) {
         $fields['host_name'] = '';
     }
     if (!$fields['host_name']) {
         if (($parts = parse_url($fields['main_url'])) && isset($parts['host'])) {
             $fields['host_name'] = $parts['host'];
         }
     }
     if (!$fields['host_name']) {
         if (($parts = parse_url($fields['feed_url'])) && isset($parts['host'])) {
             $fields['host_name'] = $parts['host'];
         }
     }
     if (!$fields['host_name']) {
         if (($parts = parse_url($fields['ping_url'])) && isset($parts['host'])) {
             $fields['host_name'] = $parts['host'];
         }
     }
     if (!$fields['host_name']) {
         if (($parts = parse_url($fields['monitor_url'])) && isset($parts['host'])) {
             $fields['host_name'] = $parts['host'];
         }
     }
     if (!$fields['host_name']) {
         if (($parts = parse_url($fields['search_url'])) && isset($parts['host'])) {
             $fields['host_name'] = $parts['host'];
         }
     }
     // set default values
     if (!isset($fields['active']) || !$fields['active']) {
         $fields['active'] = 'Y';
     }
     if (!isset($fields['process_ping']) || $fields['process_ping'] != 'Y') {
         $fields['process_ping'] = 'N';
     }
     if (!isset($fields['process_monitor']) || $fields['process_monitor'] != 'Y') {
         $fields['process_monitor'] = 'N';
     }
     if (!isset($fields['process_search']) || $fields['process_search'] != 'Y') {
         $fields['process_search'] = 'N';
     }
     // set default values for this editor
     Surfer::check_default_editor($fields);
     // update the existing record
     if (isset($fields['id'])) {
         // id cannot be empty
         if (!isset($fields['id']) || !is_numeric($fields['id'])) {
             return i18n::s('No item has the provided id.');
         }
         // update the existing record
         $query = "UPDATE " . SQL::table_name('servers') . " SET " . "title='" . SQL::escape($fields['title']) . "', " . "description='" . SQL::escape($fields['description']) . "', " . "main_url='" . SQL::escape($fields['main_url']) . "', " . "anchor='" . SQL::escape(isset($fields['anchor']) ? $fields['anchor'] : '') . "', " . "submit_feed='" . SQL::escape($fields['submit_feed'] == 'Y' ? 'Y' : 'N') . "', " . "feed_url='" . SQL::escape($fields['feed_url']) . "', " . "submit_ping='" . SQL::escape($fields['submit_ping'] == 'Y' ? 'Y' : 'N') . "', " . "ping_url='" . SQL::escape($fields['ping_url']) . "', " . "process_ping='" . SQL::escape($fields['process_ping'] == 'Y' ? 'Y' : 'N') . "', " . "submit_monitor='" . SQL::escape($fields['submit_monitor'] == 'Y' ? 'Y' : 'N') . "', " . "monitor_url='" . SQL::escape($fields['monitor_url']) . "', " . "process_monitor='" . SQL::escape($fields['process_monitor'] == 'Y' ? 'Y' : 'N') . "', " . "submit_search='" . SQL::escape($fields['submit_search'] == 'Y' ? 'Y' : 'N') . "', " . "search_url='" . SQL::escape($fields['search_url']) . "', " . "process_search='" . SQL::escape($fields['process_search'] == 'Y' ? 'Y' : 'N') . "'," . "host_name='" . SQL::escape($fields['host_name']) . "'," . "active='" . SQL::escape($fields['active']) . "'";
         // maybe a silent update
         if (!isset($fields['silent']) || $fields['silent'] != 'Y') {
             $query .= ", " . "edit_name='" . SQL::escape($fields['edit_name']) . "', " . "edit_id=" . SQL::escape($fields['edit_id']) . ", " . "edit_address='" . SQL::escape($fields['edit_address']) . "', " . "edit_date='" . SQL::escape($fields['edit_date']) . "'";
         }
         $query .= " WHERE id = " . SQL::escape($fields['id']);
         if (SQL::query($query) === FALSE) {
             return $query . BR . SQL::error();
         }
         // insert a new record
     } else {
         // always remember the date
//.........这里部分代码省略.........
开发者ID:rair,项目名称:yacs,代码行数:101,代码来源:servers.php

示例8: do_run_patch

function do_run_patch()
{
    global $output, $lang_run_patch, $world_db, $realm_db, $characters_db, $mmfpm_db;
    if (empty($_POST['query']) || empty($_POST['use_db'])) {
        redirect('run_patch.php?error=1');
    }
    $sql = new SQL();
    $sql->connect($realm_db['addr'], $realm_db['user'], $realm_db['pass'], $realm_db['name']);
    $use_db = $sql->quote_smart($_POST['use_db']);
    $query = $_POST['query'];
    if ($use_db == $realm_db['name']) {
        $sql->db($realm_db['name']);
    } elseif ($use_db == $mmfpm_db['name']) {
        $sql->connect($mmfpm_db['addr'], $mmfpm_db['user'], $mmfpm_db['pass'], $mmfpm_db['name']);
    } else {
        foreach ($world_db as $db) {
            if ($use_db == $db['name']) {
                $sql->connect($db['addr'], $db['user'], $db['pass'], $db['name']);
            }
        }
        foreach ($characters_db as $db) {
            if ($use_db == $db['name']) {
                $sql->connect($db['addr'], $db['user'], $db['pass'], $db['name']);
            }
        }
    }
    unset($use_db);
    $new_queries = array();
    $line = 0;
    $queries = explode("\n", $query);
    unset($query);
    $n_queries = count($queries);
    for ($i = 0; $i < $n_queries; ++$i) {
        $queries[$i] = trim($queries[$i]);
        if (0 === strpos($queries[$i], '#') || 0 === strpos($queries[$i], '--')) {
            ++$line;
        } else {
            array_push($new_queries, $queries[$i]);
        }
    }
    unset($n_queries);
    $qr = split(";\n", implode("\n", $new_queries));
    unset($new_queries);
    $good = 0;
    $bad = 0;
    foreach ($qr as $qry) {
        ++$line;
        if (trim($qry)) {
            $sql->query(trim($qry)) ? ++$good : ++$bad;
        }
        if ($bad) {
            $err = ereg_replace('\\n', '', $sql->error());
            $err = ereg_replace('\\r\\n$', '', $err);
            $err = ereg_replace('\\r$', '', $err);
            error($lang_run_patch['err_in_line'] . ': ' . $line . ' <br />' . $err);
            exit;
        }
    }
    unset($qry);
    unset($qr);
    unset($line);
    unset($bad);
    if ($queries) {
        redirect('run_patch.php?error=2&tot=' . $good . '');
    } else {
        redirect('run_patch.php?error=3');
    }
}
开发者ID:BACKUPLIB,项目名称:minimanager-1,代码行数:68,代码来源:run_patch.php

示例9: setup_table

 /**
  * Create or alter the structure of one table
  *
  * @param string the name of the table to setup
  * @param array of $field_name => $field_declaration
  * @param array of $index_name => $index_declaration
  * @param array of SQL statements to be executed
  * @return a text string to print
  */
 public static function setup_table($table, $fields, $indexes, $statements = NULL)
 {
     global $context;
     // sanity check
     if (!$table) {
         return '';
     }
     // if the table does not exist
     if (!SQL::has_table($table)) {
         // create it
         $query = "CREATE TABLE " . SQL::table_name($table) . " ( ";
         $count = 0;
         foreach ($fields as $field => $definition) {
             if ($count++) {
                 $query .= ", ";
             }
             $query .= '`' . $field . '` ' . $definition;
         }
         foreach ($indexes as $index => $definition) {
             if ($count++) {
                 $query .= ", ";
             }
             $query .= $index . ' ' . $definition;
         }
         $query .= " ) ENGINE MyISAM";
         // else if the table exists
     } else {
         // check its structure
         $query = "ALTER TABLE " . SQL::table_name($table) . " ";
         // analyse table structure
         $query2 = "DESCRIBE " . SQL::table_name($table);
         if (!($result = SQL::query($query2))) {
             return '<p>' . Logger::error_pop() . "</p>\n";
         }
         // build the list of fields
         while ($row = SQL::fetch($result)) {
             $actual[] = $row['Field'];
         }
         // check all fields
         $count = 0;
         foreach ($fields as $field => $definition) {
             if ($count++) {
                 $query .= ", ";
             }
             if (in_array($field, $actual)) {
                 $query .= "MODIFY";
             } else {
                 $query .= "ADD";
             }
             $query .= ' `' . $field . '` ' . $definition;
         }
         // drop the primary index
         $query .= ", DROP PRIMARY KEY";
         // list existing indexes
         $query2 = "SHOW INDEX FROM " . SQL::table_name($table);
         if (!($result = SQL::query($query2))) {
             return '<p>' . Logger::error_pop() . "</p>\n";
         }
         // drop other indexes
         while ($row = SQL::fetch($result)) {
             if ($row['Seq_in_index'] == 1 && $row['Key_name'] != 'PRIMARY') {
                 $query .= ', DROP INDEX ' . $row['Key_name'];
             }
         }
         SQL::free($result);
         // build new indexes
         foreach ($indexes as $index => $definition) {
             $query .= ", ADD " . $index . ' ' . $definition;
         }
     }
     // execute the query
     if (SQL::query($query) !== FALSE) {
         // message to the user
         $text = BR . i18n::s('The table') . " '" . $table . "'";
         // it's a success
         if (strpos($query, 'CREATE') === 0) {
             $text .= ' ' . i18n::s('has been created');
         } else {
             $text .= ' ' . i18n::s('has been updated');
         }
         // ensure utf8 character set for this table
         $query = "ALTER TABLE " . SQL::table_name($table) . "  DEFAULT CHARACTER SET utf8";
         if (SQL::query($query) !== FALSE) {
             $text .= ' (utf8)';
         }
         // silently analyze table
         $query = "ANALYZE TABLE " . SQL::table_name($table);
         if (($result = SQL::query($query)) && ($row = SQL::fetch($result)) && $row['Msg_type'] == 'status') {
             $text .= ' ' . i18n::s('and analyzed');
             SQL::free($result);
         }
//.........这里部分代码省略.........
开发者ID:rair,项目名称:yacs,代码行数:101,代码来源:sql.php

示例10: while

     while ($tokens = fgetcsv($handle, 2048, $delimiter, $enclosure)) {
         // insert one record at a time
         $query = "INSERT INTO " . SQL::escape($_REQUEST['table_name']) . " (" . $headers . ") VALUES (";
         // use all provided tokens
         $index = 0;
         foreach ($tokens as $token) {
             if ($index++) {
                 $query .= ', ';
             }
             $query .= "'" . SQL::escape($token) . "'";
         }
         // finalize the statement
         $query .= ')';
         // execute the statement
         if (!SQL::query($query, TRUE) && SQL::errno()) {
             $context['text'] .= '<p>' . $here . ': ' . $query . BR . SQL::error() . "</p>\n";
         }
         $queries++;
         // ensure we have enough time
         if (!($queries % 50)) {
             Safe::set_time_limit(30);
         }
     }
     // clear the cache
     Cache::clear();
     // report of script data
     $time = round(get_micro_time() - $context['start_time'], 2);
     $context['text'] .= '<p>' . sprintf(i18n::s('%d SQL statements have been processed in %.2f seconds.'), $queries, $time) . '</p>';
     // remember this in log as well
     Logger::remember('tables/import.php: Data has been imported into ' . $_REQUEST['table_name'], $queries . ' SQL statements have been processed in ' . $time . ' seconds.');
 }
开发者ID:rair,项目名称:yacs,代码行数:31,代码来源:import.php

示例11: purge

 /**
  * delete all documentation pages
  */
 public static function purge()
 {
     global $context;
     // purge the old documentation
     $query = "DELETE FROM " . SQL::table_name('phpdoc');
     if (SQL::query($query, TRUE) === FALSE && SQL::errno()) {
         echo $query . BR . SQL::error() . BR . "\n";
     }
 }
开发者ID:rair,项目名称:yacs,代码行数:12,代码来源:phpdoc.php


注:本文中的SQL::error方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。