コード例 #1
0
 /**
  * Get singleton instance of DbFactory
  * @return DbFactory
  */
 public static function getFactory() : DbFactory
 {
     if (!self::$factory) {
         self::$factory = new DbFactory();
     }
     return self::$factory;
 }
コード例 #2
0
 /**
  * @param string $table 表名
  * @param bool $full 是否为全表名
  * @param string $driver 连接驱动
  */
 public function __construct($table = null, $full = null, $driver = null)
 {
     $this->tableName = $this->getTable($table, $full);
     //初始化默认表
     $this->db = DbFactory::factory($driver, $this->tableName);
     //获得数据库引擎
 }
コード例 #3
0
ファイル: Model.class.php プロジェクト: lililishuang/hdcms
 protected function run($table, $full = false, $driver = null)
 {
     //初始化默认表
     $this->getTable($table, $full);
     //获得数据库引擎
     $db = DbFactory::factory($driver, $this->tableFull);
     if ($db) {
         $this->db = $db;
     } else {
         //连接异常
         if (DEBUG) {
             error("数据库连接错误", false);
         } else {
             Log::write("数据库连接错误");
         }
     }
 }
コード例 #4
0
ファイル: Model.class.php プロジェクト: www2511550/ECSHOP
 /**
  * 构造函数
  * @param null $table 表名
  * @param bool $full 全表名
  * @param null $driver 驱动
  * @param array $param 参数
  */
 public function __construct($table = null, $full = null, $param = array(), $driver = null)
 {
     /**
      * 初始化默认表
      * 如果设置了table属性时,使用table属性值为表名
      */
     if (!$this->table) {
         $this->table = $table;
     }
     /**
      * 获得数据库引擎
      */
     $this->db = DbFactory::factory($driver, $this->table, $full);
     /**
      * 执行子类构造函数__init
      */
     if (method_exists($this, "__init")) {
         $this->__init($param);
     }
 }
コード例 #5
0
ファイル: index.php プロジェクト: EdwardBlack13/ezrpg-1.0.x
    function start()
    {
        if (!isset($_POST['submit'])) {
            $dbhost = "localhost";
            $dbuser = "******";
            $dbname = "ezrpg";
            $dbprefix = "ezrpg_";
        } else {
            $dbhost = $_POST['dbhost'];
            $dbuser = $_POST['dbuser'];
            $dbname = $_POST['dbname'];
            $dbpass = $_POST['dbpass'];
            $dbprefix = $_POST['dbprefix'];
            $error = 0;
            //test database connection.
            try {
                $db = DbFactory::factory('mysql', $dbhost, $dbuser, $dbpass, $dbname);
            } catch (DbException $e) {
                $error = 1;
            }
            if ($error != 1) {
                require_once "../lib/func.rand.php";
                $secret_key = createKey(24);
                $config = <<<CONF
<?php
//This file cannot be viewed, it must be included
defined('IN_EZRPG') or exit;

/*
  Title: Config
  The most important settings for the game are set here.
*/

/*
  Variables: Database Connection
  Connection settings for the database.
  
  \$config_server - Database server
  \$config_dbname - Database name
  \$config_username - Username to login to server with
  \$config_password - Password to login to server with
  \$config_driver - Contains the database driver to use to connect to the database.
*/
\$config_server = '{$dbhost}';
\$config_dbname = '{$dbname}';
\$config_username = '******';
\$config_password = '******';
\$config_driver = 'mysql';

/*
  Constant:
  This secret key is used in the hashing of player passwords and other important data.
  Secret keys can be of any length, however longer keys are more effective.
  
  This should only ever be set ONCE! Any changes to it will cause your game to break!
  You should save a copy of the key on your computer, just in case the secret key is lost or accidentally changed,.
  
  SECRET_KEY - A long string of random characters.
*/
define('SECRET_KEY', '{$secret_key}');


/*
  Constants: Settings
  Various settings used in ezRPG.
  
  DB_PREFIX - Prefix to the table names
  VERSION - Version of ezRPG
  SHOW_ERRORS - Turn on to show PHP errors.
  DEBUG_MODE - Turn on to show database errors and debug information.
*/
define('DB_PREFIX', '{$dbprefix}');
define('VERSION', '1.0.7 lang');
define('SHOW_ERRORS', 0);
define('DEBUG_MODE', 0);
?>
CONF;
                $fh = fopen('../config.php', 'w');
                fwrite($fh, $config);
                fclose($fh);
                $this->header();
                echo "<h2>Configuration file written</h2>\n";
                echo "<p>The configuration has ben verified, and the config.php file has been successfully written.</p><br />\n";
                echo "<a href=\"index.php?step=Populate\">Continue to next step</a>";
                $this->footer();
                die;
            }
        }
        $this->header();
        echo "<h2>Database Configuration</h2><br />\n";
        echo '<form method="post">';
        echo '<label>Host</label>';
        echo '<input type="text" name="dbhost" value="' . $dbhost . '" />';
        echo '<label>Database Name</label>';
        echo '<input type="text" name="dbname" value="' . $dbname . '" />';
        echo '<label>User</label>';
        echo '<input type="text" name="dbuser" value="' . $dbuser . '" />';
        echo '<label>Password</label>';
        echo '<input type="password" name="dbpass" value="" />';
        echo '<label>Table Prefix (Optional)</label>';
        echo '<input type="text" name="dbprefix" value="', $dbprefix, '" />';
        echo '<p>You can enter a prefix for your table names if you like.<br />This can be useful if you will be sharing the database with other applications, or if you are running more than one ezRPG instance in a single database.</p>';
        echo '<input type="submit" name="submit" value="Submit"  class="button" />';
        echo '</form>';
    }
