Beispiel #1
0
 function connect($dbuser = '', $dbpassword = '', $dbname = '', $dbhost = 'localhost', $dbport = 33000)
 {
     global $ezSQL_cubrid_str;
     $return_val = false;
     // Keep track of how long the DB takes to connect
     $this->timer_start('db_connect_time');
     // Must have a user and a password
     if (!$dbuser || !$dbname) {
         $this->register_error($ezSQL_cubrid_str[1] . ' in ' . __FILE__ . ' on line ' . __LINE__);
         $this->show_errors ? trigger_error($ezSQL_cubrid_str[1], E_USER_WARNING) : null;
     } else {
         if (!($this->dbh = @cubrid_connect($dbhost, $dbport, $dbname, $dbuser, $dbpassword))) {
             $this->register_error($ezSQL_cubrid_str[2] . ' in ' . __FILE__ . ' on line ' . __LINE__);
             $this->show_errors ? trigger_error($ezSQL_cubrid_str[2], E_USER_WARNING) : null;
         } else {
             $this->dbuser = $dbuser;
             $this->dbpassword = $dbpassword;
             $this->dbhost = $dbhost;
             $this->dbname = $dbname;
             $this->dbport = $dbport;
             $return_val = true;
         }
     }
     return $return_val;
 }
Beispiel #2
0
 public function connect($config = array())
 {
     $this->config = $config;
     $this->connect = empty($this->config['user']) ? @cubrid_connect($this->config['host'], $this->config['port'], $this->config['database']) : @cubrid_connect($this->config['host'], $this->config['port'], $this->config['database'], $this->config['user'], $this->config['password']);
     if (empty($this->connect)) {
         die(getErrorMessage('Database', 'mysqlConnectError'));
     }
 }
 /**
  * @brief DB 접속
  **/
 function _connect()
 {
     // db 정보가 없으면 무시
     if (!$this->hostname || !$this->userid || !$this->password || !$this->database || !$this->port) {
         return;
     }
     // 접속시도
     $this->fd = @cubrid_connect($this->hostname, $this->port, $this->database, $this->userid, $this->password);
     // 접속체크
     if (!$this->fd) {
         $this->setError(-1, 'database connect fail');
         return $this->is_connected = false;
     }
     $this->is_connected = true;
 }
Beispiel #4
0
 public static function bind($database)
 {
     // Connects DB and set environment variables
     // $database array should contain 'server','username','password'.
     if (!isset($database) || empty($database)) {
         return false;
     }
     $handle = @cubrid_connect($database['server'], intval($database['port']), $database['database'], $database['username'], $database['password']);
     if (!$handle) {
         return false;
     }
     self::$dbProperties['handle'] = $handle;
     // Keeping handle
     self::$dbProperties['charset'] = 'utf8';
     return true;
 }
 function db_connect()
 {
     if ($this->port == '') {
         $this->port = self::DEFAULT_PORT;
     }
     $conn = cubrid_connect($this->hostname, $this->port, $this->database, $this->username, $this->password);
     if ($conn) {
         if (isset($this->auto_commit) && !$this->auto_commit) {
             cubrid_set_autocommit($conn, CUBRID_AUTOCOMMIT_FALSE);
         } else {
             cubrid_set_autocommit($conn, CUBRID_AUTOCOMMIT_TRUE);
             $this->auto_commit = TRUE;
         }
     }
     return $conn;
 }
 /**
  * Non-persistent database connection
  *
  * @access	private called by the base class
  * @return	resource
  */
 function db_connect()
 {
     // If no port is defined by the user, use the default value
     if ($this->port == '') {
         $this->port = self::DEFAULT_PORT;
     }
     $conn = cubrid_connect($this->hostname, $this->port, $this->database, $this->username, $this->password);
     if ($conn) {
         // Check if a user wants to run queries in dry, i.e. run the
         // queries but not commit them.
         if (isset($this->auto_commit) && !$this->auto_commit) {
             cubrid_set_autocommit($conn, CUBRID_AUTOCOMMIT_FALSE);
         } else {
             cubrid_set_autocommit($conn, CUBRID_AUTOCOMMIT_TRUE);
             $this->auto_commit = TRUE;
         }
     }
     return $conn;
 }
 public function connect($url, $username, $password)
 {
     $arrTmp = explode(':', $url, 8);
     $jdbc = isset($arrTmp[0]) ? $arrTmp[0] : 'jdbc';
     $cubrid = isset($arrTmp[1]) ? $arrTmp[1] : 'cubrid';
     $host = isset($arrTmp[2]) ? $arrTmp[2] : '127.0.0.1';
     $port = isset($arrTmp[3]) ? $arrTmp[3] : '33000';
     $dbName = isset($arrTmp[4]) ? $arrTmp[4] : 'demo';
     $userId = isset($arrTmp[5]) ? $arrTmp[5] : 'dba';
     $password = isset($arrTmp[6]) ? $arrTmp[6] : '';
     $property = isset($arrTmp[7]) ? $arrTmp[7] : '';
     if ($jdbc != 'jdbc' && $cubrid != 'cubrid') {
         throw new DataAccessException("데이터베이스 스키마가 드라이버와 일치하지 않습니다.");
     }
     $this->_host = $host;
     $this->_conn = @cubrid_connect($this->_host, $port, $dbName, $userId, $password);
     $this->_connected = $this->_conn ? true : false;
     return $this->_connected;
 }
