本文整理汇总了PHP中_init函数的典型用法代码示例。如果您正苦于以下问题:PHP _init函数的具体用法?PHP _init怎么用?PHP _init使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了_init函数的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: connect
function connect()
{
$dsn = \str_replace('$ROOTDIR', \dirname(__DIR__), \bmtmgr\config\get('db_dsn'));
$db = new \PDO($dsn);
$db->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
$db->setAttribute(\PDO::ATTR_DEFAULT_FETCH_MODE, \PDO::FETCH_ASSOC);
// Do we need to initialize?
if (\bmtmgr\config\get('allow_init', false)) {
if (\bmtmgr\config\get('test_force_init', false)) {
_init($db);
return $db;
}
$init_sql = \file_get_contents(dirname(__DIR__) . '/db_init.sql');
if (!\preg_match('/INSERT INTO db_version.*VALUES\\s*\\(([0-9]+)\\)/', $init_sql, $matches)) {
throw new \Exception('Cannot detect version number');
}
$newest_version = \intval($matches[1]);
try {
$vdata = $db->query('SELECT version FROM db_version');
} catch (\PDOException $e) {
_init($db);
return $db;
}
$version = -1;
foreach ($vdata as $row) {
$version = $row['version'];
}
if ($version < $newest_version) {
_init($db);
}
}
return $db;
}
示例2: define
<?php
define('DATABASE', '/Users/hasan_azimi0/Sites/phpLiteAdmin/db/test.sqlite3');
define('TITLE', 'PHP testing sandbox');
define('VERSION', '1.0.4');
define('HEADER', '../../assets/header.php');
define('BODY', '../../assets/body.php');
define('FOOTER', '../../assets/footer.php');
_init();
main();
page();
function main()
{
global $G;
message("PHP testing sandbox (%s) version %s", $G['ME'], VERSION);
try {
$db = new PDO('sqlite:' . DATABASE);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$db->exec('DROP TABLE IF EXISTS t');
$db->exec('CREATE TABLE t (a, b, c)');
message('Table t sucessfully created');
$sth = $db->prepare('INSERT INTO t VALUES (?, ?, ?)');
$sth->execute(array('a', 'b', 'c'));
$sth->execute(array(1, 2, 3));
$sth->execute(array('one', 'two', 'three'));
$sth = $db->prepare('SELECT * FROM t');
$sth->setFetchMode(PDO::FETCH_ASSOC);
$sth->execute();
foreach ($sth as $row) {
message('%s, %s, %s', $row['a'], $row['b'], $row['c']);
}