コード例 #6
0
ファイル: Boot.php プロジェクト: jyht/v5
 protected function run($table, $full = null, $driver = null)
 {
     $this->getTable($table, $full);
     $db = DbFactory::factory($driver, $this->tableFull);
     if ($db) {
         $this->db = $db;
     } else {
         if (DEBUG) {
             error(mysqli_connect_error() . "数据库连接出错了请检查配置文件中的参数", false);
         } else {
             log_write("数据库连接出错了请检查配置文件中的参数");
         }
     }
     $vars = get_object_vars($this);
     unset($vars['default']);
     $this->default = $vars;
 }
コード例 #7
0
ファイル: index.php プロジェクト: EdwardBlack13/ezrpg-1.0.x
 function start()
 {
     if (!isset($_POST['submit'])) {
         $username = '';
         $email = '';
     } else {
         $errors = 0;
         $msg = '';
         $username = $_POST['username'];
         $password = $_POST['password'];
         $password2 = $_POST['password2'];
         $email = $_POST['email'];
         if (empty($username) || empty($email) || empty($password) || empty($password2)) {
             $errors = 1;
             $msg .= 'You forgot to fill in something!';
         }
         if ($password != $password2) {
             $errors = 1;
             $msg .= 'You didn\'t verify your password correctly.';
         }
         if ($errors == 0) {
             require_once "../config.php";
             require_once "../lib/func.rand.php";
             try {
                 $db = DbFactory::factory($config_driver, $config_server, $config_username, $config_password, $config_dbname);
             } catch (DbException $e) {
                 $e->__toString();
             }
             $secret_key = createKey(16);
             $insert['username'] = $username;
             $insert['password'] = sha1($secret_key . $password . SECRET_KEY);
             $insert['email'] = $email;
             $insert['secret_key'] = $secret_key;
             $insert['registered'] = time();
             $insert['rank'] = 10;
             $db->insert('<ezrpg>players', $insert);
             $insert = array();
             $this->header();
             echo "<p>Your admin account has been created! You may now login to the game.</p>\n";
             $fh = fopen("lock", "w+");
             if (!$fh) {
                 echo "<p>You need to delete the install directory for security reasons as we were unable to lock it.</p>\n";
             }
             echo "<p><a href=\"../index.php\">Continue to your game</a></p>";
             fclose($fh);
             $this->footer();
             exit;
         } else {
             $this->header();
             echo '<p><strong>Sorry, there were some problems:</strong><br />', $msg, '</p>';
             $this->footer();
         }
     }
     $this->header();
     echo '<h2>Create your admin account for ezRPG.</h2>';
     echo '<form method="post">';
     echo '<label>Username</label>';
     echo '<input type="text" name="username" value="', $username, '" />';
     echo '<label>Email</label>';
     echo '<input type="text" name="email" value="', $email, '" />';
     echo '<label>Password</label>';
     echo '<input type="password" name="password" />';
     echo '<label>Verify Password</label>';
     echo '<input type="password" name="password2" />';
     echo '<br />';
     echo '<input type="submit" value="Create" name="submit" class="button" />';
     echo '</form>';
 }
コード例 #8
0
ファイル: ~boot.php プロジェクト: jyht/v5
 protected function run($table, $full = false, $driver = null)
 {
     $this->getTable($table, $full);
     $db = DbFactory::factory($driver, $this->tableFull);
     if ($db) {
         $this->db = $db;
     } else {
         if (DEBUG) {
             error(mysqli_connect_error() . "数据库连接出错了请检查配置文件中的参数", false);
         } else {
             Log::write("数据库连接出错了请检查配置文件中的参数");
         }
     }
 }
