本文整理汇总了PHP中DatabaseConnection::exec方法的典型用法代码示例。如果您正苦于以下问题:PHP DatabaseConnection::exec方法的具体用法?PHP DatabaseConnection::exec怎么用?PHP DatabaseConnection::exec使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DatabaseConnection
的用法示例。
在下文中一共展示了DatabaseConnection::exec方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: exec
/** @return int|void */
public static function exec($query, $args = null, $flags = 0)
{
if (!self::$default && self::$connectHandler) {
self::$connectHandler[0]->{self::$connectHandler[1]}();
}
return self::$default->exec($query, $args, $flags);
}
示例2: alias
/**
*
*
*
*
*/
public function alias()
{
$this->checkData();
console::writeLn("Generating geoalias table");
$db = new DatabaseConnection();
$db->exec('DROP TABLE IF EXISTS geoalias');
$db->exec('CREATE TABLE geoalias (id INT PRIMARY KEY AUTO_INCREMENT, geoid BIGINT, locname VARCHAR(64) CHARSET utf8, INDEX locname(locname(5))) CHARSET utf8');
$rows = $db->getRows("SELECT id,alternatenames FROM geonames WHERE alternatenames!=''");
console::write('%8d / %8d ', 0, count($rows));
foreach ($rows as $row) {
$alt = explode(',', $row['alternatenames']);
foreach ($alt as $altstr) {
$db->insertRow("INSERT INTO geoalias (geoid,locname) VALUES (%d,%s)", $row['id'], $altstr);
}
$rc++;
$rt++;
if ($rt >= 100) {
$rh++;
if ($rh >= 50) {
console::write("\n%8d / %8d ", $rc, count($rows));
$rh = 0;
} else {
console::write('.');
}
$rt = 0;
}
}
console::writeLn(' Done!');
}
示例3: initialize
public function initialize($rootuser = null)
{
console::writeLn(__astr('\\b{Initializing database}'));
$db = config::get('lepton.db.default');
$dbc = config::get('lepton.db.default');
console::writeLn(" Database: %s", $dbc['database']);
console::writeLn(" User: %s", $dbc['username']);
console::writeLn(" Host: %s", $dbc['hostname']);
switch ($db['driver']) {
case 'pdo/mysql':
case 'mysql':
console::writeLn(" Driver: MySQL");
break;
default:
console::fatal('This version of the script does not support anything else than MySQL');
exit(1);
}
console::writeLn(__astr("\n\\b{Creating database and user}"));
console::writeLn(" The script can create the database and the user. Hit enter to skip this step.");
console::write(" Password for root user: ");
$pass = console::readPass();
if ($pass) {
$db['database'] = null;
$db['username'] = 'root';
$db['password'] = $pass;
config::set('lepton.db.default', $db);
$conn = new DatabaseConnection();
$dblist = $conn->getRows("SHOW DATABASES LIKE %s", $dbc['database']);
if (count($dblist) == 0) {
console::writeLn("Creating database...");
try {
$conn->exec(sprintf("CREATE DATABASE %s;", $dbc['database']));
} catch (Exception $e) {
console::writeLn("Not successful, does the database already exist?");
}
}
console::writeLn("Creating user...");
$conn->exec(sprintf("GRANT ALL ON %s.* TO %s@localhost IDENTIFIED BY '%s';", $dbc['database'], $dbc['username'], $dbc['password']));
$conn->exec("USE " . $dbc['database']);
} else {
console::writeLn("No password specified, ignoring database and user creation.");
$conn = new DatabaseConnection();
}
console::writeLn(__astr("\n\\b{Importing tables}"));
$f = glob(base::basePath() . '/dist/sql/*.sql');
foreach ($f as $fn) {
$fc = file_get_contents($fn);
console::writeLn(" [sys] %s", basename($fn));
$conn->exec($fc);
}
$f = glob(base::appPath() . '/sql/*.sql');
foreach ($f as $fn) {
$fc = file_get_contents($fn);
console::writeLn(" [app] %s", basename($fn));
$conn->exec($fc);
}
console::writeLn("All done.");
}