Пример #1
0
function ExportTable($conn, $title, $filter, $dbtable, $dbjoin = "", $joinfield = "")
{
    $query = "SELECT * FROM {$dbtable}";
    if ($dbjoin) {
        $query .= " INNER JOIN {$dbjoin} ON {$dbtable}.{$joinfield}={$dbjoin}.{$joinfield}";
    }
    if ($filter) {
        $query .= " WHERE {$filter}";
    }
    $result = mysqli_query($conn, $query);
    $nrcampos = mysqli_field_count($conn);
    echo "<h2>{$title}</h2>";
    echo "{$dbtable}";
    if ($dbjoin) {
        echo "| <a href=\"dbshow.php?dbtable={$dbjoin}\" target=\"_blank\">{$dbjoin}</a>";
    }
    echo "| " . mysqli_num_rows($result) . " row(s)";
    echo "<p><table cellspacing=\"0\" cellpadding=\"5\" border=\"1\">";
    echo "<tr>";
    for ($i = 0; $i < $nrcampos; $i++) {
        $finfo = mysqli_fetch_field_direct($result, $i);
        echo "<td>" . $finfo->name . "</td>";
    }
    echo "</tr>";
    while ($row = mysqli_fetch_array($result)) {
        echo "<tr>";
        for ($i = 0; $i < $nrcampos; $i++) {
            echo "<td>" . $row[$i] . "</td>";
        }
        echo "</tr>";
    }
    echo "</table></p><br>&nbsp;";
}
Пример #2
0
function fnGetEventData($intThresholdEventID, $intColIndex)
{
    #$intSensorID = fnGet
    #if (!Is_Null($intSensorID)) {
    #$fnGEDSQL = "SELECT * FROM `tblthresholdevents` WHERE ((intThresholdEventID=" . $intThresholdEventID . ") AND booInProcess=1) OR ((intThresholdEventID=" . $intThresholdEventID . ") AND booIsNew=1)";
    $fnGEDSQL = "SELECT * FROM `tblthresholdevents` WHERE ((intThresholdEventID=" . $intThresholdEventID . "))";
    # AND booInProcess=1) OR ((intSensorID=" . $intSensorID . ") AND booIsNew=1)";
    echo "<br>!?!?!? fnGEDSQL: " . $fnGEDSQL;
    $linkged = mysqli_connect('localhost', 'root', '', 'climatecontroldata');
    $EventData = mysqli_query($linkged, $fnGEDSQL);
    #$rsEventData = mysqli_fetch_assoc($EventData);
    $intResCount = @mysqli_num_rows($EventData);
    $intCols = mysqli_field_count($linkged);
    if ($intColIndex <= $intCols) {
        # echo "<br>Total Cols: " . $intCols , "<br>Total Results: " . $intResCount;
        # $rsfnGEDarr = mysqli_fetch_array($EventData);
        # $GEDretVal = $rsfnGEDarr[1][1];
        $rsfnGED = mysqli_fetch_array($EventData, MYSQL_ASSOC);
        #printf("%s (%s)\n", $rsfnGED[0],$rsfnGED[4]);
        #$row = mysqli_fetch_row($EventData);
        $keys = @array_keys($rsfnGED);
        $GEDretVal = $rsfnGED[$keys[$intColIndex]];
    } else {
        echo "Requested ColumnID does not exist";
        die;
    }
    mysqli_close($linkged);
    return $GEDretVal;
}
function dump_properties($mysqli)
{
    printf("\nClass variables:\n");
    $variables = array_keys(get_class_vars(get_class($mysqli)));
    sort($variables);
    foreach ($variables as $k => $var) {
        printf("%s = '%s'\n", $var, var_export(@$mysqli->{$var}, true));
    }
    printf("\nObject variables:\n");
    $variables = array_keys(get_object_vars($mysqli));
    foreach ($variables as $k => $var) {
        printf("%s = '%s'\n", $var, var_export(@$mysqli->{$var}, true));
    }
    printf("\nMagic, magic properties:\n");
    assert(@mysqli_affected_rows($mysqli) === @$mysqli->affected_rows);
    printf("mysqli->affected_rows = '%s'/%s ('%s'/%s)\n", @$mysqli->affected_rows, gettype(@$mysqli->affected_rows), @mysqli_affected_rows($mysqli), gettype(@mysqli_affected_rows($mysqli)));
    assert(@mysqli_get_client_info() === @$mysqli->client_info);
    printf("mysqli->client_info = '%s'/%s ('%s'/%s)\n", @$mysqli->client_info, gettype(@$mysqli->client_info), @mysqli_get_client_info(), gettype(@mysqli_get_client_info()));
    assert(@mysqli_get_client_version() === @$mysqli->client_version);
    printf("mysqli->client_version =  '%s'/%s ('%s'/%s)\n", @$mysqli->client_version, gettype(@$mysqli->client_version), @mysqli_get_client_version(), gettype(@mysqli_get_client_version()));
    assert(@mysqli_errno($mysqli) === @$mysqli->errno);
    printf("mysqli->errno = '%s'/%s ('%s'/%s)\n", @$mysqli->errno, gettype(@$mysqli->errno), @mysqli_errno($mysqli), gettype(@mysqli_errno($mysqli)));
    assert(@mysqli_error($mysqli) === @$mysqli->error);
    printf("mysqli->error = '%s'/%s ('%s'/%s)\n", @$mysqli->error, gettype(@$mysqli->error), @mysqli_error($mysqli), gettype(@mysqli_error($mysqli)));
    assert(@mysqli_field_count($mysqli) === @$mysqli->field_count);
    printf("mysqli->field_count = '%s'/%s ('%s'/%s)\n", @$mysqli->field_count, gettype(@$mysqli->field_count), @mysqli_field_count($mysqli), gettype(@mysqli_field_count($mysqli)));
    assert(@mysqli_insert_id($mysqli) === @$mysqli->insert_id);
    printf("mysqli->insert_id = '%s'/%s ('%s'/%s)\n", @$mysqli->insert_id, gettype(@$mysqli->insert_id), @mysqli_insert_id($mysqli), gettype(@mysqli_insert_id($mysqli)));
    assert(@mysqli_sqlstate($mysqli) === @$mysqli->sqlstate);
    printf("mysqli->sqlstate = '%s'/%s ('%s'/%s)\n", @$mysqli->sqlstate, gettype(@$mysqli->sqlstate), @mysqli_sqlstate($mysqli), gettype(@mysqli_sqlstate($mysqli)));
    assert(@mysqli_get_host_info($mysqli) === @$mysqli->host_info);
    printf("mysqli->host_info = '%s'/%s ('%s'/%s)\n", @$mysqli->host_info, gettype(@$mysqli->host_info), @mysqli_get_host_info($mysqli), gettype(@mysqli_get_host_info($mysqli)));
    /* note that the data types are different */
    assert(@mysqli_info($mysqli) == @$mysqli->info);
    printf("mysqli->info = '%s'/%s ('%s'/%s)\n", @$mysqli->info, gettype(@$mysqli->info), @mysqli_info($mysqli), gettype(@mysqli_info($mysqli)));
    assert(@mysqli_thread_id($mysqli) > @$mysqli->thread_id);
    assert(gettype(@$mysqli->thread_id) == gettype(@mysqli_thread_id($mysqli)));
    printf("mysqli->thread_id = '%s'/%s ('%s'/%s)\n", @$mysqli->thread_id, gettype(@$mysqli->thread_id), @mysqli_thread_id($mysqli), gettype(@mysqli_thread_id($mysqli)));
    assert(@mysqli_get_proto_info($mysqli) === @$mysqli->protocol_version);
    printf("mysqli->protocol_version = '%s'/%s ('%s'/%s)\n", @$mysqli->protocol_version, gettype(@$mysqli->protocol_version), @mysqli_get_proto_info($mysqli), gettype(@mysqli_get_proto_info($mysqli)));
    assert(@mysqli_get_server_info($mysqli) === @$mysqli->server_info);
    printf("mysqli->server_info = '%s'/%s ('%s'/%s)\n", @$mysqli->server_info, gettype(@$mysqli->server_info), @mysqli_get_server_info($mysqli), gettype(@mysqli_get_server_info($mysqli)));
    assert(@mysqli_get_server_version($mysqli) === @$mysqli->server_version);
    printf("mysqli->server_version = '%s'/%s ('%s'/%s)\n", @$mysqli->server_version, gettype(@$mysqli->server_version), @mysqli_get_server_version($mysqli), gettype(@mysqli_get_server_version($mysqli)));
    assert(@mysqli_warning_count($mysqli) === @$mysqli->warning_count);
    printf("mysqli->warning_count = '%s'/%s ('%s'/%s)\n", @$mysqli->warning_count, gettype(@$mysqli->warning_count), @mysqli_warning_count($mysqli), gettype(@mysqli_warning_count($mysqli)));
    printf("\nAccess to undefined properties:\n");
    printf("mysqli->unknown = '%s'\n", @$mysqli->unknown);
    @($mysqli->unknown = 13);
    printf("setting mysqli->unknown, @mysqli_unknown = '%s'\n", @$mysqli->unknown);
    $unknown = 'friday';
    @($mysqli->unknown = $unknown);
    printf("setting mysqli->unknown, @mysqli_unknown = '%s'\n", @$mysqli->unknown);
    printf("\nAccess hidden properties for MYSLQI_STATUS_INITIALIZED (TODO documentation):\n");
    assert(@mysqli_connect_error() === @$mysqli->connect_error);
    printf("mysqli->connect_error = '%s'/%s ('%s'/%s)\n", @$mysqli->connect_error, gettype(@$mysqli->connect_error), @mysqli_connect_error(), gettype(@mysqli_connect_error()));
    assert(@mysqli_connect_errno() === @$mysqli->connect_errno);
    printf("mysqli->connect_errno = '%s'/%s ('%s'/%s)\n", @$mysqli->connect_errno, gettype(@$mysqli->connect_errno), @mysqli_connect_errno(), gettype(@mysqli_connect_errno()));
}
Пример #4
0
function grr_sql_query1($sql)
{
    $r = mysqli_query($GLOBALS['db_c'], $sql);
    if (!$r) {
        return -1;
    }
    if (mysqli_num_rows($r) != 1 || mysqli_field_count($GLOBALS['db_c']) != 1 || ($result_ = mysqli_result($r, 0, 0)) == "") {
        $result_ = -1;
    }
    mysqli_free_result($r);
    return $result_;
}
Пример #5
0
function do_download()
{
    $backup_name = 'LMT Backup ' . time() . '.sql';
    header('Content-Description: File Transfer');
    header('Content-Type: application/octet-stream');
    header('Content-Disposition: attachment; filename="' . $backup_name . '"');
    header('Content-Transfer-Encoding: binary');
    header('Expires: 0');
    header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
    cancel_templateify();
    ob_clean();
    flush();
    echo 'CREATE DATABASE `lmt-bak` DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci;' . "\n" . 'USE `lmt-bak`;' . "\n\n\n";
    $tables = array();
    $result = DB::queryRaw('SHOW TABLES');
    while ($row = mysqli_fetch_row($result)) {
        $tables[] = $row[0];
    }
    foreach ($tables as $table) {
        $result = DB::queryRaw('SELECT * FROM ' . $table);
        $num_fields = mysqli_field_count($result);
        echo 'DROP TABLE IF EXISTS ' . $table . ';';
        $row2 = mysqli_fetch_row(DB::queryRaw('SHOW CREATE TABLE ' . $table));
        echo "\n\n" . $row2[1] . ";\n\n";
        for ($i = 0; $i < $num_fields; $i++) {
            while ($row = mysqli_fetch_row($result)) {
                echo 'INSERT INTO ' . $table . ' VALUES(';
                for ($j = 0; $j < $num_fields; $j++) {
                    if (!isset($row[$j]) || is_null($row[$j])) {
                        echo 'NULL';
                    } else {
                        $row[$j] = addslashes($row[$j]);
                        $row[$j] = preg_replace("\n", "\\n", $row[$j]);
                        echo '"' . $row[$j] . '"';
                    }
                    if ($j < $num_fields - 1) {
                        echo ',';
                    }
                }
                echo ");\n";
            }
        }
        echo "\n\n\n";
    }
}
Пример #6
0
    die("Connection failed: " . $conn->connect_error);
}
//Grab the count of the number of cities PATIENTS
//SELECT city, id FROM femr.patients WHERE city NOT IN (SELECT name FROM mission_cities)
//SELECT city, id FROM femr.patients LIMIT 5
$patientCities = "SELECT city, id FROM femr.patients WHERE city NOT IN(SELECT name FROM mission_cities) LIMIT 5";
$resultQuery = $conn->query($patientCities);
$countQuery = mysqli_field_count($conn);
// while($row = $resultQuery->fetch_array()){
// for($i = 0; $i < $countQuery;$i++)
// echo $row[$i];
// }
//Grabbing the count of the cities DICTIONARY
$cityDictionary = "SELECT name FROM femr.mission_cities";
$resultQuery2 = $conn->query($cityDictionary);
$countQuery2 = mysqli_field_count($conn);
// while($row2 = $resultQuery2->fetch_array()){
// for($j = 0; $j < $countQuery2;$j++)
// echo $row[$j];
// }
?>
  <div class="jumbotron"> <div class='container'>