コード例 #9
0
ファイル: index.php プロジェクト: EdwardBlack13/ezrpg-1.0.x
    function start()
    {
        require_once "../config.php";
        try {
            $db = DbFactory::factory($config_driver, $config_server, $config_username, $config_password, $config_dbname);
        } catch (DbException $e) {
            $e->__toString();
        }
        $query1 = <<<QUERY
CREATE TABLE IF NOT EXISTS `<ezrpg>players` (
  `id` int(11) unsigned NOT NULL auto_increment,
  `username` varchar(30) default NULL,
  `password` varchar(40) default NULL,
  `email` varchar(255) default NULL,
  `secret_key` text,
  `rank` smallint(5) unsigned NOT NULL default '1',
  `registered` int(11) unsigned default NULL,
  `last_active` int(11) unsigned default '0',
  `last_login` int(11) unsigned default '0',
  `money` int(11) unsigned default '100',
  `bank` int(11) unsigned default '0',
  `level` int(11) unsigned default '1',
  `stat_points` int(11) unsigned default '10',
  `exp` int(11) unsigned default '0',
  `max_exp` int(11) unsigned default '10',
  `hp` int(11) unsigned default '20',
  `max_hp` int(11) unsigned default '20',
  `energy` int(11) unsigned NOT NULL default '10',
  `max_energy` int(11) unsigned NOT NULL default '10',
  `strength` int(11) unsigned default '5',
  `vitality` int(11) unsigned default '5',
  `agility` int(11) unsigned default '5',
  `dexterity` int(11) unsigned default '5',
  `damage` int(11) unsigned default '0',
  `kills` int(11) unsigned NOT NULL default '0',
  `deaths` int(11) unsigned NOT NULL default '0',
  `ban` int(11) unsigned default '0',
  `race` int(11) unsigned DEFAULT '0',
  `ban_forum` int(11) unsigned DEFAULT '0',
  `lang` varchar(30) NOT NULL DEFAULT 'english',
  `sex` varchar(8) NOT NULL DEFAULT 'male',
  PRIMARY KEY  (`id`),
  UNIQUE KEY `username` (`username`),
  UNIQUE KEY `email` (`email`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8;
QUERY;
        $db->execute($query1);
        $query2 = <<<QUERY
CREATE TABLE IF NOT EXISTS `<ezrpg>player_log` (
  `id` int(11) unsigned NOT NULL auto_increment,
  `player` int(11) unsigned NOT NULL,
  `time` int(11) unsigned NOT NULL,
  `message` text NOT NULL,
  `status` tinyint(1) unsigned NOT NULL default '0',
  PRIMARY KEY  (`id`),
  KEY `player_log` (`player`,`time`),
  KEY `new_logs` (`player`,`status`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
QUERY;
        $db->execute($query2);
        $this->header();
        echo "<h2>The database has been populated.</h2>\n";
        echo "<a href=\"index.php?step=ZeggyJesterC\">Continue to next step</a>";
        $this->footer();
    }
コード例 #10
0
ファイル: init.php プロジェクト: EdwardBlack13/ezrpg-1.0.x
//header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
//header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
//Constants
define('CUR_DIR', realpath(dirname(__FILE__)));
define('MOD_DIR', CUR_DIR . '/modules');
define('ADMIN_DIR', CUR_DIR . '/admin');
define('LIB_DIR', CUR_DIR . '/lib');
define('EXT_DIR', LIB_DIR . '/ext');
define('HOOKS_DIR', CUR_DIR . '/hooks');
require_once CUR_DIR . '/config.php';
//Show errors?
SHOW_ERRORS == 0 ? error_reporting(0) : error_reporting(E_ALL);
require_once CUR_DIR . '/lib.php';
//Database
try {
    $db = DbFactory::factory($config_driver, $config_server, $config_username, $config_password, $config_dbname);
} catch (DbException $e) {
    $e->__toString();
}
//Database password no longer needed, unset variable
unset($config_password);
//HTML Purifier Config
$purifier_config = HTMLPurifier_Config::createDefault();
$purifier_config->set('HTML.Allowed', 'b,a[href],i,br,em,strong,ul,li');
$purifier_config->set('URI.Base', $_SERVER['DOCUMENT_ROOT']);
$purifier_config->set('URI.MakeAbsolute', true);
$purifier_config->set('URI.DisableExternal', true);
$purifier = new HTMLPurifier($purifier_config);
//Smarty
$tpl = new Smarty();
$tpl->template_dir = CUR_DIR . '/smarty/templates/';
コード例 #11
0
ファイル: index.php プロジェクト: EdwardBlack13/ezrpg-1.0.x
    function start()
    {
        require_once "../config.php";
        try {
            $db = DbFactory::factory($config_driver, $config_server, $config_username, $config_password, $config_dbname);
        } catch (DbException $e) {
            $e->__toString();
        }
        $query1 = <<<QUERY
CREATE TABLE  `<ezrpg>settings` (
  `id` smallint(5) unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(120) NOT NULL,
  `title` varchar(120) NOT NULL,
  `description` text,
  `optionscode` text,
  `value` text,
  UNIQUE KEY `id` (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8;
QUERY;
        $db->execute($query1);
        $query2 = <<<QUERY
CREATE TABLE IF NOT EXISTS `<ezrpg>forum_cat` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `title` varchar(30) NOT NULL,
  `description` text NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
QUERY;
        $db->execute($query2);
        $query3 = <<<QUERY
CREATE TABLE IF NOT EXISTS `<ezrpg>forum_mes` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `id_top` int(11) NOT NULL,
  `id_cat` int(11) NOT NULL,
  `poster` varchar(15) NOT NULL,
  `message` text NOT NULL,
  `date` int(11) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8;
QUERY;
        $db->execute($query3);
        $query4 = <<<QUERY
CREATE TABLE IF NOT EXISTS `<ezrpg>forum_top` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `id_cat` int(11) NOT NULL,
  `starter` varchar(15) NOT NULL,
  `title` varchar(60) NOT NULL,
  `message` text NOT NULL,
  `date` int(11) NOT NULL,
  `topic` enum('ON','OFF') NOT NULL DEFAULT 'ON',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
QUERY;
        $db->execute($query4);
        $data1 = <<<QUERY
INSERT INTO `<ezrpg>settings` (`id`, `name`, `title`, `description`, `optionscode`, `value`) VALUES
(1, 'game_name', 'Untitled', 'The title for your game', 'version', '0.0.1'),
(2, 'core_name', 'ezRPG', 'The title for your core', 'version', '1.0.7 lang'),
(3, 'english', 'English', NULL, 'language', 'English'),
(4, 'deutsch', 'Deutsch', NULL, 'language', 'Deutsch'),
(5, 'russian', 'Russian', NULL, 'language', 'Russian');
QUERY;
        $db->execute($data1);
        $this->header();
        echo "<h2>The database has been ForumLang.</h2>\n";
        echo "<a href=\"index.php?step=CreateAdmin\">Continue to next step</a>";
        $this->footer();
    }
コード例 #12
0
ファイル: index.php プロジェクト: EdwardBlack13/ezrpg-1.0.x
    function start()
    {
        require_once "../config.php";
        try {
            $db = DbFactory::factory($config_driver, $config_server, $config_username, $config_password, $config_dbname);
        } catch (DbException $e) {
            $e->__toString();
        }
        $query1 = <<<QUERY
CREATE TABLE  `<ezrpg>mines` (
  `id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
  `player` INT UNSIGNED NOT NULL ,
  `mines` INT UNSIGNED NOT NULL DEFAULT  '1',
  `rocks` INT UNSIGNED NOT NULL DEFAULT  '0',
  `copper` INT UNSIGNED NOT NULL DEFAULT  '0',
  `diamonds` INT UNSIGNED NOT NULL DEFAULT  '0',
  PRIMARY KEY  (`id`),
  UNIQUE (`player`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8;
QUERY;
        $db->execute($query1);
        $query2 = <<<QUERY
CREATE TABLE IF NOT EXISTS `<ezrpg>bots` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(30) default NULL,
  `level` int(11) unsigned NOT NULL,
  `health` int(11) unsigned NOT NULL,
  `damage` int(11) unsigned NOT NULL,
  `exp` int(11) unsigned NOT NULL,
  `money` int(11) unsigned NOT NULL,
  PRIMARY KEY  (`id`),
  KEY `level` (`level`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
QUERY;
        $db->execute($query2);
        $query3 = <<<QUERY
CREATE TABLE IF NOT EXISTS `<ezrpg>items` (
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`class` VARCHAR( 50 ) NOT NULL ,
`player` INT UNSIGNED NOT NULL ,
`name` VARCHAR( 50 ) NOT NULL ,
`value1` INT NOT NULL ,
`value2` INT NOT NULL ,
`value3` INT NOT NULL ,
`value4` INT NOT NULL ,
`value5` INT NOT NULL ,
INDEX (  `player` )
) ENGINE=InnoDB  DEFAULT CHARSET=utf8;
QUERY;
        $db->execute($query3);
        $query4 = <<<QUERY
CREATE TABLE IF NOT EXISTS `<ezrpg>mail` (
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`to` VARCHAR( 50 ) NOT NULL ,
`from` VARCHAR( 50 ) NOT NULL ,
`subject` VARCHAR( 45 ) NOT NULL ,
`date` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ,
`isread` INT( 1 ) NOT NULL ,
`message` VARCHAR( 5000 ) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
QUERY;
        $db->execute($query4);
        $this->header();
        echo "<h2>The database has been ZeggyJesterc.</h2>\n";
        echo "<a href=\"index.php?step=ForumLang\">Continue to next step</a>";
        $this->footer();
    }