Example #1
0
 public static function find($modelName, $where = '1')
 {
     Model::dbConnect();
     $models = array();
     $sql = mysql_query("SELECT * FROM {$modelName} WHERE {$where}");
     while ($row = mysql_fetch_object($sql, $modelName)) {
         $models[] = $row;
     }
     return $models;
 }
Example #2
0
 public static function find($id)
 {
     // Get connection to the database
     parent::dbConnect();
     // @TODO: Create select statement using prepared statements
     $stmt = parent::$dbc->prepare('SELECT * FROM users WHERE user_id = :id');
     $stmt->bindValue(':id', $id, PDO::PARAM_INT);
     $stmt->execute();
     // @TODO: Store the resultset in a variable named $result
     $results = $stmt->fetch(PDO::FETCH_ASSOC);
     // The following code will set the attributes on the calling object based on the result variable's contents
     $instance = null;
     if ($results) {
         $instance = new static();
         $instance->attributes = $results;
     }
     return $instance;
 }
 static function Init($setting)
 {
     self::$set = $setting;
     self::$db_static = parent::dbConnect(self::$set['database']);
     $host = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : "";
     if ($host && !preg_match("/\\d+\\.\\d+.\\d+.\\d+/", $host)) {
         ini_set("session.cookie_domain", strstr($host, "."));
     }
     //不使用 GET/POST 变量方式
     ini_set('session.use_trans_sid', 0);
     //设置垃圾回收最大生存时间
     ini_set('session.gc_maxlifetime', self::$set['lifeTime']);
     //使用 COOKIE 保存 SESSION ID 的方式
     ini_set('session.use_cookies', 1);
     ini_set('session.cookie_path', '/');
     //多主机共享保存 SESSION ID 的 COOKIE
     //将 session.save_handler 设置为 user,而不是默认的 files
     session_module_name('user');
     //定义 SESSION 各项操作所对应的方法名:
     session_set_save_handler(array('SessionHandleMySQL', 'open'), array('SessionHandleMySQL', 'close'), array('SessionHandleMySQL', 'read'), array('SessionHandleMySQL', 'write'), array('SessionHandleMySQL', 'destroy'), array('SessionHandleMySQL', 'gc'));
     session_start();
 }
Example #4
0
 function view_main()
 {
     $this->db = Model::dbConnect($GLOBALS["gDataBase"]["db"]);
     $serverinfo = PHP_OS . ' / PHP v' . PHP_VERSION;
     $serverinfo .= @ini_get('safe_mode') ? ' Safe Mode' : NULL;
     $dbversion = $this->db->getOne("SELECT VERSION()");
     $fileupload = @ini_get('file_uploads') ? ini_get('upload_max_filesize') : '<font color="red">' . $lang['no'] . '</font>';
     $dbsize = 0;
     $query = $tables = $this->db->getAll("SHOW TABLE STATUS");
     foreach ($tables as $table) {
         $dbsize += $table['Data_length'] + $table['Index_length'];
     }
     $dbsize = $dbsize ? size_unit_convert($dbsize) : $lang['unknown'];
     $dbversion = $this->db->getOne("SELECT VERSION()");
     $magic_quote_gpc = get_magic_quotes_gpc() ? 'On' : 'Off';
     $allow_url_fopen = ini_get('allow_url_fopen') ? 'On' : 'Off';
     $this->tpl->assign('serverinfo', $serverinfo);
     $this->tpl->assign('fileupload', $fileupload);
     $this->tpl->assign('dbsize', $dbsize);
     $this->tpl->assign('dbversion', $dbversion);
     $this->tpl->assign('magic_quote_gpc', $magic_quote_gpc);
     $this->tpl->assign('allow_url_fopen', $allow_url_fopen);
 }
    public function insert()
    {
        parent::dbConnect();
        $query = 'INSERT INTO ads (title, vendor, city, state, zip, category, origin, style, vintage, price, description, image, post_date)
								VALUES (:title, :vendor, :city, :state, :zip, :category, :origin, :style, :vintage, :price, :description, :image, :post_date);';
        $stmt = parent::$dbc->prepare($query);
        $stmt->bindValue(':title', $this->title, PDO::PARAM_STR);
        $stmt->bindValue(':vendor', $this->vendor, PDO::PARAM_STR);
        $stmt->bindValue(':city', $this->city, PDO::PARAM_STR);
        $stmt->bindValue(':state', $this->state, PDO::PARAM_STR);
        $stmt->bindValue(':zip', $this->zip, PDO::PARAM_STR);
        $stmt->bindValue(':category', $this->category, PDO::PARAM_STR);
        $stmt->bindValue(':origin', $this->origin, PDO::PARAM_STR);
        $stmt->bindValue(':style', $this->style, PDO::PARAM_STR);
        $stmt->bindValue(':vintage', $this->vintage, PDO::PARAM_INT);
        $stmt->bindValue(':price', $this->price, PDO::PARAM_INT);
        $stmt->bindValue(':description', $this->description, PDO::PARAM_STR);
        $stmt->bindValue(':image', $this->image, PDO::PARAM_STR);
        $stmt->bindValue(':post_date', $this->post_date, PDO::PARAM_STR);
        return $stmt->execute();
    }