<center><img align="middle" src="images/femrLogo.png"></img></center>
<center><h1> City Cleanse Results </h1></center>
 <center><div class='row col-md-6 col-md-offset-2 custyle'></center>

 <table class='table table-striped custab table-bordered'>


 <thead>
     <tr>
Пример #7
0
 public function executeSQL($query, &$resultArry, &$rowsAffected, $assoc = TRUE)
 {
     $l_iTries = 3;
     //times
     $l_iPause = 2;
     //seconds
     $l_bConnected = FALSE;
     //bool
     do {
         $link = mysqli_init();
         $rowsAffected = 0;
         if (!$link) {
             throw new DBAdapter2Exception("mysqli_init failed");
         }
         if (!mysqli_options($link, MYSQLI_OPT_CONNECT_TIMEOUT, 5)) {
             throw new DBAdapter2Exception("Setting MYSQLI_OPT_CONNECT_TIMEOUT failed");
         }
         if (!mysqli_real_connect($link, $this->host, $this->username, $this->password, $this->schema)) {
             unset($link);
             sleep($l_iPause);
             $l_iTries = $l_iTries - 1;
         } else {
             $l_bConnected = TRUE;
             $l_iTries = 0;
         }
     } while (!$l_bConnected && $l_iTries > 0);
     if (!$l_bConnected) {
         throw new DBAdapter2Exception('Connect Error (' . mysqli_connect_errno() . ') ' . mysqli_connect_error());
     }
     if (!mysqli_set_charset($link, $this->charset)) {
         throw new DBAdapter2Exception('Error loading character set ' . $this->charset . ' - ' . mysqli_error($link));
     }
     //do queries
     if (mysqli_real_query($link, $query)) {
         //should be e proper select
         if (mysqli_field_count($link)) {
             //buffered
             $result = mysqli_store_result($link);
             if ($result) {
                 $resultArry = array();
                 $rowsAffected = mysqli_num_rows($result);
                 if ($assoc) {
                     while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
                         $resultArry[] = $row;
                     }
                 } else {
                     while ($row = mysqli_fetch_array($result, MYSQLI_NUM)) {
                         $resultArry[] = $row;
                     }
                 }
                 mysqli_free_result($result);
                 unset($result);
             }
         }
     } else {
         throw new DBAdapter2Exception('Error in query: ' . mysqli_error($link));
     }
     mysqli_close($link);
 }
