本文整理汇总了PHP中object::exec方法的典型用法代码示例。如果您正苦于以下问题:PHP object::exec方法的具体用法?PHP object::exec怎么用?PHP object::exec使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类object
的用法示例。
在下文中一共展示了object::exec方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: PDO
/**
* intizializes the database class and tries to estabilish database connections
*
* @return NULL
*/
function __construct()
{
global $cfg_value;
// +++ main database connection
try {
$dsn = $cfg_value['server']['server_engine'] . ':host=' . $cfg_value['server']['server_host'] . ';port=' . $cfg_value['server']['server_port'] . ';dbname=' . $cfg_value['server']['server_db'];
$this->connection_server = new PDO($dsn, $cfg_value['server']['server_username'], $cfg_value['server']['server_password']);
$this->connection_server->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
// +++ set names to UTF-8
try {
$sql_names = "SET NAMES 'utf8';";
$query_names = $this->connection_server->exec($sql_names);
$sql_character_set = "SET CHARACTER SET utf8;";
$query_character_set = $this->connection_server->exec($sql_character_set);
} catch (PDOException $e) {
}
// --- set names to UTF-8
} catch (PDOException $e) {
$this->connection_server = NULL;
$this->error_server = $e->getMessage();
}
// --- main database connection
// register a shutdown function that closes the database connection
register_shutdown_function(array($this, 'disconnect'));
return;
}
示例2: PDO
/**
* intizializes the database class and tries to estabilish database connections
*
* @return NULL
*/
function __construct()
{
// +++ main database connection
try {
$dsn = CFG_DB_ENGINE . ':host=' . CFG_DB_HOST . ';port=' . CFG_DB_PORT . ';dbname=' . CFG_DB_DATABASE;
$this->connection = new PDO($dsn, CFG_DB_USERNAME, CFG_DB_PASSWORD);
$this->connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
// +++ set names to UTF-8
try {
$sql_names = "SET NAMES 'utf8';";
$query_names = $this->connection->exec($sql_names);
$sql_character_set = "SET CHARACTER SET utf8;";
$query_character_set = $this->connection->exec($sql_character_set);
} catch (PDOException $e) {
}
// --- set names to UTF-8
} catch (PDOException $e) {
$this->connection = NULL;
$this->error = $e->getMessage();
}
// --- main database connection
// register a shutdown function that closes the database connection
register_shutdown_function(array($this, 'disconnect'));
return;
}
示例3: execute
/**
* Execute the deploy command
*
* @param object $ssh The SSH connection handle
* @param string $project Name of the project
* @param string $host Host type of project (Git/Local)
* @param string $destination Location where project resides on the server
* @param string $path Path to the project on the repository
* @param string $commit Commit hash
* @param string $branch Name of the branch
*
* @return string $output Output from git command
*/
function execute($ssh = null, $project = null, $host = null, $destination = null, $path = null, $commit = null, $branch = null)
{
if (!empty($destination)) {
$output = "Performing deploy... \n";
// Check if path exists on server.
$dircheck = $ssh->exec("[ -d '" . $destination . "' ] && echo 'found'");
if (strpos($dircheck, 'found') === false) {
// Create project on server if not found
$command = "mkdir -p " . $destination . "; cd " . $destination . "; ";
if ($host == 'Github') {
$command .= "git clone git://github.com/" . Configure::read('Ballista.githubAccount') . "/" . $project . " ./";
} elseif (Configure::read('Ballista.gitoliteProtocol')) {
$command .= "git clone " . Configure::read('Ballista.gitoliteProtocol') . ":" . $project . " ./";
} else {
$command .= "git clone " . Configure::read('Ballista.accessProtocol') . $path . " ./";
}
// Perform the command
$output .= $ssh->exec($command);
if ($branch != Configure::read('Ballista.master')) {
// If branch is not master, then go into the project and checkout the branch from the repo
$output .= $ssh->exec("cd " . $destination . "; git checkout -b " . $branch . " origin/" . $branch);
}
} else {
// Path found, so project already exists. Just fetch and set to desired version.
$output .= $ssh->exec("cd " . $destination . "; git fetch; git reset --hard " . $commit);
}
return $output;
} else {
return "Error: Undefined path or action. Cannot execute.\n";
}
}
示例4: execute
public function execute($sql)
{
//参数分析
if (!$sql) {
return false;
}
$result = $this->db_link->exec($sql);
return $result;
}
示例5: exec
/**
* 执行SQL语句并返回影响的行数
* @param string $sql
* @return int
* @throws Exception
*/
public function exec($sql)
{
util_log::appLog()->info(__CLASS__ . '::' . __FUNCTION__ . "(): SQL: {$sql}");
$affectedRows = $this->db->exec($sql);
//数据库错误抛出异常就好,暂时不重连
if ($affectedRows === false) {
$errorInfo = $this->errorInfo();
$errorCode = $this->errorCode();
util_log::monitor()->error(array('MONITOR_KEY' => "database_failed", 'errorCode' => $errorCode, 'errorInfo' => $errorInfo, 'sql' => $sql));
throw new Exception($errorInfo, $errorCode);
}
return $affectedRows;
}
示例6: __construct
/**
* establishes a database connection using PDO
*/
private function __construct()
{
try {
// connect to the database
$this->db = new PDO('mysql:host=' . Config::get('db.host') . ';dbname=' . Config::get('db.name'), Config::get('db.user'), Config::get('db.pass'));
$this->db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
// create tables if they don't exist
$query = $this->db->exec("CREATE TABLE IF NOT EXISTS users(\n id INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT,\n username VARCHAR(25) NOT NULL,\n password VARCHAR(255) NOT NULL\n )");
$query = $this->db->exec("CREATE TABLE IF NOT EXISTS articles(\n id INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT,\n title VARCHAR(100) NOT NULL,\n body TEXT NOT NULL,\n created TIMESTAMP DEFAULT CURRENT_TIMESTAMP\n )");
} catch (PDOException $e) {
display_error($e->getMessage());
}
}
示例7: activate
/**
* Activates places to stay for course
*
* @param $key
*
* @return boolean
*/
function activate($key, $price)
{
$res = $this->db->query('SELECT id FROM kortkursus_x_indkvartering WHERE kursus_id = ' . $this->course->getId() . ' AND indkvartering_key = ' . $key);
if (PEAR::isError($res)) {
throw new Exception($res->getUserInfo());
}
if (!$res->fetchRow()) {
$this->db->exec('INSERT INTO kortkursus_x_indkvartering SET datetime = NOW(), kursus_id = ' . $this->course->getId() . ', indkvartering_key = ' . $key . ', price = "' . $price . '"');
} else {
$this->db->exec('UPDATE kortkursus_x_indkvartering SET datetime = NOW(), kursus_id = ' . $this->course->getId() . ', indkvartering_key = ' . $key . ', price = "' . $price . '"');
}
return true;
}
示例8: getConnection
/**
* @return object PDO
* Caso exista retorna a conexão com o banco, se não existir realiza a conexão antes de retorna-lá
*/
public static function getConnection()
{
if (is_null(self::$connection)) {
try {
$dsn = DB_DRIVER . ':host=' . DB_HOST . ';dbname=' . DB_NAME;
self::$connection = new \PDO($dsn, DB_USER, DB_PASS);
self::$connection->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
self::$connection->setAttribute(\PDO::ATTR_DEFAULT_FETCH_MODE, \PDO::FETCH_OBJ);
self::$connection->exec('set names utf8');
} catch (\PDOException $e) {
echo $e->getMessage();
}
}
return self::$connection;
}
示例9: checkOperation
/**
* Check If An action Is In Progress For The Selected Context
*
* @param String $context
* @return bool
* @access public
*/
public function checkOperation($context)
{
switch (@$context) {
case 'makeRepo':
if (!empty($this->repoPath)) {
if (intval(trim($this->sshConnection->exec('cd ' . $this->repoPath . "; ls -a | grep -c '.cachelock*'"))) != 0) {
// Operation In Progress : Game Repo Locked
return TRUE;
}
return FALSE;
}
break;
//------------------------------------------------------+
//------------------------------------------------------+
case 'installGame':
case 'updateGame':
if (!empty($this->gameServerPath)) {
if (trim($this->sshConnection->exec('test -f ' . $this->gameServerPath . ".cacheuid && echo 'true' || echo 'false'")) == 'true') {
return TRUE;
}
return FALSE;
}
break;
}
}
示例10: __call
/**
* Pass method to PDO object
*
* @param string $method PDO method name
* @param array $args PDO method arguments
* @return object PDO method results
*/
public function __call($method, $args)
{
if ('use' === strtolower($method)) {
if (!empty($args[0]) && is_string($args[0])) {
$this->conn->exec("USE `{$args[0]}`;");
return $this;
} else {
throw new \PDOException("Invalid Database name");
}
} elseif (!method_exists($this->conn, $method)) {
throw new \PDOException(sprintf("Call to undefined method '%s'", $method));
}
$len = count($args);
if (0 === $len) {
return $this->conn->{$method}();
} elseif (1 === $len) {
return $this->conn->{$method}($args[0]);
} elseif (2 === $len) {
return $this->conn->{$method}($args[0], $args[1]);
} elseif (3 === $len) {
return $this->conn->{$method}($args[0], $args[1], $args[2]);
} elseif (4 === $len) {
return $this->conn->{$method}($args[0], $args[1], $args[2], $args[3]);
} elseif (5 === $len) {
return $this->conn->{$method}($args[0], $args[1], $args[2], $args[3], $args[4]);
} else {
return call_user_func_array(array($this->conn, $method), $args);
}
}
示例11: gc
/**
* Garbage collector
*
* This function is responsible for garbage collection. It is responsible
* for deleting old counter logs.
*
* @access public
* @param int $lifetime Maximum lifetime of counter logs.
* @return void
* @throws HTTP_FloodControl_Exception if an error occured during garbage collection.
*/
public function gc($lifetime)
{
$quotedTblName = $this->_db->quoteIdentifier($this->_options['table']);
$query = sprintf("DELETE FROM %s WHERE access < %d", $quotedTblName, time() - $lifetime);
$result = $this->_db->exec($query);
if (PEAR::isError($result)) {
throw new HTTP_FloodControl_Exception($result->getMessage(), $result->getCode());
}
if ($this->_options['autooptimize']) {
switch ($this->_db->phptype) {
case 'mysql':
$query = sprintf("OPTIMIZE TABLE %s", $quotedTblName);
break;
case 'pgsql':
$query = sprintf("VACUUM %s", $quotedTblName);
break;
default:
$query = null;
break;
}
if (!is_null($query)) {
$result = $this->_db->exec($query);
if (PEAR::isError($result)) {
throw new HTTP_FloodControl_Exception($result->getMessage(), $result->getCode());
}
}
}
}
示例12: Execute
/**
* Wykonanie przygotowanego zapytania SQL. Nie są pobierane żadne dane.
* Zwracany ilość zmienionych rekordów.
*
* @param String $sql - zapytanie sql'owe
* @param Array $params (default: array()) - parametry zapytania
* @param bool $throwException
*
* @throws MK_Db_Exception
* @return integer
*/
protected function Execute($sql, array $params = array(), $throwException = true)
{
// Bez array_values wywala błąd - nie ma być kluczy w tablicy!
$params = array_values($params);
// Uruchomienie licznika uruchamiania zapytania SQL
$timeStart = MK_DEBUG_FIREPHP ? microtime(true) : 0;
// Jeżeli zostały podany parametry, to wykonujemy zapytanie przy pomocy prepare/execute
// W przeciwnym wypadku uruchiamy zapytanie poprzez exec(), które umożliwia wykonanie wielu zapytań SQL
if (count($params) > 0) {
$pdoObj = $this->db->prepare($sql);
if ($pdoObj->execute($params) === false && $throwException === true) {
throw new MK_Db_Exception(MK_Db_PDO_Singleton::MESSAGE_ERROR_RESULTS);
}
$affectedRows = $pdoObj->rowCount();
} else {
$results = $this->db->exec($sql);
if ($results === false && $throwException === true) {
throw new MK_Db_Exception(MK_Db_PDO_Singleton::MESSAGE_ERROR_RESULTS);
}
$affectedRows = $results;
}
// Zwrócenie szczegółowego komunikatu w konsoli FireBug-a
if (MK_DEBUG_FIREPHP) {
$this->fireBugSqlDump("DbExecute", $sql, $params, microtime(true) - $timeStart);
}
// Jeżeli jest włączone debugowanie, to SQL-e zapisywane są do pliku debug.log
$this->debugToFile($sql, $params);
// Ilość zmodyfikowanych wierszy
return $affectedRows;
}
示例13: init
/**
* Initialize the driver.
*
* Validate configuration and perform all resource-intensive tasks needed to
* make the driver active.
*
* @throws ILSException
* @return void
*/
public function init()
{
if (empty($this->config)) {
throw new ILSException('Configuration needs to be set.');
}
//Connect to MySQL
$this->db = new PDO('mysql:host=' . $this->config['Catalog']['host'] . ';port=' . $this->config['Catalog']['port'] . ';dbname=' . $this->config['Catalog']['database'], $this->config['Catalog']['username'], $this->config['Catalog']['password']);
// Throw PDOExceptions if something goes wrong
$this->db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
// Return result set like mysql_fetch_assoc()
$this->db->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
//character set utf8
$this->db->exec("SET NAMES utf8");
//Storing the base URL of ILS
$this->ilsBaseUrl = $this->config['Catalog']['url'];
//Boolean - use id prefixes like "KN31120" or not
$this->idPrefix = $this->config['Catalog']['id_prefix'];
//Boolean - indicates if library uses barcodes (true), or if barcodes are
// generated automatically (false)
$this->useBarcodes = $this->config['Catalog']['use_barcodes'];
//set number prefix for library
$this->prefix = $this->config['Catalog']['prefix'];
//how long (in days) hide new items
$this->hideNewItemsDays = 0;
if (isset($this->config['Catalog']['hide_days'])) {
$this->c = $this->config['Catalog']['hide_days'];
}
}
示例14: query
/**
* Prepare query to the database
*
* This function checks if we have already opened a connection to
* the database. If that's not the case, a new connection is opened.
* After that the query is passed to the database.
*
* @access public
* @param string Query string
* @return mixed a MDB_result object or MDB_OK on success, a MDB
* or PEAR error on failure
*/
function query($query)
{
$err = $this->_prepare();
if ($err !== true) {
return $err;
}
return $this->db->exec($query);
}
示例15: testExecStderrHandle
/**
* Tests the STDERR handle.
*
* @since 0.1
* @return void
*
* @depends testStderrSetHandle
*/
public function testExecStderrHandle()
{
$tmpfile = tmpfile();
$this->bunsen->stderrSetHandle($tmpfile);
$this->bunsen->exec('echo "hello world" >&2');
rewind($tmpfile);
$this->assertEquals(stream_get_contents($tmpfile), 'hello world' . "\n");
fclose($tmpfile);
}