Example #6
0
 /**
  * execTime
  * @access public
  * @return void
  */
 public function execTime()
 {
     $exec_time = getmicrotime() - $GLOBALS['gAppStartTime'];
     $memused = memory_get_usage();
     if ($exec_time > $GLOBALS['gLog']['maxExecTime'] || $memused > $GLOBALS['gLog']['maxMemUsed']) {
         if (isset($GLOBALS['gDataBase']['db_setting.db3']) && !empty($GLOBALS['gDataBase']['db_setting.db3'])) {
             $db = Model::dbConnect($GLOBALS['gDataBase']['db_setting.db3']);
             $datetime = date("Y-m-d H:i:s");
             if (isset($db) && is_object($db)) {
                 $is_table_exists = $db->getOne("SELECT name FROM sqlite_master WHERE type='table' AND name='eventlog'");
                 if (!$is_table_exists) {
                     $db->execute("CREATE TABLE eventlog (eid INTEGER NOT NULL PRIMARY KEY,visit DATETIME,exec_time FLOAT,memuse DOUBLE,url VARCHAR(255) )");
                 }
                 $db->execute("replace into eventlog (url,visit,exec_time,memuse) values ('" . addslashes(WEB_URL) . "','{$datetime}','{$exec_time}','{$memused}')");
             }
         }
     }
     //exit("<!-- execute time :".$exec_time."-->");
 }
 public function __construct()
 {
     $this->db = parent::dbConnect($GLOBALS["gDataBase"]["db"]);
 }
