/**
  * @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
0
 /**
  * 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
0
파일: Db.php 프로젝트: uwitec/outbuying
 /**
  * 重新连接一次数据库
  * 如果 $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
0
 /**
  * @param Connection $dbh
  */
 public function __construct(Connection $conn)
 {
     $this->conn = $conn;
     $this->dblink = $conn->getResource();
     $dsn = $conn->getDSN();
     $this->dbname = $dsn['database'];
 }
예제 #5
0
파일: DatabaseInfo.php 프로젝트: saiber/www
 /**
  * @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
0
파일: Request.php 프로젝트: jamm/http
 /**
  * @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
0
 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
0
파일: Db.php 프로젝트: uwitec/outbuying
 /**
  * 重新连接一次数据库
  * 如果 $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.");
         }
     }
 }
 /**
  * @see Connection::getResource()
  */
 public function getResource()
 {
     return $this->childConnection->getResource();
 }
예제 #10
0
 function init(Connection $ssh)
 {
     echo "SFTP INIT\r\n";
     $this->ssh = $ssh;
     $this->sftp = ssh2_sftp($ssh->getResource());
 }
예제 #11
0
 /**
  * @see Connection::getResource()
  */
 public function getResource()
 {
     krumo('DBArrayConnection getResource ');
     die;
     return $this->childConnection->getResource();
 }