예제 #1
0
 public function __construct($hostname, $port, $username, $password, $dbname, $minpool, $maxpool)
 {
     SqlDriverManager::install("mysql");
     $this->pooling = SqlDriverManager::getPool('mysql://' . $hostname . ':' . $port . '/' . $dbname, 'mysql', array('username' => $username, 'password' => $password));
     //$this->pooling->setMaxPoolSize($maxpool);
     $this->pooling->setMaxPoolSize(1);
     $this->pool = $this->pooling->getConnection();
     $this->pool->query('USE bloon;')->update();
 }
예제 #2
0
--TEST--
SqlDriverManager test install invalid #2
--FILE--
<?php 
use php\sql\SqlDriverManager;
use php\sql\SqlException;
try {
    SqlDriverManager::install('foobar');
} catch (SqlException $e) {
    echo $e->getMessage();
}
?>
--EXPECT--
java.sql.SQLException: Driver class 'foobar' is not found in classpath
예제 #3
0
--TEST--
Test create table #1
--FILE--
<?php 
use php\sql\SqlDriverManager;
$pool = SqlDriverManager::getPool(':sqlite::memory:', 'sqlite');
$conn = $pool->getConnection();
$statement = $conn->query('create table person (id integer, name string)');
var_dump($statement->update());
$result = $conn->query('select COUNT(*) from person')->fetch();
var_dump($result->toArray());
?>
--EXPECTF--
int(0)
array(1) {
  ["COUNT(*)"]=>
  int(0)
}
예제 #4
0
--TEST--
SqlDriverManager test insert into table #2
--FILE--
<?php 
use php\sql\SqlDriverManager;
use php\sql\SqlResult;
use php\util\Flow;
SqlDriverManager::install('sqlite');
$conn = SqlDriverManager::getConnection('sqlite::memory:');
$conn->query('create table person (id integer, name string)')->update();
$result = $conn->query("insert into person values(?, ?)", [1, 'leo'])->update();
$result += $conn->query("insert into person values(?, ?)", [2, 'yui'])->update();
var_dump($result);
$array = Flow::of($conn->query('select * from person'))->map(function (SqlResult $result) {
    return $result->toArray();
})->toArray();
var_dump($array);
?>
--EXPECTF--
int(2)
array(2) {
  [0]=>
  array(2) {
    ["id"]=>
    int(1)
    ["name"]=>
    string(3) "leo"
  }
  [1]=>
  array(2) {
    ["id"]=>
예제 #5
0
--TEST--
SqlDriverManager test metadata #2
--FILE--
<?php 
use php\sql\SqlDriverManager;
SqlDriverManager::install('sqlite');
$conn = SqlDriverManager::getConnection('sqlite::memory:', ['username' => 'admin', 'password' => 'admin']);
var_dump($conn->getCatalogs());
var_dump($conn->getSchemas());
var_dump($conn->getMetaData());
?>
--EXPECT--
array(0) {
}
array(0) {
}
array(34) {
  ["userName"]=>
  string(0) ""
  ["driverName"]=>
  string(10) "SQLiteJDBC"
  ["driverVersion"]=>
  string(6) "native"
  ["databaseName"]=>
  string(6) "SQLite"
  ["databaseVersion"]=>
  string(5) "3.8.7"
  ["catalogSeparator"]=>
  string(1) "."
  ["catalogTerm"]=>
  string(7) "catalog"