Example #8
0
function error_live_handler($errno, $errmsg, $filename, $linenum, $vars)
{
    //echo $errno;
    // 错误发生时间
    $dt = date("Y-m-d H:i:s (T)");
    //定义错误类型为一个数组
    $errortype = array(E_ERROR => 'Error(代码严重错误)', E_WARNING => 'Warning(代码警告)', E_PARSE => 'Parsing Error(代码格式错误)', E_NOTICE => 'Notice(代码建议提示)', E_CORE_ERROR => 'Core Error(PHP内核错误)', E_CORE_WARNING => 'Core Warning(PHP内核警告)', E_COMPILE_ERROR => 'Compile Error(编译错误)', E_COMPILE_WARNING => 'Compile Warning(编译警告)', E_USER_ERROR => 'User Error(用户错误)', E_USER_WARNING => 'User Warning(用户警告)', E_USER_NOTICE => 'User Notice(用户提示)', E_STRICT => 'Runtime Notice', E_RECOVERABLE_ERROR => 'Catchable Fatal Error');
    // 哪一类型的错误会被写入日志
    $log_errors = array(E_ERROR, E_WARNING, E_PARSE, E_NOTICE, E_USER_ERROR, E_USER_WARNING, E_USER_NOTICE, E_RECOVERABLE_ERROR, E_STRICT);
    // 哪一类型的错误会被发送邮件到开发人员
    $devloper_errors = array(E_CORE_ERROR, E_CORE_WARNING, E_COMPILE_ERROR, E_COMPILE_WARNING, E_ERROR, E_WARNING, E_PARSE, E_NOTICE, E_USER_ERROR, E_USER_WARNING, E_USER_NOTICE, E_RECOVERABLE_ERROR, E_STRICT);
    // 哪一类型的错误会被呈现到用户面前
    $display_user_errors = array(E_NOTICE, E_ERROR, E_WARNING, E_PARSE, E_USER_ERROR);
    if (php_sapi_name() != "cli") {
        $host = $_SERVER["SERVER_ADDR"];
    } else {
        $host = '127.0.0.1';
        define('WEB_URL', $_SERVER["SCRIPT_NAME"]);
    }
    $num = "";
    $tmp = "";
    list($tmp, $tmp, $tmp, $num) = explode(".", $host);
    $crcno = sprintf("%u", crc32($linenum . $filename . $errmsg));
    $errNum = $num . '.' . $crcno;
    // Get a unique error ID for this
    if (in_array($errno, $log_errors)) {
        $error_exit = is_error_in_log($crcno);
        if ($error_exit < 1) {
            $brief_message = "<strong>ErrorNo: #{$errNum}:</strong>\n\t\t\t\t\t\t<p style='font-size: 15px;'>\n\t\t\t\t\t   <span style='color: #FF1111;'> 发生时间: </span> {$dt}<br />\n\t\t\t\t\t\t<span style='color: #FF1111;'> {$errortype[$errno]} </span>\n\t\t\t\t\t\t&nbsp;\n\t\t\t\t\t\t\"" . htmlspecialchars($errmsg) . "\" in file {$filename} (on line {$linenum})<br />\n\t\t\t\t\t\t<span style='color: #FF1111;'> URL: </span> \"" . BASE_URL . "\"\n\t\t\t\t\t\t</p>";
            $backtrace_msg = "\n\t\t\t\t\t\t<span id=\"{$errNum}\"> " . "<br>" . fetch_backtrace() . "<br />" . get_misc_error_info() . "\n\t\t\t\t\t\t</span>\n\t\t\t\t\t\t";
            //Do not log repeated messages
            error_log($crcno . "\n", 3, LOG_FILE_DIR . "/ignore_repeated_errors.txt");
            // log error backtrace in database
            if (isset($GLOBALS['gDataBase']['db_setting.db3']) && !empty($GLOBALS['gDataBase']['db_setting.db3'])) {
                if (!class_exists("Database")) {
                    require_once "Libs/Database.class.php";
                }
                $db = Model::dbConnect($GLOBALS['gDataBase']['db_setting.db3']);
                $is_table_exists = $db->getOne("SELECT name FROM sqlite_master WHERE type='table' AND name='errorlog'");
                if (!$is_table_exists) {
                    $db->execute("CREATE TABLE errorlog (\n\t\t\t\t\t  id             integer PRIMARY KEY AUTOINCREMENT NOT NULL,\n\t\t\t\t\t  error_no       varchar(32) NOT NULL,\n\t\t\t\t\t  linenum        integer DEFAULT 6,\n\t\t\t\t\t  filename       varchar DEFAULT 255,\n\t\t\t\t\t  errmsg         varchar DEFAULT 255,\n\t\t\t\t\t  backtrace_msg  text\n\t\t\t\t\t)");
                }
                if (!$db->getOne("select error_no from errorlog where error_no='{$errNum}'")) {
                    $db->execute("insert into errorlog (error_no,linenum,filename,errmsg,backtrace_msg) values ('{$errNum}','{$linenum}','{$filename}','" . htmlspecialchars($errmsg, ENT_QUOTES) . "','" . htmlspecialchars($backtrace_msg, ENT_QUOTES) . "')");
                }
            }
            //send email to notice
            if (isset($GLOBALS['gLog']['sendemail']) && $GLOBALS['gLog']['sendemail'] == 1) {
                send_email($GLOBALS['gEmail']['smtp_from'], $GLOBALS['gLog']['receiver'], $GLOBALS['gLog']['subject'], $brief_message . $backtrace_msg);
            }
        }
    }
    if (in_array($errno, $display_user_errors)) {
        //header("location: http://image.guodong.dev2/500.html");
        //echo "<script>window.location.replace('http://image.guodong.dev2/500.html');</script>";
        $message = "\n\t\t<meta http-equiv='Content-Type' content='text/html; charset=UTF-8' />\n\t\t<meta http-equiv='pragma' content='no-cache' />\n\t\t<meta HTTP-EQUIV='cache-control' content='no-cache'>\n\t\t<p style='font-size: 12px;'>\n\t\t<strong>该应用发生错误。 错误代号: #{$errNum}. <a href='mailto:" . $GLOBALS['gEmail']['smtp_from'] . "?subject=errorNum:" . $errNum . "&body=Thank You!'>通知管理员。</strong>\n\t\t</p>\n\t\t";
        echo $message;
        die;
        //echo $message;
    }
}
    public function insert()
    {
        parent::dbConnect();
        $query = 'INSERT INTO users (username, password, email, age)
								VALUES (:username, :password, :email, :age);';
        $stmt = parent::$dbc->prepare($query);
        $stmt->bindValue(':username', $this->username, PDO::PARAM_STR);
        $stmt->bindValue(':password', $this->password, PDO::PARAM_STR);
        $stmt->bindValue(':email', $this->email, PDO::PARAM_STR);
        $stmt->bindValue(':age', $this->age, PDO::PARAM_INT);
        return $stmt->execute();
    }
Example #10
0
<?php

require_once 'Model.php';
class User extends Model
{
    protected static $table = 'contacts';
}
Model::dbConnect();