Beispiel #1
0
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;
}
Beispiel #2
0
 /**
  * This function initializes the class.
  *
  * @access public
  * @override
  * @param DB_Connection_Driver $connection  the connection to be used
  * @param string $sql                       the SQL statement to be queried
  * @param integer $mode                     the execution mode to be used
  */
 public function __construct(DB_Connection_Driver $connection, $sql, $mode = NULL)
 {
     $resource = $connection->get_resource();
     $command = @drizzle_query($resource, $sql);
     if ($command === FALSE or !@drizzle_result_buffer($command)) {
         throw new Throwable_SQL_Exception('Message: Failed to query SQL statement. Reason: :reason', array(':reason' => @drizzle_con_error($resource)));
     }
     $this->command = $command;
     $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);
}
 /**
  * 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);
 }
Beispiel #5
0
 function find($table_type, $field, $value, $like = '', $partition_flag = '')
 {
     // drizzle
     if (strcmp($this->database_type, 'drizzle') == 0) {
         if (strcmp($like, 'like') == 0) {
             $like = 'like';
             $value = "'%{$value}'";
         } else {
             $like = '=';
         }
         if (strcmp($partition_flag, 'nopart') == 0) {
             $sql = "select * from {$table_type}" . "_no_partition where {$field} {$like} '{$value}'";
             $result = @drizzle_query($this->connection, $sql);
             if (!$result) {
                 die('Invalid query: ' . drizzle_con_error($this->connection));
             }
             drizzle_result_buffer($result) or die('ERROR: ' . drizzle_con_error($dbh) . "\n");
             while ($row = drizzle_row_next($result)) {
                 $myarray[] = $row;
             }
             return $myarray;
         }
         if (strcmp($partition_flag, 'drizzle') == 0) {
             $sql = "select * from {$table_type} where {$field} {$like} '{$value}'";
             print "partition sql: {$sql}\n";
             $result = @drizzle_query($this->connection, $sql);
             if (!$result) {
                 die('Invalid query: ' . drizzle_con_error($this->connection));
             }
             drizzle_result_buffer($result) or die('ERROR: ' . drizzle_con_error($dbh) . "\n");
             while ($row = drizzle_row_next($result)) {
                 $myarray[] = $row;
             }
             return $myarray;
         }
         // iterate through the tables using the meta_table
         $sql = "select * from meta_table where tablename like \"" . $table_type . "%\"";
         print $sql . "\n";
         try {
             $result = @drizzle_query($this->connection, $sql);
             if (!$result) {
                 throw new Exception('meta_table query failed');
             }
         } catch (Exception $e) {
             echo drizzle_con_error($this->connection) . "\n";
             echo "Caught active server error exception:\n", $e->getMessage(), " ", $e->getFile(), ": Line ", $e->getLine(), "\n", $e->getTraceAsString(), "\n";
         }
         drizzle_result_buffer($result) or die('ERROR: ' . drizzle_con_error($dbh) . "\n");
         while ($row = drizzle_row_next($result)) {
             print_r($row);
             $current_table = $row[1];
             $iterator = $row[2];
             $last_user_id = $row[3];
         }
         print "current_table: {$current_table}\n";
         // awesome, we got meta data
         // we need to now:
         // go through each table
         // find the info
         // return the info
         // get current_table number
         preg_match('/_[0-9]+/', $current_table, $matches);
         $bar_number = $matches[0];
         preg_match('/[0-9]+/', $bar_number, $matches);
         $table_number = $matches[0];
         // get how long the number is b/c of padding issues later
         $num_length = strlen($table_number);
         $i_table_number = (int) $table_number;
         // for ($i = 0; $i <= $i_table_number; $i++) {
         $i = 0;
         $i_sent = 0;
         $myarray = array();
         while ($i_sent <= 0) {
             // search each partition
             $curr_table = $table_type . "_" . padNumber($i, $num_length);
             $sql = "select * from {$curr_table} where {$field} {$like} '{$value}'";
             print $sql . "\n";
             $result = @drizzle_query($this->connection, $sql);
             if (!$result) {
                 die('Invalid query: ' . drizzle_con_error($this->connection));
             }
             drizzle_result_buffer($result) or die('ERROR: ' . drizzle_con_error($dbh) . "\n");
             while ($row = drizzle_row_next($result)) {
                 $myarray[] = $row;
             }
             print "count (myarray) : " . count($myarray) . "\n";
             if (count($myarray) >= 1) {
                 print "count > 1\n";
                 $i_sent = 1;
             }
             if ($i >= $i_table_number) {
                 print "{$i} <= {$i_table_number}\n";
                 $i_sent = 1;
             }
             $i++;
         }
         /*
         			$sql = "select * from $table where $field $like $value";
         			$result = mysql_query($sql, $this->connection);
         			if (!$result) {
         				die('Invalid query: ' . mysql_error());
         			}
         			while($row = mysql_fetch_assoc($result))
         			{
         			  $array[] = $row; 
         			}
         */
         print_r($myarray);
         return $myarray;
     }
     // end of drizzle portion
     // mysql
     if (strcmp($this->database_type, 'mysql') == 0) {
         if (strcmp($like, 'like') == 0) {
             $like = 'like';
             $value = "'%{$value}'";
         } else {
             $like = '=';
         }
         if (strcmp($partition_flag, 'nopart') == 0) {
             $sql = "select SQL_CACHE * from {$table_type}" . "_no_partition where {$field} {$like} '{$value}'";
             $result = mysql_query($sql, $this->connection);
             if (!$result) {
                 die('Invalid query: ' . mysql_error());
             }
             while ($row = mysql_fetch_assoc($result)) {
                 $myarray[] = $row;
             }
             return $myarray;
         }
         if (strcmp($partition_flag, 'mysql') == 0) {
             $sql = "select SQL_CACHE * from {$table_type} where {$field} {$like} '{$value}'";
             print "partition sql: {$sql}\n";
             $result = mysql_query($sql, $this->connection);
             if (!$result) {
                 die('Invalid query: ' . mysql_error());
             }
             while ($row = mysql_fetch_assoc($result)) {
                 $myarray[] = $row;
             }
             return $myarray;
         }
         // iterate through the tables using the meta_table
         $sql = "select SQL_CACHE * from meta_table where tablename like \"" . $table_type . "%\"";
         print $sql . "\n";
         $result = mysql_query($sql, $this->connection);
         if (!$result) {
             die('Cannnot access meta table: ' . mysql_error());
         }
         while ($row = mysql_fetch_assoc($result)) {
             $current_table = $row['tablename'];
             $iterator = $row['iterator'];
             $last_user_id = $row['last_user_id'];
         }
         print "current_table: {$current_table}\n";
         // awesome, we got meta data
         // we need to now:
         // go through each table
         // find the info
         // return the info
         // get current_table number
         preg_match('/_[0-9]+/', $current_table, $matches);
         $bar_number = $matches[0];
         preg_match('/[0-9]+/', $bar_number, $matches);
         $table_number = $matches[0];
         // get how long the number is b/c of padding issues later
         $num_length = strlen($table_number);
         $i_table_number = (int) $table_number;
         // for ($i = 0; $i <= $i_table_number; $i++) {
         $i = 0;
         $i_sent = 0;
         $myarray = array();
         while ($i_sent <= 0) {
             // search each partition
             $curr_table = $table_type . "_" . padNumber($i, $num_length);
             $sql = "select SQL_CACHE * from {$curr_table} where {$field} {$like} '{$value}'";
             print $sql . "\n";
             $result = mysql_query($sql, $this->connection);
             if (!$result) {
                 die('Invalid query: ' . mysql_error());
             }
             while ($row = mysql_fetch_assoc($result)) {
                 $myarray[] = $row;
             }
             print "count (myarray) : " . count($myarray) . "\n";
             if (count($myarray) >= 1) {
                 print "count > 1\n";
                 $i_sent = 1;
             }
             if ($i >= $i_table_number) {
                 print "{$i} <= {$i_table_number}\n";
                 $i_sent = 1;
             }
             $i++;
         }
         /*
         			$sql = "select * from $table where $field $like $value";
         			$result = mysql_query($sql, $this->connection);
         			if (!$result) {
         				die('Invalid query: ' . mysql_error());
         			}
         			while($row = mysql_fetch_assoc($result))
         			{
         			  $array[] = $row; 
         			}
         */
         print_r($myarray);
         return $myarray;
     }
     // end of mysql portion
 }
Beispiel #6
0
 /**
  * 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);
 }