function cubrid_mysql_connect($server, $username, $password, $database)
{
    // Note: In Cubrid, the database name is mandatory
    // initialize globals
    $GLOBALS['calculate_last_insert_id'] = true;
    $GLOBALS['cubrid_last_insert_id'] = 1;
    $GLOBALS['cubrid_default_port'] = 31111;
    // or use 33111
    $GLOBALS['cubrid_database'] = "";
    if (strpos($server, ":") > 1) {
        list($host, $port) = explode(":", $server, 2);
    } else {
        $host = $server;
        $port = $GLOBALS['cubrid_default_port'];
        // default port
    }
    // save database name
    $GLOBALS['cubrid_database'] = $database;
    return cubrid_connect($host, $port, $database, $username, $password);
}
Beispiel #9
0
 /**
  * DB Connect
  * this method is private
  * @param array $connection connection's value is db_hostname, db_port, db_database, db_userid, db_password
  * @return resource
  */
 function __connect($connection)
 {
     // attempts to connect
     $result = @cubrid_connect($connection["db_hostname"], $connection["db_port"], $connection["db_database"], $connection["db_userid"], $connection["db_password"]);
     // check connections
     if (!$result) {
         $this->setError(-1, 'database connect fail');
         return;
     }
     if (!defined('__CUBRID_VERSION__')) {
         $cubrid_version = cubrid_get_server_info($result);
         $cubrid_version_elem = explode('.', $cubrid_version);
         $cubrid_version = $cubrid_version_elem[0] . '.' . $cubrid_version_elem[1] . '.' . $cubrid_version_elem[2];
         define('__CUBRID_VERSION__', $cubrid_version);
     }
     if (__CUBRID_VERSION__ >= '8.4.0') {
         cubrid_set_autocommit($result, CUBRID_AUTOCOMMIT_TRUE);
     }
     return $result;
 }
Beispiel #10
0
 /**
  * DB Connect
  * this method is private
  * @param array $connection connection's value is db_hostname, db_port, db_database, db_userid, db_password
  * @return resource
  */
 function __connect($connection)
 {
     // attempts to connect
     $result = @cubrid_connect($connection['host'], $connection['port'], $connection['database'], $connection['user'], $connection['pass']);
     // check connections
     if (!$result) {
         $this->setError(-1, 'database connect fail');
         return;
     }
     if (!defined('__CUBRID_VERSION__')) {
         $cubrid_version = cubrid_get_server_info($result);
         $cubrid_version_elem = explode('.', $cubrid_version);
         $cubrid_version = $cubrid_version_elem[0] . '.' . $cubrid_version_elem[1] . '.' . $cubrid_version_elem[2];
         define('__CUBRID_VERSION__', $cubrid_version);
     }
     if (version_compare(__CUBRID_VERSION__, '9.0', '<')) {
         $this->setError(-1, 'Rhymix requires CUBRID 9.0 or later. Current CUBRID version is ' . __CUBRID_VERSION__);
         return;
     }
     cubrid_set_autocommit($result, CUBRID_AUTOCOMMIT_TRUE);
     return $result;
 }
