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; } }
/** * 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; }
/** * @group php-822 */ public function testCubridPrepare0() { 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); $this->req = cubrid_prepare($this->con, $this->sql, CUBRID_INCLUDE_OID); $this->assertNotNull($this->req); cubrid_bind($this->req, 1, "1"); cubrid_bind($this->req, 2, "test"); cubrid_execute($this->req); $this->sql = "select * from test1"; $this->req1 = cubrid_execute($this->con, $this->sql); list($id, $name) = cubrid_fetch($this->req1); $this->assertEquals(1, $id); cubrid_bind($this->req, 1, "2"); cubrid_bind($this->req, 2, "test1"); cubrid_execute($this->req); $this->sql = "select * from test1 where id=2"; $this->req = cubrid_execute($this->con, $this->sql); list($id, $name) = cubrid_fetch($this->req); $this->assertEquals(2, $id); $this->sql = "select * from test1 where id=?"; //$this->assertNotNull($this->req); $this->req2 = cubrid_prepare($this->con, $this->sql, CUBRID_INCLUDE_OID); $this->assertNotNull($this->req2); cubrid_bind($this->req2, 1, "2"); cubrid_execute($this->req2); list($id, $name) = cubrid_fetch($this->req2); $this->assertEquals("test1", $name); }