Пример #8
0
 function backup_tables_mysqli($host, $user, $pass, $name, $tables = '*')
 {
     $link = mysqli_connect($host, $user, $pass, $name);
     /* Obtebemos las tablas */
     if ($tables == '*') {
         $tables = array();
         $result = mysqli_query($link, 'SHOW TABLES');
         while ($row = mysqli_fetch_row($result)) {
             $tables[] = $row[0];
         }
     } else {
         $tables = is_array($tables) ? $tables : explode(',', $tables);
     }
     /* generamos el contenido */
     foreach ($tables as $table) {
         $result = mysqli_query($link, 'SELECT * FROM ' . $table);
         $num_fields = mysqli_field_count($link);
         $return .= 'DROP TABLE ' . $table . ';';
         $row2 = mysqli_fetch_row(mysqli_query($link, 'SHOW CREATE TABLE ' . $table));
         $return .= "\n\n" . $row2[1] . ";\n\n";
         for ($i = 0; $i < $num_fields; $i++) {
             while ($row = mysqli_fetch_row($result)) {
                 $return .= 'INSERT INTO ' . $table . ' VALUES(';
                 for ($j = 0; $j < $num_fields; $j++) {
                     $row[$j] = addslashes($row[$j]);
                     $row[$j] = ereg_replace("\n", "\\n", $row[$j]);
                     if (isset($row[$j])) {
                         $return .= '"' . $row[$j] . '"';
                     } else {
                         $return .= '""';
                     }
                     if ($j < $num_fields - 1) {
                         $return .= ',';
                     }
                 }
                 $return .= ");\n";
             }
         }
         $return .= "\n\n\n";
     }
     /* Guardamos el archivo */
     $handle = fopen('db-backup-' . time() . '-' . md5(implode(',', $tables)) . '.sql', 'w+');
     if (fwrite($handle, $return)) {
         fclose($handle);
         echo "<script>alert('Archivo creado, descargalo desde la pagina principal')</script>";
     } else {
         echo "<script>alert('No se pudo descargar')</script>";
     }
 }