Beispiel #11
0
$count = 0;
while (!feof($fh)) {
    $tmp = fgets($fh);
    if ($tmp === false) {
        break;
    }
    $buff = explode(",", trim($tmp));
    if (preg_match("/^[0-9]/", $buff[0]) > 0) {
        $buff[4] = preg_replace(array("/\\(/", "/\\)/"), array('', ''), $buff[4]);
        $addr_list[] = $buff;
    }
    $count++;
}
fclose($fh);
printf("%d records readed.\n", $count - 1);
$dh = cubrid_connect($db["host"], $db["port"], $db["dbname"], $db["username"], $db["password"]);
if ($dh === false) {
    sprintf("DB Error %d (%d): %s\n", cubrid_error_code(), cubrid_error_code_facility(), cubrid_error_msg());
    exit(0);
}
$result = cubrid_execute($dh, "SELECT count (\"class_name\") AS \"cnt\" " . "FROM \"db_class\" WHERE " . "\"class_name\" = '" . $db["table"] . "';");
if ($result === false) {
    printf("DB Error %d (%d): %s\n", cubrid_error_code(), cubrid_error_code_facility(), cubrid_error_msg());
    cubrid_rollback($dh);
    cubrid_disconnect($dh);
    exit(0);
}
cubrid_commit($dh);
$is_exist = cubrid_fetch($result, CUBRID_NUM);
if ($is_exist === false) {
    printf("DB Error %d (%d): %s\n", cubrid_error_code(), cubrid_error_code_facility(), cubrid_error_msg());
 /**
  *  Attempts to connect to the database given the existing $_POST vars.
  *
  * @return boolean
  */
 public function test_db_connection()
 {
     if (!$this->db_available()) {
         return false;
     }
     $db_name = $this->ci->input->post('database');
     $driver = $this->ci->input->post('driver');
     $hostname = $this->ci->input->post('hostname');
     $password = $this->ci->input->post('password');
     $port = $this->ci->input->post('port');
     $username = $this->ci->input->post('username');
     switch ($driver) {
         case 'mysql':
             return @mysql_connect("{$hostname}:{$port}", $username, $password);
         case 'bfmysqli':
         case 'mysqli':
             $mysqli = new mysqli($hostname, $username, $password, '', $port);
             if (!$mysqli->connect_error) {
                 return true;
             }
             return false;
         case 'cubrid':
             return @cubrid_connect($hostname, $port, $db_name, $username, $password);
         case 'mongodb':
             // deprecated
             $connect_string = $this->get_mongo_connection_string($hostname, $port, $username, $password, $db_name);
             try {
                 $mongo = new Mongo($connect_string);
                 return true;
             } catch (MongoConnectionException $e) {
                 show_error('Unable to connect to MongoDB.', 500);
             }
             return false;
             break;
         case 'mongoclient':
             // no driver support at this time
             $connect_string = $this->get_mongo_connection_string($hostname, $port, $username, $password, $db_name);
             try {
                 $mongo = new MongoClient($connect_string);
                 return true;
             } catch (MongoConnectionException $e) {
                 show_error('Unable to connect MongoClient.', 500);
             }
             return false;
             break;
         case 'mssql':
             return @mssql_connect("{$hostname},{$port}", $username, $password);
         case 'oci8':
             $connect_string = $this->get_oracle_connection_string($hostname, $port);
             return @oci_connect($username, $password, $connect_string);
         case 'odbc':
             $connect_string = $this->get_odbc_connection_string($hostname);
             return @odbc_connect($connect_string, $username, $password);
         case 'pdo':
             $connect_string = $this->get_pdo_connection_string($hostname, $db_name);
             try {
                 $pdo = new PDO($connect_string, $username, $password);
                 return true;
             } catch (PDOException $e) {
                 show_error('Unable to connect using PDO.', 500);
             }
             return false;
             break;
         case 'postgre':
             $connect_string = $this->get_postgre_connection_string($hostname, $port, $username, $password, $db_name);
             return @pg_connect($connect_string);
         case 'sqlite':
             if (!($sqlite = @sqlite_open($db_name, FILE_WRITE_MODE, $error))) {
                 show_error($error, 500);
                 return false;
             }
             return $sqlite;
         case 'sqlsrv':
             $connection = $this->get_sqlsrv_connection($username, $password, $db_name);
             return sqlsrv_connect($hostname, $connection);
         default:
             return false;
     }
 }
Beispiel #13
0
function sql_connect_db($server, $username, $password, $database = null, $new_link = false)
{
    if ($new_link !== true) {
        $new_link = false;
    }
    if ($database === null) {
        return true;
    }
    if ($database !== null) {
        $myport = "30000";
        $hostex = explode(":", $server);
        if (isset($hostex[1]) && !is_numeric($hostex[1])) {
            $hostex[1] = $myport;
        }
        if (isset($hostex[1])) {
            $server = $hostex[0];
            $myport = $hostex[1];
        }
        $link = cubrid_connect($server, $myport, $database, $username, $password);
        cubrid_set_autocommit($link, CUBRID_AUTOCOMMIT_TRUE);
    }
    if ($link === false) {
        output_error("Not connected: " . $sqliteerror, E_USER_ERROR);
        return false;
    }
    return $link;
}
Beispiel #14
0
<?php

require_once 'connectLarge.inc';
require_once 'until.php';
if (!($conn = cubrid_connect($host, $port, $db, $user, $passwd))) {
    printf("Cannot connect to db server using host=%s, port=%d, dbname=%s, user=%s, passwd=***\n", $host, $port, $db, $user);
    exit(1);
}
$retval = check_table_existence($conn, "largetable");
if ($retval == -1) {
    exit(1);
} elseif ($retval == 1) {
    printf("this table is created\n");
} else {
    printf("#####start: create largetable#####\n");
    $cubrid_req = cubrid_execute($conn, "CREATE TABLE largetable(a int AUTO_INCREMENT, b clob)");
    if (!$cubrid_req) {
        printf("Failed to create test table: [%d] %s\n", cubrid_error_code(), cubrid_error_msg());
        exit(1);
    }
    $req = cubrid_prepare($conn, "insert into largetable(b) values (?)");
    $importName = array("largeFile/large.txt");
    for ($i = 0; $i < count($importName); $i++) {
        $lob = cubrid_lob2_new($conn, "CLOB");
        cubrid_lob2_import($lob, $importName[$i]);
        cubrid_lob2_bind($req, 1, $lob, "CLOB");
        cubrid_execute($req);
        cubrid_lob2_close($lob);
    }
    cubrid_close_prepare($req);
    if (!cubrid_commit($conn)) {
Beispiel #15
0
#!/usr/bin/php

<?php 
$sql = "insert into foo1 values(1,1)";
for ($i = 0; $i < 1; $i++) {
    $con = @cubrid_connect("test-db-server", 33113, "testdb", "dba", "");
    if ($con) {
        $req = cubrid_query($sql, $con);
        if ($req) {
            echo "cubrid_query error";
        }
        while ($row = cubrid_fetch($req)) {
            echo "to: \$ row [0], b: \$ row [1] \\ n";
        }
        if ($req) {
            cubrid_close_request($req);
        }
        cubrid_disconnect($con);
    } else {
        echo "failed cubrid_connect . \\ n ";
        sleep(1);
    }
}
Beispiel #16
0
 /**
  * @group lock
  */
 public function testCubridLockRead0()
 {
     if (OUTPUT_FUNCTION_NAME == true) {
         echo "\r\nRunning: " . __FUNCTION__ . " = ";
     }
     //    $this->markTestIncomplete(
     //            'This test has not been implemented yet.'
     //            );
     // change configure file
     if (OS == 'LINUX') {
         system("sh modconf.sh " . CubridTest::DBNAME . "> /dev/null &");
     } else {
         system("modconf.cmd " . CubridTest::DBNAME);
     }
     sleep(20);
     //cubrid_disconnect($this->con);
     //cubrid_close_request($this->req);
     $this->con = cubrid_connect(CubridTest::HOST, CubridTest::PORT, CubridTest::DBNAME, CubridTest::USERID, CubridTest::PASSWORD);
     $this->sql = "create table test1 (id int primary key, name varchar(300))";
     cubrid_execute($this->con, $this->sql);
     for ($i = 0; $i < 10; $i++) {
         $this->sql = "insert into test1 values({$i}, 'testalsjdflakasdfkljaklsjdfklasjkldfja;klsjdlfkjasdfs')";
         $this->req = cubrid_execute($this->con, $this->sql);
         //    $this->sql = "insert into test1 values(4, 'cj')";
         //    $this->req = cubrid_execute($this->con, $this->sql);
         cubrid_commit($this->con);
     }
     $this->sql = "select * from test1 where id=3";
     //      $this->req = cubrid_execute($this->con, $this->sql);
     $this->req = cubrid_execute($this->con, $this->sql, CUBRID_INCLUDE_OID);
     cubrid_fetch($this->req);
     $oid = cubrid_current_oid($this->req);
     cubrid_commit($this->con);
     $res = cubrid_lock_read($this->con, $oid);
     //    sleep(100);
     $this->assertTrue($res);
     system("cubrid lockdb " . CubridTest::DBNAME . "  | grep -w -A4 test1 | grep -w S_LOCK> lock.log");
     $fp = fopen("lock.log", "r");
     $content = fread($fp, 100);
     $this->assertContains("S_LOCK", $content);
     fclose($fp);
     system("rm -f lock.log");
     $this->sql = "drop test1";
     $this->req = cubrid_execute($this->con, $this->sql, CUBRID_INCLUDE_OID);
     cubrid_commit($this->con);
     $this->con = null;
     $this->req = null;
     // recover
     if (OS == 'LINUX') {
         system("sh recov.sh " . CubridTest::DBNAME . " > /dev/null &");
     } else {
         system("recov.cmd " . CubridTest::DBNAME);
     }
     sleep(20);
 }
Beispiel #17
0
<?php

include "connect.inc";
header('Content-type: text/html; charset=euc-kr');
$conn = cubrid_connect($host, $port, $db, "dba", $passwd);
$sql = "insert into cubridsus9278(b) values('aaaa')";
$i = 0;
while ($i < 300) {
    $result = cubrid_execute($conn, $sql);
    if ($result == true) {
        cubrid_commit($conn);
    } else {
        cubrid_rollback($conn);
    }
    $i++;
}