本文整理汇总了PHP中Connection::exec方法的典型用法代码示例。如果您正苦于以下问题:PHP Connection::exec方法的具体用法?PHP Connection::exec怎么用?PHP Connection::exec使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Connection
的用法示例。
在下文中一共展示了Connection::exec方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testExec
public function testExec()
{
$that = $this;
$this->connectAndAuth();
$this->object->exec('uname -a', function ($stdio) use($that) {
$that->assertInternalType('string', $stdio);
});
}
示例2: execute
/**
* @param null $sql
*
* @return mixed
* @throws SqlException
*/
public function execute($sql = null)
{
if (null == $sql) {
$sql = $this->prepare();
}
$result = $this->_connection->exec($sql);
if (false === $result) {
throw new SqlException($this->_connection->getErrorMessage());
}
return $result;
}
示例3: __construct
/**
* Driver options:
* - charset => character encoding to set (default is utf8)
* - sqlmode => see http://dev.mysql.com/doc/refman/5.0/en/server-sql-mode.html
*/
public function __construct(Connection $connection, array $options)
{
$this->connection = $connection;
$charset = isset($options['charset']) ? $options['charset'] : 'utf8';
if ($charset) {
$connection->exec("SET NAMES '{$charset}'");
}
if (isset($options['sqlmode'])) {
$connection->exec("SET sql_mode='{$options['sqlmode']}'");
}
$connection->exec("SET time_zone='" . date('P') . "'");
}
示例4: connect
/**
* 链接数据库
* @param $config
* @return Connection
*/
public static function connect($config)
{
$dsn = $config['driver'] . ':host=' . $config['host'] . ';port=' . $config['port'];
$user = $config['user'];
$pass = $config['pass'];
$connection_options = array(\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION);
$pdo = new Connection($dsn, $user, $pass, $connection_options);
if (!empty($config['collation'])) {
$pdo->exec('SET NAMES ' . $config['charset'] . ' COLLATE ' . $config['collation']);
} else {
$pdo->exec('SET NAMES ' . $config['charset']);
}
return $pdo;
}
示例5: loadFromFile
/**
* Import SQL dump from file - extreme fast.
* @return int count of commands
*/
public static function loadFromFile(Connection $connection, $file)
{
@set_time_limit(0);
// intentionally @
$handle = @fopen($file, 'r');
// intentionally @
if (!$handle) {
throw new FileNotFoundException("Cannot open file '{$file}'.");
}
$count = 0;
$sql = '';
while (!feof($handle)) {
$s = fgets($handle);
$sql .= $s;
if (substr(rtrim($s), -1) === ';') {
$connection->exec($sql);
// native query without logging
$sql = '';
$count++;
}
}
if (trim($sql) !== '') {
$connection->exec($sql);
$count++;
}
fclose($handle);
return $count;
}