Пример #9
0
 function sql_num_fields($type, $result, $con)
 {
     if ($type === 'mysql') {
         if (function_exists('mysqli_field_count')) {
             return mysqli_field_count($con);
         } elseif (function_exists('mysql_num_fields')) {
             return mysql_num_fields($result);
         }
     } elseif ($type === 'mssql') {
         if (function_exists('mssql_num_fields')) {
             return mssql_num_fields($result);
         } elseif (function_exists('sqlsrv_num_fields')) {
             return sqlsrv_num_fields($result);
         }
     } elseif ($type === 'pgsql') {
         return pg_num_fields($result);
     } elseif ($type === 'oracle') {
         return oci_num_fields($result);
     } elseif ($type === 'sqlite3') {
         return $result->numColumns();
     } elseif ($type === 'sqlite') {
         return sqlite_num_fields($result);
     } elseif ($type === 'odbc') {
         return odbc_num_fields($result);
     } elseif ($type === 'pdo') {
         return $result->columnCount();
     }
 }
}
if ($_POST['ward'] != '0') {
    $ward_sqlsafe = " AND Participants.Ward = '" . mysqli_real_escape_string($cnnSWOP, $_POST['ward']) . "' ";
} else {
    $ward_sqlsafe = "";
}
$search_pool_sqlsafe = "SELECT * FROM Participants " . $status_sqlsafe . $join_inst_sqlsafe . $benchmarks_sqlsafe . $date_join_sqlsafe . $organizer_join_sqlsafe . $member_type_join_sqlsafe . "LEFT JOIN Participants_Properties ON Participants.Participant_ID=Participants_Properties.Participant_ID\r\n            WHERE Participants.Participant_ID IS NOT NULL " . $institution_sqlsafe . $type_sqlsafe . $step_sqlsafe . $step_done_sqlsafe . $start_sqlsafe . $end_sqlsafe . $lag_sqlsafe . $organizer_sqlsafe . $first_name_sqlsafe . $last_name_sqlsafe . $email_sqlsafe . $phone_sqlsafe . $notes_sqlsafe . $date_of_birth_sqlsafe . $gender_sqlsafe . $has_itin_sqlsafe . $ward_sqlsafe . $language_spoken_sqlsafe;
//echo $search_pool . "<p>";
include "../include/dbconnopen.php";
$search_results = mysqli_query($cnnSWOP, $search_pool_sqlsafe);
?>

<table class="all_projects">
    <caption>Choose the columns you would like to view and export for this query:</caption>
    <?php 
