function bmark_query($sql, $dbh) { $result_set = null; if (is_a($dbh, "DrizzleCon")) { $sql = str_replace("ENGINE=InnoDB DEFAULT CHARSET=utf8", "", $sql); $result = @drizzle_query($dbh, $sql) or die('ERROR: ' . drizzle_con_error($dbh) . "\n"); // buffer result set drizzle_result_buffer($result) or die('ERROR: ' . drizzle_con_error($dbh) . "\n"); if (drizzle_result_row_count($result)) { while ($row = drizzle_row_next($result)) { $result_set[] = $row; } } // free result set drizzle_result_free($result); // close connection // drizzle_con_close($dbh); return $result_set; } if (bmark_type($dbh) === 'mysql') { $result = mysql_query($sql, $dbh) or die('ERROR: ' . mysql_error($dbh)); if (preg_match("/select.*/i", $sql)) { if (mysql_num_rows($result) > 0) { while ($row = mysql_fetch_assoc($result)) { $result_set[] = $row; } } } return $result_set; } return FALSE; }
/** * This function frees the command reference. * * @access public * @override */ public function free() { if ($this->command !== NULL) { @drizzle_result_free($this->command); $this->command = NULL; $this->record = FALSE; } }
/** * Test database connection * * @param string $extension 'drizzle', 'mysql' or 'mysqli' * @param string $connect_type 'tcp' or 'socket' * @param string $host * @param string $port * @param string $socket * @param string $user * @param string $pass * @param string $error_key * * @return bool|array */ function test_db_connection($extension, $connect_type, $host, $port, $socket, $user, $pass = null, $error_key = 'Server') { // test_php_errormsg(); $socket = empty($socket) || $connect_type == 'tcp' ? null : $socket; $port = empty($port) || $connect_type == 'socket' ? null : ':' . $port; $error = null; if ($extension == 'drizzle') { while (1) { $drizzle = @drizzle_create(); if (!$drizzle) { $error = __('Could not initialize Drizzle connection library'); break; } $conn = $socket ? @drizzle_con_add_uds($socket, $user, $pass, null, 0) : @drizzle_con_add_tcp($drizzle, $host, $port, $user, $pass, null, 0); if (!$conn) { $error = __('Could not connect to Drizzle server'); drizzle_free($drizzle); break; } // connection object is set up but we have to send some query // to actually connect $res = @drizzle_query($conn, 'SELECT 1'); if (!$res) { $error = __('Could not connect to Drizzle server'); } else { drizzle_result_free($res); } drizzle_con_free($conn); drizzle_free($drizzle); break; } } else { if ($extension == 'mysql') { $conn = @mysql_connect($host . $socket . $port, $user, $pass); if (!$conn) { $error = __('Could not connect to MySQL server'); } else { mysql_close($conn); } } else { $conn = @mysqli_connect($host, $user, $pass, null, $port, $socket); if (!$conn) { $error = __('Could not connect to MySQL server'); } else { mysqli_close($conn); } } } // test_php_errormsg(false); if (isset($php_errormsg)) { $error .= " - {$php_errormsg}"; } return is_null($error) ? true : array($error_key => $error); }
/** * Frees resources taken by this result * * @return void */ public function free() { unset($this->_columns); unset($this->_columnNames); drizzle_result_free($this->_dresult); unset($this->_dresult); }
/** * Test database connection * * @param string $connect_type 'tcp' or 'socket' * @param string $host host name * @param string $port tcp port to use * @param string $socket socket to use * @param string $user username to use * @param string $pass password to use * @param string $error_key key to use in return array * * @return bool|array */ public static function testDBConnection($connect_type, $host, $port, $socket, $user, $pass = null, $error_key = 'Server') { // static::testPHPErrorMsg(); $error = null; if (PMA_DatabaseInterface::checkDbExtension('mysqli')) { $socket = empty($socket) || $connect_type == 'tcp' ? null : $socket; $port = empty($port) || $connect_type == 'socket' ? null : $port; $extension = 'mysqli'; } else { $socket = empty($socket) || $connect_type == 'tcp' ? null : ':' . ($socket[0] == '/' ? '' : '/') . $socket; $port = empty($port) || $connect_type == 'socket' ? null : ':' . $port; $extension = 'mysql'; } // dead code (drizzle extension) if ($extension == 'drizzle') { while (1) { $drizzle = @drizzle_create(); if (!$drizzle) { $error = __('Could not initialize Drizzle connection library!'); break; } $conn = $socket ? @drizzle_con_add_uds($socket, $user, $pass, null, 0) : @drizzle_con_add_tcp($drizzle, $host, $port, $user, $pass, null, 0); if (!$conn) { $error = __('Could not connect to the database server!'); drizzle_free($drizzle); break; } // connection object is set up but we have to send some query // to actually connect $res = @drizzle_query($conn, 'SELECT 1'); if (!$res) { $error = __('Could not connect to the database server!'); } else { drizzle_result_free($res); } drizzle_con_free($conn); drizzle_free($drizzle); break; } } else { if ($extension == 'mysql') { $conn = @mysql_connect($host . $port . $socket, $user, $pass); if (!$conn) { $error = __('Could not connect to the database server!'); } else { mysql_close($conn); } } else { $conn = @mysqli_connect($host, $user, $pass, null, $port, $socket); if (!$conn) { $error = __('Could not connect to the database server!'); } else { mysqli_close($conn); } } } // static::testPHPErrorMsg(false); if (isset($php_errormsg)) { $error .= " - {$php_errormsg}"; } return is_null($error) ? true : array($error_key => $error); }
/** * Frees resources taken by this result */ public function free() { _dlog(); unset($this->columns); unset($this->columnNames); drizzle_result_free($this->dresult); unset($this->dresult); }
/** * This function processes an SQL statement that will NOT return data. * * @access public * @override * @param string $sql the SQL statement * @throws Throwable_SQL_Exception indicates that the executed * statement failed */ public function execute($sql) { if (!$this->is_connected()) { throw new Throwable_SQL_Exception('Message: Failed to execute SQL statement. Reason: Unable to find connection.'); } $command = @drizzle_query($this->resource, $sql); if ($command === FALSE) { throw new Throwable_SQL_Exception('Message: Failed to execute SQL statement. Reason: :reason', array(':reason' => @drizzle_con_error($this->resource))); } $this->insert_id = preg_match("/^\\s*(insert|replace)\\s+/i", $sql) ? @drizzle_result_insert_id($command) : FALSE; $this->sql = $sql; @drizzle_result_free($command); }