本文整理汇总了PHP中Connection::getResource方法的典型用法代码示例。如果您正苦于以下问题:PHP Connection::getResource方法的具体用法?PHP Connection::getResource怎么用?PHP Connection::getResource使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Connection
的用法示例。
在下文中一共展示了Connection::getResource方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1:
/**
* @param string $table The table name.
* @param string $database The database name.
* @param resource $dblink The db connection resource.
*/
function __construct(DatabaseInfo $database, $name)
{
$this->database = $database;
$this->name = $name;
$this->conn = $database->getConnection();
// shortcut because all drivers need this for the queries
$this->dblink = $this->conn->getResource();
$this->dbname = $database->getName();
}
示例2: execute
/**
* Executes a prepared query
*
* @param array $params Input params for query.
* @param array $resultTypes Types information, used to convert output values (overrides auto-generated types).
* @return ResultSet|int|bool Execution result.
* @throws exceptions\TypeConversionException
* @throws exceptions\InvalidQueryException
*/
public function execute(array $params = array(), array $resultTypes = array())
{
if (!empty($params)) {
$this->_values = array();
foreach (array_values($params) as $i => $value) {
$this->bindValue($i + 1, $value);
}
}
$params = array();
foreach ($this->_values as $key => $value) {
if (isset($this->_converters[$key])) {
$params[$key] = $this->_converters[$key]->output($value);
} else {
$params[$key] = $this->_connection->guessOutputFormat($value);
}
}
$result = @pg_execute($this->_connection->getResource(), $this->_queryId, $params);
if (!$result) {
throw new exceptions\InvalidQueryException(pg_last_error($this->_connection->getResource()));
}
switch (pg_result_status($result)) {
case PGSQL_COPY_IN:
case PGSQL_COPY_OUT:
pg_free_result($result);
return true;
case PGSQL_COMMAND_OK:
$count = pg_affected_rows($result);
pg_free_result($result);
return $count;
case PGSQL_TUPLES_OK:
default:
return new ResultSet($result, $this->_connection->getTypeConverterFactory(), $resultTypes);
}
}
示例3: reconnect
/**
* 重新连接一次数据库
* 如果 $con_name 相同则不连接
*
* @param string|array $con_name
* @param string $forceReconnect
*/
public function reconnect($con_name, $forceReconnect = false)
{
if (is_array($con_name)) {
$cfg = $con_name;
} else {
$cfg = null;
}
if ($forceReconnect || $con_name != $this->getConnName()) {
if ($this->_debug) {
Watt_Debug::addInfoToDefault("Watt", "Before connect use Watt_Db.");
}
if (class_exists('Propel')) {
$this->_connection = Propel::getConnection($con_name);
$this->_conn = $this->_connection->getResource();
$this->_dsn = $this->_connection->getDSN();
} else {
if (!is_array($cfg)) {
$configuration = (include Watt_Config::getConfigPath() . "propel.conf.php");
$cfg = $configuration['datasources'][$con_name]['connection'];
}
$this->_conn = mysql_connect($cfg["hostspec"] . ($cfg["port"] ? ":" . $cfg["port"] : ""), $cfg["username"], $cfg["password"]);
$this->_dsn = $cfg;
mysql_select_db($cfg["database"], $this->_conn);
$charset = @$cfg["charset"] ? $cfg["charset"] : 'utf8';
mysql_query("set names '{$charset}'");
}
$this->setConnName($con_name);
if ($this->_debug) {
Watt_Debug::addInfoToDefault("Watt", "After connect [{$con_name}] use Watt_Db.");
}
}
}
示例4: __construct
/**
* @param Connection $dbh
*/
public function __construct(Connection $conn)
{
$this->conn = $conn;
$this->dblink = $conn->getResource();
$dsn = $conn->getDSN();
$this->dbname = $dsn['database'];
}
示例5: __construct
/**
* @param Connection $dbh
*/
public function __construct(Connection $conn, $vendorInfo = array())
{
$this->conn = $conn;
$this->dblink = $conn->getResource();
$dsn = $conn->getDSN();
$this->dbname = $dsn['database'];
$this->vendorSpecificInfo = $vendorInfo;
}
示例6: ReadResponse
/**
* @param IResponse $Response
* @return IResponse
*/
protected function ReadResponse(IResponse $Response)
{
//read headers
$status_header = '';
$headers = array();
$start_time = time();
$connection = $this->Connection->getResource();
if (empty($connection)) {
return false;
}
while (!$this->feof($connection)) {
if ($this->response_timeout > 0 && time() - $start_time > $this->response_timeout) {
$this->Connection->close();
return false;
}
$header = trim($this->fgets($connection));
if (!empty($header)) {
if (empty($status_header)) {
$status_header = $header;
continue;
}
if (strpos($header, ':') !== false) {
$header = explode(':', $header, 2);
$headers[trim($header[0])] = trim($header[1]);
} else {
$headers[] = $header;
}
} else {
break;
}
}
$Response->setHeaders($headers);
if (!empty($status_header)) {
$status_header = explode(' ', $status_header, 3);
$Response->setStatusCode(intval(trim($status_header[1])));
if (isset($status_header[2])) {
$Response->setStatusReason(trim($status_header[2]));
}
}
if (strtolower($Response->getHeader('Connection')) != 'keep-alive' && $this->Connection->isKeepAlive()) {
$this->Connection->setType($Response->getHeader('Connection'));
}
$body = $this->getResponseBody($Response, $connection);
if ($body === false) {
$this->Connection->close();
}
if (!empty($body)) {
$Serializer = $Response->getSerializer();
if (!empty($Serializer)) {
$body = $Serializer->unserialize($body);
}
$Response->setBody($body);
}
return $Response;
}
示例7: testConstructorWithOptions
public function testConstructorWithOptions()
{
$adapterConnection = $this->prophesize(AbstractConnection::class);
$options = $this->prophesize(ConnectionOptions::class);
$connectionFactoryFactory = $this->prophesize(Factory\ConnectionFactoryFactory::class);
$connectionFactory = $this->prophesize(Factory\ConnectionFactoryInterface::class);
$connectionFactory->createConnection($options->reveal())->willReturn($adapterConnection->reveal());
$connectionFactoryFactory->createFactory('foo')->willReturn($connectionFactory->reveal());
$options->getType()->shouldBeCalled()->willReturn('foo');
$options->getConnectionFactoryFactory()->willReturn($connectionFactoryFactory->reveal());
$connection = new Connection($options->reveal());
$resource = $connection->getResource();
static::assertInstanceOf(AbstractConnection::class, $resource);
static::assertSame($adapterConnection->reveal(), $resource);
}
示例8: reconnect_old
/**
* 重新连接一次数据库
* 如果 $con_name 相同则不连接
*
* @param string $con_name
* @param string $forceReconnect
*/
public function reconnect_old($con_name, $forceReconnect = false)
{
if ($forceReconnect || $con_name != $this->getConnName()) {
if ($this->_debug) {
Pft_Debug::addInfoToDefault("Pft", "Before connect use Pft_Db.");
}
$this->_connection = Propel::getConnection($con_name);
$this->_conn = $this->_connection->getResource();
$this->_dsn = $this->_connection->getDSN();
/*
$configuration = include( Pft_Config::getConfigPath()."propel.conf.php" );
$cfg = $configuration['datasources'][$con_name]['connection'];
$this->_conn = mysql_connect($cfg["hostspec"].($cfg["port"]?":".$cfg["port"]:""), $cfg["username"], $cfg["password"]);
mysql_select_db( $cfg["database"], $this->_conn );
*/
$this->setConnName($con_name);
if ($this->_debug) {
Pft_Debug::addInfoToDefault("Pft", "After connect [{$con_name}] use Pft_Db.");
}
}
}
示例9: getResource
/**
* @see Connection::getResource()
*/
public function getResource()
{
return $this->childConnection->getResource();
}
示例10: init
function init(Connection $ssh)
{
echo "SFTP INIT\r\n";
$this->ssh = $ssh;
$this->sftp = ssh2_sftp($ssh->getResource());
}
示例11: getResource
/**
* @see Connection::getResource()
*/
public function getResource()
{
krumo('DBArrayConnection getResource ');
die;
return $this->childConnection->getResource();
}