$num_columns = mysqli_field_count($cnnSWOP);
//echo $num_columns;
//this is brought over from PAWS.  I'm trying to give Sarah what she wants in terms of checkboxes to determine which search fields will be
//returned.
$table = '';
for ($k = 0; $k < $num_columns; $k++) {
    $get_column_names = mysqli_fetch_field_direct($search_results, $k);
    //skip Name_Middle field
    if ($get_column_names->name == "Name_Middle") {
        continue;
    }
    if ($get_column_names->table != 'progress' && $get_column_names->table != 'laststatus') {
        if ($get_column_names->table != $table) {
            $table = $get_column_names->table;
            ?>
<tr class="note"><th colspan="4"><a href="javascript:;" onclick="
Пример #11
0
 /**
  * Executes the given SQL query and returns the records
  *
  * @param string $sql The query string should not end with a semicolon
  * @return object PHP 'mysql result' resource object containing the records
  *                on SELECT, SHOW, DESCRIBE or EXPLAIN queries and returns;
  *                TRUE or FALSE for all others i.e. UPDATE, DELETE, DROP
  *                AND FALSE on all errors (setting the local Error message)
  */
 public function Query($sql)
 {
     $this->ResetError();
     $this->last_sql = $sql;
     $this->last_result = @mysqli_query($this->mysql_link, $sql);
     if (!$this->last_result) {
         $this->active_row = -1;
         $this->SetError();
         return false;
     } else {
         if (strpos(strtolower($sql), "insert") === 0) {
             $this->last_insert_id = mysqli_insert_id($this->mysql_link);
             if ($this->last_insert_id === false) {
                 $this->SetError();
                 return false;
             } else {
                 $numrows = 0;
                 $this->active_row = -1;
                 return $this->last_result;
             }
         } else {
             if (strpos(strtolower($sql), "select") === 0) {
                 $numrows = mysqli_field_count($this->mysql_link);
                 if ($numrows > 0) {
                     $this->active_row = 0;
                 } else {
                     $this->active_row = -1;
                 }
                 $this->last_insert_id = 0;
                 return $this->last_result;
             } else {
                 return $this->last_result;
             }
         }
     }
 }
Пример #12
0
 /**
  * Executes query and Return new DBStatementI or int if this is INSERT statement
  *
  * @param $query
  * @return DBStatementI|int
  */
 public function queryLastId($query)
 {
     mysqli_select_db($this->_linkIdentifier, $this->_database);
     if (static::$_debug) {
         echo $query . "<br />\n";
     }
     $queryResult = mysqli_real_query($this->_linkIdentifier, $query);
     $mysqli_field_count = mysqli_field_count($this->_linkIdentifier);
     if ($mysqli_field_count) {
         $result = mysqli_store_result($this->_linkIdentifier);
     } else {
         $result = $queryResult;
     }
     if ($result === true && preg_match('/^\\s*"?(INSERT|REPLACE)\\s+/i', $query)) {
         $insertId = (int) $this->insertId();
         return $insertId;
     }
     return new DBStatementI($result);
 }
Пример #13
0
 /**
  * フィールド数を取得
  *
  * @return int|null
  */
 public function fieldsCount()
 {
     if ($this->mysql_mode == MYSQL_MODE_MYSQL) {
         return mysql_num_fields($this->linkId);
     } else {
         if ($this->mysql_mode == MYSQL_MODE_MYSQLI) {
             return mysqli_field_count($this->linkId);
         }
     }
     return null;
 }
Пример #14
0
 /**
  *  結果データを構築する
  *
  *  結果セットを取得する
  *    - 一括、逐次読み込みを任意に設定する場合は引数で指定する
  *    - デフォルトは一括読み込みとする
  *
  *  @param   boolean  結果セットを一括読み込みする場合TRUE
  *  @retrun  boolean  TRUE:成功時
  */
 protected function use_or_store_result($store_result)
 {
     // 結果データを返さない場合はそのまま終了
     if (mysqli_field_count($this->le_link) < 1) {
         return TRUE;
     }
     // 結果データを取得
     set_error_handler(array($this, 'php_error_handler'));
     $le_result = $store_result ? mysqli_store_result($this->le_link) : mysqli_use_result($this->le_link);
     restore_error_handler();
     if ($le_result === FALSE) {
         return FALSE;
     }
     // フィールド情報を取得する
     foreach (mysqli_fetch_fields($le_result) as $field) {
         $tmp = array(self::FIELD_DEF_IS_POS => count($this->def_fields), self::FIELD_DEF_IS_TYPE => $field->type, self::FIELD_DEF_IS_NAME => $field->name, self::FIELD_DEF_IS_NAME_ORIG => $field->orgname, self::FIELD_DEF_IS_TABLE => $field->table, self::FIELD_DEF_IS_TABLE_ORIG => $field->orgtable);
         // MEMO : 底層レベルのバグでorgnameが取得できない場合がある
         if (strlen($field->orgname) < 1) {
             $this->def_fields[$field->name] = $tmp;
         } else {
             $this->def_fields[$field->orgname] = $tmp;
         }
     }
     $this->le_result = $le_result;
     $this->affected_rows = mysqli_num_rows($le_result);
 }
Пример #15
0
 public function getLengthFields($rs)
 {
     return @mysqli_field_count($rs);
 }
Пример #16
0
 public function FieldsCount()
 {
     return mysqli_field_count($this->res);
 }
$stmt = mysqli_stmt_init($link);
/* Depending on your version, the MySQL server migit not support this */
if ($stmt->prepare('EXPLAIN SELECT t1.*, t2.* FROM test AS t1, test AS t2') && $stmt->execute()) {
    if (!mysqli_stmt_store_result($stmt)) {
        printf("[008] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
    }
    if (!($res_meta = mysqli_stmt_result_metadata($stmt))) {
        printf("[009] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
    }
    if (($tmp = mysqli_stmt_num_rows($stmt)) !== $num_rows) {
        printf("[010] Expecting int/%d got %s/%s\n", $num_rows, gettype($tmp), $tmp);
    }
    if (($tmp = mysqli_stmt_field_count($stmt)) !== $num_fields) {
        printf("[011] Expecting int/%d got %s/%s\n", $num_fields, gettype($tmp), $tmp);
    }
    if (($tmp = mysqli_field_count($link)) !== $num_fields) {
        printf("[013] Expecting int/%d got %s/%s\n", $num_fields, gettype($tmp), $tmp);
    }
    if (($tmp = $res_meta->field_count) !== $num_fields) {
        printf("[014] Expecting int/%d got %s/%s\n", $num_fields, gettype($tmp), $tmp);
    }
    $fields_res_meta = mysqli_fetch_fields($res_meta);
    if (($tmp = count($fields_res_meta)) !== $num_fields) {
        printf("[015] Expecting int/%d got %s/%s\n", $num_fields, gettype($tmp), $tmp);
    }
    if ($fields_res_meta != $fields) {
        printf("[016] Prepared Statement metadata differs from normal metadata, dumping\n");
        var_dump($fields_res_meta);
        var_dump($fields);
    }
    if (function_exists('mysqli_stmt_get_result') && $stmt->prepare('EXPLAIN SELECT t1.*, t2.* FROM test AS t1, test AS t2') && $stmt->execute()) {
Пример #18
0
 /**
  * Returns the last query as a JSON document
  *
  * @return string JSON containing all records listed
  */
 public function GetJSON()
 {
     if ($this->last_result) {
         if ($this->RowCount() > 0) {
             for ($i = 0, $il = mysqli_field_count($this->mysql_link); $i < $il; $i++) {
                 $field = mysqli_fetch_field_direct($this->last_result, $i);
                 $types[$i] = $field->type;
             }
             $json = '[';
             $this->MoveFirst();
             while ($member = mysqli_fetch_object($this->last_result)) {
                 $json .= json_encode($member) . ",";
             }
             $json .= ']';
             $json = str_replace("},]", "}]", $json);
         } else {
             $json = 'null';
         }
     } else {
         $this->active_row = -1;
         $json = 'null';
     }
     return $json;
 }
Пример #19
0
<?php

require_once "connect.inc";
/*** test mysqli_connect 127.0.0.1 ***/
$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket);
mysqli_real_query($link, "SHOW VARIABLES");
if (mysqli_field_count($link)) {
    $result = mysqli_store_result($link);
    $num = mysqli_num_fields($result);
    mysqli_free_result($result);
}
var_dump($num);
mysqli_close($link);
print "done!";
}
printf("\nClass variables:\n");
$variables = array_keys(get_class_vars(get_class($mysqli_result)));
sort($variables);
foreach ($variables as $k => $var) {
    printf("%s\n", $var);
}
printf("\nObject variables:\n");
$variables = array_keys(get_object_vars($mysqli_result));
foreach ($variables as $k => $var) {
    printf("%s\n", $var);
}
printf("\nMagic, magic properties:\n");
assert(($tmp = mysqli_field_tell($res)) === $mysqli_result->current_field);
printf("mysqli_result->current_field = '%s'/%s ('%s'/%s)\n", $mysqli_result->current_field, gettype($mysqli_result->current_field), $tmp, gettype($tmp));
assert(($tmp = mysqli_field_count($link)) === $mysqli_result->field_count);
printf("mysqli_result->field_count = '%s'/%s ('%s'/%s)\n", $mysqli_result->field_count, gettype($mysqli_result->field_count), $tmp, gettype($tmp));
assert(($tmp = mysqli_fetch_lengths($res)) === $mysqli_result->lengths);
printf("mysqli_result->lengths -> '%s'/%s ('%s'/%s)\n", is_array($mysqli_result->lengths) ? implode(' ', $mysqli_result->lengths) : 'n/a', gettype($mysqli_result->lengths), is_array($tmp) ? implode(' ', $tmp) : 'n/a', gettype($tmp));
assert(($tmp = mysqli_num_rows($res)) === $mysqli_result->num_rows);
printf("mysqli_result->num_rows = '%s'/%s ('%s'/%s)\n", $mysqli_result->num_rows, gettype($mysqli_result->num_rows), $tmp, gettype($tmp));
assert(in_array($mysqli_result->type, array(MYSQLI_STORE_RESULT, MYSQLI_USE_RESULT)));
printf("mysqli_result->type = '%s'/%s\n", MYSQLI_STORE_RESULT == $mysqli_result->type ? 'store' : 'use', gettype($mysqli_result->type));
printf("\nAccess to undefined properties:\n");
printf("mysqli_result->unknown = '%s'\n", @$mysqli_result->unknown);
printf("\nConstructor:\n");
if (!is_object($res = new mysqli_result($link))) {
    printf("[001] Expecting object/mysqli_result got %s/%s\n", gettye($res), $res);
}
if (!mysqli_query($link, "SELECT id FROM test_mysqli_class_mysqli_result_interface_table_1 ORDER BY id")) {
    printf("[003] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
Пример #21
0
function sql_num_fields($q_id = '')
{
    if (empty($q_id)) {
        global $query_id;
        $q_id = $query_id;
    }
    return @mysqli_field_count($q_id);
}
Пример #22
0
 /**
  * @return int|null
  */
 private function fieldsCount()
 {
     if ($this->mode == self::MODE_MYSQL) {
         return mysql_num_fields($this->linkId);
     } else {
         if ($this->mode == self::MODE_MYSQLI) {
             return mysqli_field_count($this->linkId);
         } else {
             if ($this->mode == self::MODE_PDO) {
             }
         }
     }
     return null;
 }
function testStatement($offset, $link, $sql, $expected_lib, $expected_mysqlnd, $check_mysqlnd, $compare)
{
    if (!($stmt = mysqli_stmt_init($link))) {
        printf("[%04d - %s] [%d] %s\n", $offset, $sql, mysqli_errno($link), mysqli_error($link));
        return false;
    }
    if (!@mysqli_stmt_prepare($stmt, $sql)) {
        /* Not all server versions will support all statements */
        /* Failing to prepare is OK */
        return true;
    }
    if (empty($expected_lib) && false !== $res) {
        printf("[%04d - %s] No metadata expected\n", $offset + 1, $sql);
        return false;
    } else {
        if (!empty($expected_lib) && false == $res) {
            printf("[%04d - %s] Metadata expected\n", $offset + 2, $sql);
            return false;
        }
    }
    if (!empty($expected_lib)) {
        if (!is_object($res)) {
            printf("[%04d - %s] [%d] %s\n", $offset + 3, $sql, mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
            return false;
        }
        if (get_class($res) != 'mysqli_result') {
            printf("[%04d - %s] Expecting object/mysqli_result got object/%s\n", $offset + 4, $sql, get_class($res));
            return false;
        }
        $meta = array('num_fields' => mysqli_num_fields($res), 'fetch_field' => mysqli_fetch_field($res), 'fetch_field_direct0' => mysqli_fetch_field_direct($res, 0), 'fetch_field_direct1' => @mysqli_fetch_field_direct($res, 1), 'fetch_fields' => count(mysqli_fetch_fields($res)), 'field_count' => $res->field_count, 'field_seek-1' => @mysqli_field_seek($res, -1), 'field_seek0' => mysqli_field_seek($res, 0), 'field_tell' => mysqli_field_tell($res));
        if (is_object($meta['fetch_field'])) {
            $meta['fetch_field']->charsetnr = 'ignore';
            $meta['fetch_field']->flags = 'ignore';
        }
        if (is_object($meta['fetch_field_direct0'])) {
            $meta['fetch_field_direct0']->charsetnr = 'ignore';
            $meta['fetch_field_direct0']->flags = 'ignore';
        }
        if (is_object($meta['fetch_field_direct1'])) {
            $meta['fetch_field_direct1']->charsetnr = 'ignore';
            $meta['fetch_field_direct1']->flags = 'ignore';
        }
        mysqli_free_result($res);
        if ($meta != $expected_lib) {
            printf("[%04d - %s] Metadata differs from expected values\n", $offset + 5, $sql);
            var_dump($meta);
            var_dump($expected_lib);
            return false;
        }
    }
    if (function_exists('mysqli_stmt_get_result')) {
        /* mysqlnd only */
        if (!mysqli_stmt_execute($stmt)) {
            printf("[%04d - %s] [%d] %s\n", $offset + 6, $sql, mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
            return false;
        }
        $res = mysqli_stmt_get_result($stmt);
        if (false === $res && !empty($expected_mysqlnd)) {
            printf("[%04d - %s] Expecting resultset [%d] %s\n", $offset + 7, $sql, mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
            return false;
        } else {
            if (empty($expected_mysqlnd) && false !== $res) {
                printf("[%04d - %s] Unexpected resultset [%d] %s\n", $offset + 8, $sql, mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
                return false;
            }
        }
        if (!is_object($res)) {
            printf("[%04d - %s] [%d] %s\n", $offset + 9, $sql, mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
            return false;
        }
        if ('mysqli_result' != get_class($res)) {
            printf("[%04d - %s] Expecting object/mysqli_result got object/%s\n", $offset + 10, $sql, get_class($res));
            return false;
        }
        $meta_res = array('num_fields' => mysqli_num_fields($res), 'fetch_field' => mysqli_fetch_field($res), 'fetch_field_direct0' => mysqli_fetch_field_direct($res, 0), 'fetch_field_direct1' => @mysqli_fetch_field_direct($res, 1), 'fetch_fields' => count(mysqli_fetch_fields($res)), 'field_count' => mysqli_field_count($link), 'field_seek-1' => @mysqli_field_seek($res, -1), 'field_seek0' => mysqli_field_seek($res, 0), 'field_tell' => mysqli_field_tell($res));
        if (is_object($meta_res['fetch_field'])) {
            $meta_res['fetch_field']->charsetnr = 'ignore';
            $meta_res['fetch_field']->flags = 'ignore';
        }
        if (is_object($meta_res['fetch_field_direct0'])) {
            $meta_res['fetch_field_direct0']->charsetnr = 'ignore';
            $meta_res['fetch_field_direct0']->flags = 'ignore';
        }
        if (is_object($meta_res['fetch_field_direct1'])) {
            $meta_res['fetch_field_direct1']->charsetnr = 'ignore';
            $meta_res['fetch_field_direct1']->flags = 'ignore';
        }
        mysqli_free_result($res);
        if ($check_mysqlnd && $meta_res != $expected_mysqlnd) {
            printf("[%04d - %s] Metadata differs from expected\n", $offset + 11, $sql);
            var_dump($meta_res);
            var_dump($expected_mysqlnd);
        } else {
            if ($meta_res['field_count'] < 1) {
                printf("[%04d - %s] Metadata seems wrong, no fields?\n", $offset + 12, $sql);
                var_dump($meta_res);
                var_dump(mysqli_fetch_assoc($res));
            }
        }
        if ($compare && $meta_res != $meta) {
            printf("[%04d - %s] Metadata returned by mysqli_stmt_result_metadata() and mysqli_stmt_get_result() differ\n", $offset + 13, $sql);
            var_dump($meta_res);
            var_dump($meta);
        }
    }
    mysqli_stmt_close($stmt);
    return true;
}
Пример #24
0
     $schema = $row[1] . ";";
     $fd .= "{$schema}\n";
 }
 //On ne sauvegarde pas les données de la table ".TABLE_PREFIX."_log
 if ($donnees && $temp != "" . TABLE_PREFIX . "_log") {
     // les données de la table
     $fd .= "#\n# Données de {$temp}\n#\n";
     $query = "SELECT * FROM {$temp}";
     $resData = mysqli_query($GLOBALS['db_c'], $query);
     //peut survenir avec la corruption d'une table, on prévient
     if (!$resData) {
         $fd .= "Problème avec les données de {$temp}, corruption possible !\n";
     } else {
         if (mysqli_num_rows($resData) > 0) {
             $sFieldnames = "";
             $num_fields = mysqli_field_count($GLOBALS['db_c']);
             if ($insertComplet) {
                 for ($k = 0; $k < $num_fields; $k++) {
                     $sFieldnames .= "`" . mysql_field_name($resData, $k) . "`";
                     //on ajoute à la fin une virgule si nécessaire
                     if ($k < $num_fields - 1) {
                         $sFieldnames .= ", ";
                     }
                 }
                 $sFieldnames = "({$sFieldnames})";
             }
             $sInsert = "INSERT INTO {$temp} {$sFieldnames} values ";
             while ($rowdata = mysqli_fetch_row($resData)) {
                 $lesDonnees = "";
                 for ($mp = 0; $mp < $num_fields; $mp++) {
                     $lesDonnees .= "'" . mysqli_real_escape_string($GLOBALS['db_c'], $rowdata[$mp]) . "'";
Пример #25
0
/**
* Dump all tables (except csv import cache) into text files
* It is assumed that all tables exist and empty in target db
*
* @param mixed $db
* @param mixed $verbose
*/
function db_dump($db, $verbose = true)
{
    // Create dump directory
    $directory = HEURIST_UPLOAD_ROOT . $db;
    if (!file_exists($directory)) {
        mkdir($directory, 0777, true);
    }
    // Create file
    $filename = $directory . "/hdb_" . $db . "_" . time() . ".sql";
    $file = fopen($filename, "a+");
    $mysqli = server_connect();
    if ($mysqli && $mysqli->select_db("hdb_" . $db)) {
        // SQL settings
        $settings = "/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;\n\n        /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;\n\n        /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;\n\n        /*!40101 SET NAMES utf8 */;\n\n        /*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;\n\n        /*!40103 SET TIME_ZONE='+00:00' */;\n\n        /*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;\n\n        /*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;\n\n        /*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;\n\n        /*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;\n";
        fwrite($file, $settings);
        // Dump all tables of the database
        $tables = $mysqli->query("SHOW TABLES");
        if ($tables) {
            // Start to dump all tables
            while ($table = $tables->fetch_row()) {
                $table = $table[0];
                // Select everything in the table
                $result = $mysqli->query('SELECT * FROM ' . $table);
                $num_fields = mysqli_field_count($mysqli);
                // Drop table sql
                $output = '\\n\\nDROP TABLE IF EXISTS `' . $table . '`;';
                // Create table sql
                $row2 = mysqli_fetch_row($mysqli->query('SHOW CREATE TABLE ' . $table));
                $output .= $row2[1] . ";\n\n";
                // Insert values sql
                $output .= '/*!40000 ALTER TABLE ' . $table . ' DISABLE KEYS */;';
                for ($i = 0; $i < $num_fields; $i++) {
                    while ($row = $result->fetch_row()) {
                        $output .= 'INSERT INTO ' . $table . ' VALUES(';
                        for ($j = 0; $j < $num_fields; $j++) {
                            $row[$j] = addslashes($row[$j]);
                            $row[$j] = ereg_replace("\n", "\\n", $row[$j]);
                            if (isset($row[$j])) {
                                $output .= '"' . $row[$j] . '"';
                            } else {
                                $output .= '""';
                            }
                            if ($j < $num_fields - 1) {
                                $output .= ',';
                            }
                        }
                        $output .= ");\n";
                    }
                }
                $output .= '/*!40000 ALTER TABLE ' . $table . ' ENABLE KEYS */;';
                // Write table sql to file
                $output .= "\n\n\n";
                fwrite($file, $output);
            }
        }
        fwrite($file, "SET FOREIGN_KEY_CHECKS=1;\n");
        fwrite($file, "SET sql_mode = 'TRADITIONAL';\n");
        $mysqli->close();
    } else {
        if ($verbose) {
            echo "Failed to connect to database hdb_" . $db;
        }
        return false;
    }
    // Close file
    fclose($file);
    chmod($filename, 0777);
    // Echo output
    if ($verbose) {
        $size = filesize($filename) / pow(1024, 2);
        echo "<br/>Successfully dumped " . $db . " to " . $filename;
        echo "<br/>Size of SQL dump: " . sprintf("%.2f", $size) . " MB";
    }
    return true;
}
Пример #26
0
 /**
  * Helper function used by getExplain to run the EXPLAIN query for the current query
  *
  * @param	string	The current SQL query
  *
  * @return	string	The formatted output for the EXPLAIN information for the query
  */
 protected function runExplainQuery($sql)
 {
     if (!$this->doExplain) {
         return;
     }
     $results = $this->functions['query']($this->connection_recent, 'EXPLAIN ' . $sql);
     $output = '<table width="100%" cellpadding="2" cellspacing="1"><tr>';
     while ($field = $this->functions['fetch_field']($results)) {
         $output .= '<th>' . $field->name . '</th>';
     }
     $output .= '</tr>';
     $numfields = mysqli_field_count($this->connection_recent);
     // $this->functions['num_fields']
     while ($result = $this->fetch_row($results)) {
         $output .= '<tr>';
         for ($i = 0; $i < $numfields; $i++) {
             $output .= "<td>" . ($result["{$i}"] == '' ? '&nbsp;' : $result["{$i}"]) . "</td>";
         }
         $output .= '</tr>';
     }
     $output .= '</table>';
     return $output;
 }
<?php

require_once "connect.inc";
$tmp = NULL;
$link = NULL;
if (!is_null($tmp = @mysqli_field_count())) {
    printf("[001] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
}
if (!is_null($tmp = @mysqli_field_count($link))) {
    printf("[002] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
}
require 'table.inc';
var_dump(mysqli_field_count($link));
if (!($res = mysqli_query($link, "SELECT * FROM test ORDER BY id LIMIT 1"))) {
    printf("[004] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
}
var_dump(mysqli_field_count($link));
mysqli_free_result($res);
if (!mysqli_query($link, "INSERT INTO test(id, label) VALUES (100, 'x')")) {
    printf("[005] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
}
var_dump($link->field_count);
var_dump(mysqli_field_count($link));
if (!($res = mysqli_query($link, "SELECT NULL as _null, '' AS '', 'three' AS 'drei'"))) {
    printf("[006] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
}
var_dump(mysqli_field_count($link));
mysqli_free_result($res);
mysqli_close($link);
var_dump(mysqli_field_count($link));
print "done!";
Пример #28
0
 /**
  * db_num_fields returns the number of columns for the most recent query.
  *
  * @return integer  Returns the number of fields in a result set.
  * @access public
  */
 function db_num_fields()
 {
     $connection = $this->connection;
     return mysqli_field_count($connection);
 }
Пример #29
0
<?php

require_once "connect.inc";
/*** test mysqli_connect 127.0.0.1 ***/
$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket);
mysqli_select_db($link, $db);
mysqli_query($link, "DROP TABLE IF EXISTS test_037_table_1");
mysqli_query($link, "CREATE TABLE test_037_table_1 (a int, b varchar(10)) ENGINE = " . $engine);
mysqli_query($link, "INSERT INTO test_037_table_1 VALUES (1, 'foo')");
$ir[] = mysqli_field_count($link);
mysqli_real_query($link, "SELECT * FROM test_037_table_1");
$ir[] = mysqli_field_count($link);
var_dump($ir);
mysqli_query($link, "DROP TABLE IF EXISTS test_037_table_1");
mysqli_close($link);
print "done!";
require_once "connect.inc";
if (!($link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))) {
    printf("[c001] [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
}
if (!mysqli_query($link, "DROP TABLE IF EXISTS test_037_table_1")) {
    printf("[c002] Cannot drop table, [%d] %s\n", mysqli_errno($link), mysqli_error($link));
}
mysqli_close($link);
function db_numfields($lhandle) {
	global $conn;
	return @mysqli_field_count($conn);
}