示例#1
0
 /**
  * Test handle query result with exception
  */
 public function testPostgresRaiseException()
 {
     $this->setExpectedException(RaiseException::class);
     $function = '
         CREATE OR REPLACE FUNCTION raise_exception()
         RETURNS VOID AS $$
         BEGIN
             RAISE EXCEPTION \'exception message;\';
         END;
         $$ LANGUAGE plpgsql;
     ';
     $Connection = new Connection();
     $Connection->setHost('postgres');
     $Connection->setUserName('postgres');
     $Connection->query($function);
     $Connection->query('SELECT raise_exception();');
 }
示例#2
0
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * Postgresql query example
 * @author alxmsl
 */
// Firstly include base class
include '../vendor/autoload.php';
use alxmsl\Connection\Postgresql\Connection;
// Create connection
$Connection = new Connection();
$Connection->setUserName('postgres')->setPassword('postgres')->setDatabase('postgres')->setHost('localhost')->setPort(5432);
// Connect and ...
$Connection->connect();
// ..query needed data
$Result = $Connection->query('select * from "pg_class"', null);
$Data = $Result->getResult();
var_dump($Data[0]);
// ..query data with parameters
$Result = $Connection->query('select count(*) from {{ tbl(table) }}', array('table' => 'pg_class'));
$Data = $Result->getResult();
var_dump($Data);
示例#3
0
/**
 * This program is free software. It comes without any warranty, to
 * the extent permitted by applicable law. You can redistribute it
 * and/or modify it under the terms of the Do What The F**k You Want
 * To Public License, Version 2, as published by Sam Hocevar. See
 * http://www.wtfpl.net/ for more details.
 *
 * Postgres set test
 * @author alxmsl
 * @date 4/6/13
 */
include '../source/Autoloader.php';
include '../vendor/alxmsl/connection/source/Autoloader.php';
use alxmsl\Connection\Postgresql\Connection;
use alxmsl\Primitives\SetFactory;
// Create new postgres connection
$Connection = new Connection();
$Connection->setNeedBusyCheckup(false)->setUserName('postgres')->setPassword('postgres')->setDatabase('postgres')->setHost('localhost')->setPort(5432);
// Create set instance
$Set = SetFactory::createPostgresSet('test', $Connection);
// Add items to set
$Set->add('obj_01');
$Set->add('obj_02');
// Check items existence
var_dump($Set->exists('obj_01'), $Set->exists('obj_03'));
$v = $Set->getProvider()->get(5);
var_dump($v);
foreach ($Set->getIterator() as $item) {
    var_dump($item);
}