Exemple #1
0
function check_table_existence($conn_handle, $table_name)
{
    $sql_stmt = "SELECT class_name FROM db_class WHERE class_name = ?";
    $cubrid_req = cubrid_prepare($conn_handle, $sql_stmt);
    if (!$cubrid_req) {
        return -1;
    }
    $cubrid_retval = cubrid_bind($cubrid_req, 1, $table_name);
    if (!$cubrid_req) {
        cubrid_close_request($cubrid_req);
        return -1;
    }
    $cubrid_retval = cubrid_execute($cubrid_req);
    if (!$cubrid_retval) {
        cubrid_close_request($cubrid_req);
        return -1;
    }
    $row_num = cubrid_num_rows($cubrid_req);
    if ($row_num < 0) {
        cubrid_close_request($cubrid_req);
        return -1;
    }
    cubrid_close_request($cubrid_req);
    if ($row_num > 0) {
        return 1;
    } else {
        return 0;
    }
}
Exemple #2
0
    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)) {
        exit(1);
    }
}
?>
Exemple #3
0
 /**
  * Execute the query
  * this method is private
  * @param string $query
  * @param resource $connection
  * @return resource
  */
 function __query($query, $connection)
 {
     if ($this->use_prepared_statements == 'Y') {
         $req = @cubrid_prepare($connection, $query);
         if (!$req) {
             $this->_setError();
             return false;
         }
         $position = 0;
         if ($this->param) {
             foreach ($this->param as $param) {
                 $value = $param->getUnescapedValue();
                 $type = $param->getType();
                 if ($param->isColumnName()) {
                     continue;
                 }
                 switch ($type) {
                     case 'number':
                         $bind_type = 'numeric';
                         break;
                     case 'varchar':
                         $bind_type = 'string';
                         break;
                     default:
                         $bind_type = 'string';
                 }
                 if (is_array($value)) {
                     foreach ($value as $v) {
                         $bound = @cubrid_bind($req, ++$position, $v, $bind_type);
                         if (!$bound) {
                             $this->_setError();
                             return false;
                         }
                     }
                 } else {
                     $bound = @cubrid_bind($req, ++$position, $value, $bind_type);
                     if (!$bound) {
                         $this->_setError();
                         return false;
                     }
                 }
             }
         }
         $result = @cubrid_execute($req);
         if (!$result) {
             $this->_setError();
             return false;
         }
         return $req;
     }
     // Execute the query
     $result = @cubrid_execute($connection, $query);
     // error check
     if (!$result) {
         $this->_setError();
         return false;
     }
     // Return the result
     return $result;
 }
Exemple #4
0
 /**
  * @group php-822
  */
 public function testCubridPrepare2()
 {
     if (OUTPUT_FUNCTION_NAME == true) {
         echo "\r\nRunning: " . __FUNCTION__ . " = ";
     }
     $this->sql = "create table test1 (id int, name varchar(30))";
     cubrid_execute($this->con, $this->sql);
     $this->sql = "insert into test1 values(?, ?)";
     //$this->assertNotNull($this->req);
     // error parameter
     try {
         cubrid_prepare($this->con);
     } catch (Exception $e) {
         //echo cubrid_error_code();
         $this->assertTrue(TRUE);
         //echo $e->getMessage();
     }
     // error parameter
     try {
         cubrid_prepare($this->req, $this->sql);
     } catch (Exception $e) {
         //echo cubrid_error_code();
         $this->assertTrue(TRUE);
         //echo $e->getMessage();
     }
 }