Example #1
0
 public static function cast_query_results($rs)
 {
     $fields = mysqli_fetch_fields($rs);
     $data = array();
     $types = array();
     foreach ($fields as $field) {
         switch ($field->type) {
             case 1:
                 $types[$field->name] = 'boolean';
                 break;
             case 3:
                 $types[$field->name] = 'int';
                 break;
             case 4:
                 $types[$field->name] = 'float';
                 break;
             default:
                 $types[$field->name] = 'string';
                 break;
         }
     }
     while ($row = mysqli_fetch_assoc($rs)) {
         $data[] = $row;
     }
     for ($i = 0; $i < count($data); $i++) {
         foreach ($types as $name => $type) {
             settype($data[$i][$name], $type);
         }
     }
     return $data;
 }
 function fetch_next($class = null)
 {
     $fetch = $this->fetch_type;
     $result = $this->result;
     switch ($fetch) {
         case MySqliResult::$FETCH_OBJECT:
             if ($class != null) {
                 $row = $result->fetch_object($class, null);
             } else {
                 $row = $result->fetch_object();
             }
             //mysqli_fetch_object($result);
             break;
         case MySqliResult::$FETCH_ARRAY:
             $row = mysqli_fetch_array($result);
             break;
         case MySqliResult::$FETCH_FIELDS:
             $row = mysqli_fetch_fields($result);
             break;
         case MySqliResult::$FETCH_LENGTHS:
             $row = mysqli_fetch_fields($result);
             break;
         case MySqliResult::$FETCH_ROW:
             $row = mysqli_fetch_row($result);
             break;
         case MySqliResult::$FETCH_ASSOC:
             $row = mysqli_fetch_assoc($result);
             break;
     }
     return $row;
 }
Example #3
0
function mysql_query_cache($sql, $linkIdentifier = false, $timeout = 4)
{
    $mysqli = $GLOBALS['mysqli'];
    //首先调用上面的getCache函数,如果返回值不为false的话,就说明是从memcached服务器获取的数据
    //如果返回false,此时就需要直接从数据库中获取数据了。
    //需要注意的是这里使用操作的命令加上sql语句的md5码作为一个特定的key,可能大家觉得使用数据项的
    //名称作为key会比较自然一点。运行memcached加上"-vv"参数,并且不作为daemon运行的话,可以看见
    //memcached处理时输出的相关信息
    if (!($cache = getCache(md5("mysql_query" . $sql)))) {
        $cache = false;
        $r = mysqli_query($mysqli, $sql);
        $fields = mysqli_fetch_fields($r);
        //读取数据库,并将结果放入$cache数组中
        for ($i = 0; $row = mysqli_fetch_array($r); $i++) {
            $j = 0;
            foreach ($fields as $val) {
                $cache[$i][$val->name] = $row[$j];
                $j++;
            }
        }
        //将数据放入memcached服务器中,如果memcached服务器没有开的话,此语句什么也不会做
        //如果开启了服务器的话,数据将会被缓存到memcached服务器中
        if (!setCache(md5("mysql_query" . $sql), $cache, $timeout)) {
            # If we get here, there isn’t a memcache daemon running or responding
            echo "apt-get install memcached";
        }
    }
    return $cache;
}
Example #4
0
 public function display_data_in_table($sql)
 {
     $this->last_query = $sql;
     $result = mysqli_query($this->db, $sql);
     if (mysqli_num_rows($result) > 0) {
         $finfo = mysqli_fetch_fields($result);
         echo "<table class='table'>";
         echo "<tr>";
         foreach ($finfo as $val) {
             echo "<td>";
             $self = $_SERVER['PHP_SELF'];
             echo "<b>" . $val->name . "<b></a>";
             echo "</td>";
         }
         echo "<td><b>custom</b></td>";
         echo "</tr>";
         while ($row = mysqli_fetch_array($result)) {
             echo "<tr>";
             for ($x = 0; $x < count($finfo); $x++) {
                 echo "<td>";
                 echo $row[$x];
                 echo "</td>";
             }
             echo "<td><a href='#'><button>custom</button></a></td>";
             echo "</tr>";
         }
         // end of while
         echo "</table>";
         // echo "<input type='submit' value='delete'>";
         echo "</form>";
     } else {
         echo "0 results";
     }
 }
Example #5
0
 /**
  * 获取结果集
  **/
 public function fetch($rs, $fetchMode = self::DB_FETCH_DEFAULT)
 {
     $fields = mysqli_fetch_fields($rs);
     $values = mysqli_fetch_array($rs, $fetchMode);
     if ($values) {
         foreach ($fields as $field) {
             switch ($field->type) {
                 case MYSQLI_TYPE_TINY:
                 case MYSQLI_TYPE_SHORT:
                 case MYSQLI_TYPE_INT24:
                 case MYSQLI_TYPE_LONG:
                     if ($field->type == MYSQLI_TYPE_TINY && $field->length == 1) {
                         $values[$field->name] = (bool) $values[$field->name];
                     } else {
                         $values[$field->name] = (int) $values[$field->name];
                     }
                     break;
                 case MYSQLI_TYPE_DECLIMAL:
                 case MYSQLI_TYPE_FLOAT:
                 case MYSQLI_TYPE_DOUBLE:
                 case MYSQLI_TYPE_LONGLONG:
                     $values[$field->name] = (double) $values[$field->name];
                     break;
             }
         }
     }
     return $values;
 }
Example #6
0
 /**
  * Field data
  *
  * Generates an array of objects containing field meta-data
  *
  * @access	public
  * @return	array
  */
 function field_data()
 {
     $retval = array();
     $field_data = mysqli_fetch_fields($this->result_id);
     for ($i = 0, $c = count($field_data); $i < $c; $i++) {
         $retval[$i] = new stdClass();
         $retval[$i]->name = $field_data[$i]->name;
         $retval[$i]->type = $field_data[$i]->type;
         $retval[$i]->max_length = $field_data[$i]->max_length;
         $retval[$i]->primary_key = (int) ($field_data[$i]->flags & 2);
         $retval[$i]->default = '';
     }
     /** Fixed from github commit. See https://github.com/EllisLab/CodeIgniter/commit/effd0133b3fa805e21ec934196e8e7d75608ba00
     		while ($field = mysqli_fetch_object($this->result_id))
     		{
     			preg_match('/([a-zA-Z]+)(\(\d+\))?/', $field->Type, $matches);
     
     			$type = (array_key_exists(1, $matches)) ? $matches[1] : NULL;
     			$length = (array_key_exists(2, $matches)) ? preg_replace('/[^\d]/', '', $matches[2]) : NULL;
     
     			$F				= new stdClass();
     			$F->name		= $field->Field;
     			$F->type		= $type;
     			$F->default		= $field->Default;
     			$F->max_length	= $length;
     			$F->primary_key = ( $field->Key == 'PRI' ? 1 : 0 );
     
     			$retval[] = $F;
     		}
     **/
     return $retval;
 }
Example #7
0
/**
 * Fonction basée sur l'api mysqli et
 * simulant la fonction mysql_result()
 * Copyright 2014 Marc Leygnac
 *
 * @param type $result résultat après requête
 * @param integer $row numéro de la ligne
 * @param string/integer $field indice ou nom du champ
 * @return type valeur du champ ou false si erreur
 */
function old_mysql_result($result, $row, $field = 0)
{
    if ($result === false) {
        return false;
    }
    if ($row >= mysqli_num_rows($result)) {
        return false;
    }
    if (is_string($field) && !(strpos($field, ".") === false)) {
        // si $field est de la forme table.field ou alias.field
        // on convertit $field en indice numérique
        $t_field = explode(".", $field);
        $field = -1;
        $t_fields = mysqli_fetch_fields($result);
        for ($id = 0; $id < mysqli_num_fields($result); $id++) {
            if ($t_fields[$id]->table == $t_field[0] && $t_fields[$id]->name == $t_field[1]) {
                $field = $id;
                break;
            }
        }
        if ($field == -1) {
            return false;
        }
    }
    mysqli_data_seek($result, $row);
    $line = mysqli_fetch_array($result);
    return isset($line[$field]) ? $line[$field] : false;
}
Example #8
0
 /**
  * Return rows of field information in a result set. This function is a
  * basically a wrapper on the native mysqli_fetch_fields function.
  *
  * @param bool $as_array Return each field info as array; defaults to false
  *
  * @return array Array of field information each as an associative array
  */
 public function fetch_fields($as_array = false)
 {
     if ($as_array) {
         return array_map(function ($object) {
             return (array) $object;
         }, mysqli_fetch_fields($this->result));
     } else {
         return mysqli_fetch_fields($this->result);
     }
 }
Example #9
0
 public function getResgitro($rsQuery, $iLinha)
 {
     $oStdClas = new stdClass();
     $aResult = mysqli_fetch_row($rsQuery);
     if ($aResult != null) {
         $aCampos = mysqli_fetch_fields($rsQuery);
         foreach ($aCampos as $iCampo => $aCampo) {
             $oStdClas->{$aCampo->name} = $aResult[$iCampo];
         }
     }
     return $oStdClas;
 }
function func_mysqli_fetch_array($mysqli, $engine, $sql_type, $sql_value, $php_value, $offset, $regexp_comparison = NULL)
{
    if (!$mysqli->query("DROP TABLE IF EXISTS test")) {
        printf("[%04d] [%d] %s\n", $offset, $mysqli->errno, $mysqli->error);
        return false;
    }
    if (!$mysqli->query($sql = sprintf("CREATE TABLE test(id INT NOT NULL, label %s, PRIMARY KEY(id)) ENGINE = %s", $sql_type, $engine))) {
        // don't bail, engine might not support the datatype
        return false;
    }
    if (is_null($php_value)) {
        if (!$mysqli->query($sql = sprintf("INSERT INTO test(id, label) VALUES (1, NULL)"))) {
            printf("[%04d] [%d] %s\n", $offset + 1, $mysqli->errno, $mysqli->error);
            return false;
        }
    } else {
        if (is_string($sql_value)) {
            if (!$mysqli->query($sql = "INSERT INTO test(id, label) VALUES (1, '" . $sql_value . "')")) {
                printf("[%04ds] [%d] %s - %s\n", $offset + 1, $mysqli->errno, $mysqli->error, $sql);
                return false;
            }
        } else {
            if (!$mysqli->query($sql = sprintf("INSERT INTO test(id, label) VALUES (1, '%d')", $sql_value))) {
                printf("[%04di] [%d] %s\n", $offset + 1, $mysqli->errno, $mysqli->error);
                return false;
            }
        }
    }
    if (!($res = $mysqli->query("SELECT id, label FROM test"))) {
        printf("[%04d] [%d] %s\n", $offset + 2, $mysqli->errno, $mysqli->error);
        return false;
    }
    if (!($row = $res->fetch_array(MYSQLI_BOTH))) {
        printf("[%04d] [%d] %s\n", $offset + 3, $mysqli->errno, $mysqli->error);
        return false;
    }
    $fields = mysqli_fetch_fields($res);
    if (!(gettype($php_value) == "unicode" && $fields[1]->flags & 128)) {
        if ($regexp_comparison) {
            if (!preg_match($regexp_comparison, (string) $row['label']) || !preg_match($regexp_comparison, (string) $row[1])) {
                printf("[%04d] Expecting %s/%s [reg exp = %s], got %s/%s resp. %s/%s. [%d] %s\n", $offset + 4, gettype($php_value), $php_value, $regexp_comparison, gettype($row[1]), $row[1], gettype($row['label']), $row['label'], $mysqli->errno, $mysqli->error);
                return false;
            }
        } else {
            if ($row['label'] !== $php_value || $row[1] != $php_value) {
                printf("[%04d] Expecting %s/%s, got %s/%s resp. %s/%s. [%d] %s\n", $offset + 4, gettype($php_value), $php_value, gettype($row[1]), $row[1], gettype($row['label']), $row['label'], $mysqli->errno, $mysqli->error);
                return false;
            }
        }
    }
    return true;
}
Example #11
0
 protected function _performGetBlobFieldNames($result)
 {
     $allFields = mysqli_fetch_fields($result);
     $blobFields = array();
     if (!empty($allFields)) {
         foreach ($allFields as $field) {
             if (stripos($field["type"], "BLOB") !== false) {
                 $blobFields[] = $field["name"];
             }
         }
     }
     return $blobFields;
 }
Example #12
0
 public function __construct($qvar)
 {
     //constructor takes query string as a parameter
     include "/home/ubuntu/workspace/db_connect.php";
     //contains $conn - Oracle connection info
     $this->qvar = $qvar;
     $sql = $mysqli->query($this->qvar);
     $this->numcols = mysqli_num_fields($sql);
     $this->colname = mysqli_fetch_fields($sql);
     $this->numrows = mysqli_num_rows($sql);
     while ($row = mysqli_fetch_assoc($sql)) {
         $this->tableArray[] = $row;
     }
     $sql->close();
 }
function zerofill($offset, $link, $datatype, $insert = 1)
{
    mysqli_query($link, 'ALTER TABLE test_mysqli_stmt_bind_result_zerofill_table_1 DROP zero');
    $sql = sprintf('ALTER TABLE test_mysqli_stmt_bind_result_zerofill_table_1 ADD zero %s UNSIGNED ZEROFILL', $datatype);
    if (!mysqli_query($link, $sql)) {
        // no worries - server might not support it
        return true;
    }
    if (!mysqli_query($link, sprintf('UPDATE test_mysqli_stmt_bind_result_zerofill_table_1 SET zero = %s', $insert))) {
        printf("[%03d] UPDATE failed, [%d] %s\n", $offset, mysqli_errno($link), mysqli_error($link));
        return false;
    }
    if (!($stmt = mysqli_prepare($link, 'SELECT zero FROM test_mysqli_stmt_bind_result_zerofill_table_1 LIMIT 1'))) {
        printf("[%03d] SELECT failed, [%d] %s\n", $offset, mysqli_errno($link), mysqli_error($link));
        return false;
    }
    $result = null;
    if (!mysqli_stmt_bind_result($stmt, $result)) {
        printf("[%03d] Bind failed, [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
        return false;
    }
    if (!mysqli_stmt_execute($stmt) || !mysqli_stmt_fetch($stmt)) {
        printf("[%03d] Execute or fetch failed, [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
        return false;
    }
    $res = mysqli_stmt_result_metadata($stmt);
    $meta = mysqli_fetch_fields($res);
    mysqli_stmt_free_result($stmt);
    $meta = $meta[0];
    $length = $meta->length;
    if ($length > strlen($insert)) {
        $expected = str_repeat('0', $length - strlen($insert));
        $expected .= $insert;
        if ($expected !== $result) {
            printf("[%03d] Expecting '%s' got '%s'\n", $offset, $expected, $result);
            return false;
        }
    } else {
        if ($length <= 1) {
            printf("[%03d] Length reported is too small to run test\n", $offset);
            return false;
        }
    }
    return true;
}
 protected function attributes()
 {
     // return an array of attribute keys and there values
     global $database;
     //$row_result = $database->query("select * from ". static::$table_name. " where id=1 limit 1");
     $row_result = $database->query("select * from " . static::$table_name . " limit 1");
     $finfo = mysqli_fetch_fields($row_result);
     //echo "attributes are: ". print_r($finfo);
     $attribute = array();
     foreach ($finfo as $val) {
         $name = $val->name;
         if (property_exists($this, $name)) {
             $attribute["{$name}"] = $this->{$name};
             //"'$"."{$name}'";
         }
     }
     mysqli_free_result($row_result);
     return $attribute;
 }
Example #15
0
function build_cbm_tables()
{
    $tables = array();
    $mysqli = mysqli_connect("localhost", "root", "", "cbm");
    /* check connection */
    if (mysqli_connect_errno()) {
        printf("Connect failed: %s\r\n", mysqli_connect_error());
        exit;
    }
    //查找所有的表名
    $result = $mysqli->query("show tables");
    //执行查询语句
    while ($arr = $result->fetch_assoc()) {
        $tbl = $arr["Tables_in_cbm"];
        //遍历查询结果
        if ($tbl == 'cbm_dummy') {
            continue;
        }
        $tables[$tbl] = array();
    }
    //查找表中的所有字段
    foreach (array_keys($tables) as $tbl) {
        $query = "SELECT * from {$tbl}";
        if ($result = mysqli_query($mysqli, $query)) {
            /* Get field information for all columns */
            $finfo = mysqli_fetch_fields($result);
            $fields = array();
            foreach ($finfo as $val) {
                //类型编号映射成c++数据类型
                // var_dump($tbl.'----'.h_type2txt($val->type));
                $fields[$val->name] = MYSQL_type_to_cpp_type(h_type2txt($val->type));
            }
            $tables[$tbl] = $fields;
            mysqli_free_result($result);
        }
    }
    /* close connection */
    mysqli_close($mysqli);
    return $tables;
}
 function consulta_tabela()
 {
     $this->consulta_campos();
     echo "<table border='1'>\n";
     echo "<tr>\n";
     foreach (mysqli_fetch_fields($this->dados) as $campo) {
         echo "<td>";
         echo $campo->name;
         echo "</td>\n";
     }
     echo "</tr>\n";
     while ($reg = mysqli_fetch_assoc($this->dados)) {
         echo "<tr>\n";
         for ($i = 0; $i < $this->campos_num; $i++) {
             echo "<td>";
             echo $reg[$this->campos_nome[$i]];
             echo "</td>\n";
         }
         echo "</tr>\n";
     }
     echo "</table>\n";
 }
Example #17
0
 public function nextr($result)
 {
     if ($this->mnd) {
         return $result->fetch_array(MYSQL_BOTH);
     }
     $ref = $result->result_metadata();
     if (!$ref) {
         return false;
     }
     $tmp = mysqli_fetch_fields($ref);
     if (!$tmp) {
         return false;
     }
     $ref = [];
     foreach ($tmp as $col) {
         $ref[] = [$col->name, null];
     }
     $tmp = [];
     foreach ($ref as $k => $v) {
         $tmp[] =& $ref[$k][1];
     }
     try {
         if (!call_user_func_array(array($result, 'bind_result'), $tmp)) {
             return false;
         }
     } catch (\Exception $e) {
     }
     if (!$result->fetch()) {
         return false;
     }
     $tmp = [];
     $i = 0;
     foreach ($ref as $k => $v) {
         $tmp[$i++] = $v[1];
         $tmp[$v[0]] = $v[1];
     }
     return $tmp;
 }
function zerofill($offset, $link, $datatype, $insert = 1)
{
    mysqli_query($link, 'ALTER TABLE test DROP zero');
    $sql = sprintf('ALTER TABLE test ADD zero %s UNSIGNED ZEROFILL', $datatype);
    if (!mysqli_query($link, $sql)) {
        // no worries - server might not support it
        return true;
    }
    if (!mysqli_query($link, sprintf('UPDATE test SET zero = %s', $insert))) {
        printf("[%03d] UPDATE failed, [%d] %s\n", $offset, mysqli_errno($link), mysqli_error($link));
        return false;
    }
    if (!($res = mysqli_query($link, 'SELECT zero FROM test LIMIT 1'))) {
        printf("[%03d] SELECT failed, [%d] %s\n", $offset, mysqli_errno($link), mysqli_error($link));
        return false;
    }
    $row = mysqli_fetch_assoc($res);
    $meta = mysqli_fetch_fields($res);
    mysqli_free_result($res);
    $meta = $meta[0];
    $length = $meta->length;
    if ($length > strlen($insert)) {
        $expected = str_repeat('0', $length - strlen($insert));
        $expected .= $insert;
        if ($expected !== $row['zero']) {
            printf("[%03d] Expecting '%s' got '%s'\n", $offset, $expected, $row['zero']);
            return false;
        }
    } else {
        if ($length <= 1) {
            printf("[%03d] Length reported is too small to run test\n", $offset);
            return false;
        }
    }
    return true;
}
Example #19
0
/**
 * fGetCamposTabla
 * Función que devuelve un array con el nombre de los campos de tipo texto
 * de la base de datos...
 * Los campos de tipo texto son VARCHAR (253) y CHAR (254)
 *
 * @param string $tabla El nombre de la tabla
 * @return array
 **/
function fGetCamposTabla($tabla)
{
    // PRIMERO nos conectamos a la base de datos
    $conexion = Conectar();
    // Construimos la cadena SQL para seleccionar
    $sql = 'SELECT * FROM ' . $tabla;
    // Array para almacenar los resultados de la consulta de selección...
    $campos = array();
    // Ejecutamos la consulta de selección
    $resultado = mysqli_query($conexion, $sql);
    // Obtener la información del campo para todas las columnas
    $info_campo = mysqli_fetch_fields($resultado);
    foreach ($info_campo as $valor) {
        if ($valor->type == 253 || $valor->type == 254) {
            $campos[] = $valor->name;
        }
    }
    // Liberamos los resultados de la conexión
    Liberar($resultado);
    // Nos desconectamos de la base de datos
    Desconectar($conexion);
    // Devolvemos el resultado de la consulta
    return $campos;
}
function func_mysqli_stmt_get_result_geom($link, $engine, $sql_type, $bind_value, $offset)
{
    if (!mysqli_query($link, "DROP TABLE IF EXISTS test_mysqli_stmt_get_result_geom_table_1")) {
        printf("[%04d] [%d] %s\n", $offset, mysqli_errno($link), mysqli_error($link));
        return false;
    }
    if (!mysqli_query($link, sprintf("CREATE TABLE test_mysqli_stmt_get_result_geom_table_1(id INT, label %s, PRIMARY KEY(id)) ENGINE = %s", $sql_type, $engine))) {
        // don't bail - column type might not be supported by the server, ignore this
        return false;
    }
    for ($id = 1; $id < 4; $id++) {
        $sql = sprintf("INSERT INTO test_mysqli_stmt_get_result_geom_table_1(id, label) VALUES (%d, %s)", $id, $bind_value);
        if (!mysqli_query($link, $sql)) {
            printf("[%04d] [%d] %s\n", $offset + 2 + $id, mysqli_errno($link), mysqli_error($link));
        }
    }
    if (!($stmt = mysqli_stmt_init($link))) {
        printf("[%04d] [%d] %s\n", $offset + 6, mysqli_errno($link), mysqli_error($link));
        return false;
    }
    if (!mysqli_stmt_prepare($stmt, "SELECT id, label FROM test_mysqli_stmt_get_result_geom_table_1")) {
        printf("[%04d] [%d] %s\n", $offset + 7, mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
        mysqli_stmt_close($stmt);
        return false;
    }
    if (!mysqli_stmt_execute($stmt)) {
        printf("[%04d] [%d] %s\n", $offset + 8, mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
        mysqli_stmt_close($stmt);
        return false;
    }
    if (!($res = mysqli_stmt_get_result($stmt))) {
        printf("[%04d] [%d] %s\n", $offset + 9, mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
        mysqli_stmt_close($stmt);
        return false;
    }
    $result = mysqli_stmt_result_metadata($stmt);
    $fields = mysqli_fetch_fields($result);
    if ($fields[1]->type != MYSQLI_TYPE_GEOMETRY) {
        printf("[%04d] [%d] %s wrong type %d\n", $offset + 10, mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt), $fields[1]->type);
    }
    $num = 0;
    while ($row = mysqli_fetch_assoc($res)) {
        $bind_res =& $row['label'];
        if (!($stmt2 = mysqli_stmt_init($link))) {
            printf("[%04d] [%d] %s\n", $offset + 11, mysqli_errno($link), mysqli_error($link));
            return false;
        }
        if (!mysqli_stmt_prepare($stmt2, "INSERT INTO test_mysqli_stmt_get_result_geom_table_1(id, label) VALUES (?, ?)")) {
            printf("[%04d] [%d] %s\n", $offset + 12, mysqli_stmt_errno($stmt2), mysqli_stmt_error($stmt2));
            return false;
        }
        $id = $row['id'] + 10;
        if (!mysqli_stmt_bind_param($stmt2, "is", $id, $bind_res)) {
            printf("[%04d] [%d] %s\n", $offset + 13, mysqli_stmt_errno($stmt2), mysqli_stmt_error($stmt2));
            return false;
        }
        if (!mysqli_stmt_execute($stmt2)) {
            printf("[%04d] [%d] %s\n", $offset + 14, mysqli_stmt_errno($stmt2), mysqli_stmt_error($stmt2));
            return false;
        }
        mysqli_stmt_close($stmt2);
        if (!($res_normal = mysqli_query($link, sprintf("SELECT id, label FROM test_mysqli_stmt_get_result_geom_table_1 WHERE id = %d", $row['id'] + 10)))) {
            printf("[%04d] [%d] %s\n", $offset + 15, mysqli_errno($link), mysqli_error($link));
            return false;
        }
        if (!($row_normal = mysqli_fetch_assoc($res_normal))) {
            printf("[%04d] [%d] %s\n", $offset + 16, mysqli_errno($link), mysqli_error($link));
            return false;
        }
        if ($row_normal['label'] != $bind_res) {
            printf("[%04d] PS and non-PS return different data.\n", $offset + 17);
            return false;
        }
        mysqli_free_result($res_normal);
        $num++;
    }
    if ($num != 3) {
        printf("[%04d] [%d] %s, expecting 3 results, got only %d results\n", $offset + 18, mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt), $num);
        mysqli_free_result($res);
        mysqli_stmt_close($stmt);
        return false;
    }
    mysqli_free_result($res);
    mysqli_stmt_close($stmt);
    return true;
}
<?php

//__variables__
$pagename = 'Mieterliste';
$tablename = 'Mieter';
//__generic query__
include 'db_Cando.inc.php';
$sql = "SELECT * FROM {$tablename}";
$result = $conn->query($sql);
//__display__
echo "<article>";
echo "<h1>" . $pagename . "</h1>";
echo "<table border=\"1\">";
/* Headers - dynamisch ausgeben */
$fields = mysqli_fetch_fields($result);
$headers = array();
foreach ($fields as $field) {
    $headers[] = $field->name;
    echo "<th>" . $field->name . "</th>\n";
}
echo "</tr>\n";
/* Row - dynamisch ausgeben */
if ($result->num_rows > 0) {
    while ($row = $result->fetch_assoc()) {
        echo "<tr>";
        for ($i = 0; $i < sizeof($headers); $i++) {
            echo "<td>" . $row["{$headers[$i]}"] . "</td>";
        }
        echo "</tr>";
    }
} else {
Example #22
0
 protected function fetch_fields($result)
 {
     return mysqli_fetch_fields($result);
 }
Example #23
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_047_table_1");
mysqli_query($link, "CREATE TABLE test_047_table_1 (foo int, bar varchar(10) character set latin1) ENGINE=" . $engine);
mysqli_query($link, "INSERT INTO test_047_table_1 VALUES (1, 'Zak'),(2, 'Greant')");
$stmt = mysqli_prepare($link, "SELECT * FROM test_047_table_1");
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_result_metadata($stmt);
echo "\n=== fetch_fields ===\n";
var_dump(mysqli_fetch_fields($result));
echo "\n=== fetch_field_direct ===\n";
var_dump(mysqli_fetch_field_direct($result, 0));
var_dump(mysqli_fetch_field_direct($result, 1));
echo "\n=== fetch_field ===\n";
while ($field = mysqli_fetch_field($result)) {
    var_dump($field);
}
print_r(mysqli_fetch_lengths($result));
mysqli_free_result($result);
mysqli_stmt_close($stmt);
mysqli_query($link, "DROP TABLE IF EXISTS test_047_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());
}
Example #24
0
 /**
  * returns metainfo for fields in $result
  *
  * @param mysqli_result $result result set identifier
  *
  * @return array meta info for fields in $result
  */
 public function getFieldsMeta($result)
 {
     // Build an associative array for a type look up
     $typeAr = array();
     $typeAr[MYSQLI_TYPE_DECIMAL] = 'real';
     $typeAr[MYSQLI_TYPE_NEWDECIMAL] = 'real';
     $typeAr[MYSQLI_TYPE_BIT] = 'int';
     $typeAr[MYSQLI_TYPE_TINY] = 'int';
     $typeAr[MYSQLI_TYPE_SHORT] = 'int';
     $typeAr[MYSQLI_TYPE_LONG] = 'int';
     $typeAr[MYSQLI_TYPE_FLOAT] = 'real';
     $typeAr[MYSQLI_TYPE_DOUBLE] = 'real';
     $typeAr[MYSQLI_TYPE_NULL] = 'null';
     $typeAr[MYSQLI_TYPE_TIMESTAMP] = 'timestamp';
     $typeAr[MYSQLI_TYPE_LONGLONG] = 'int';
     $typeAr[MYSQLI_TYPE_INT24] = 'int';
     $typeAr[MYSQLI_TYPE_DATE] = 'date';
     $typeAr[MYSQLI_TYPE_TIME] = 'time';
     $typeAr[MYSQLI_TYPE_DATETIME] = 'datetime';
     $typeAr[MYSQLI_TYPE_YEAR] = 'year';
     $typeAr[MYSQLI_TYPE_NEWDATE] = 'date';
     $typeAr[MYSQLI_TYPE_ENUM] = 'unknown';
     $typeAr[MYSQLI_TYPE_SET] = 'unknown';
     $typeAr[MYSQLI_TYPE_TINY_BLOB] = 'blob';
     $typeAr[MYSQLI_TYPE_MEDIUM_BLOB] = 'blob';
     $typeAr[MYSQLI_TYPE_LONG_BLOB] = 'blob';
     $typeAr[MYSQLI_TYPE_BLOB] = 'blob';
     $typeAr[MYSQLI_TYPE_VAR_STRING] = 'string';
     $typeAr[MYSQLI_TYPE_STRING] = 'string';
     // MySQL returns MYSQLI_TYPE_STRING for CHAR
     // and MYSQLI_TYPE_CHAR === MYSQLI_TYPE_TINY
     // so this would override TINYINT and mark all TINYINT as string
     // https://sourceforge.net/p/phpmyadmin/bugs/2205/
     //$typeAr[MYSQLI_TYPE_CHAR]        = 'string';
     $typeAr[MYSQLI_TYPE_GEOMETRY] = 'geometry';
     $typeAr[MYSQLI_TYPE_BIT] = 'bit';
     if (defined('MYSQLI_TYPE_JSON')) {
         $typeAr[MYSQLI_TYPE_JSON] = 'json';
     }
     $fields = mysqli_fetch_fields($result);
     // this happens sometimes (seen under MySQL 4.0.25)
     if (!is_array($fields)) {
         return false;
     }
     foreach ($fields as $k => $field) {
         $fields[$k]->_type = $field->type;
         $fields[$k]->type = $typeAr[$field->type];
         $fields[$k]->_flags = $field->flags;
         $fields[$k]->flags = $this->fieldFlags($result, $k);
         // Enhance the field objects for mysql-extension compatibility
         //$flags = explode(' ', $fields[$k]->flags);
         //array_unshift($flags, 'dummy');
         $fields[$k]->multiple_key = (int) (bool) ($fields[$k]->_flags & MYSQLI_MULTIPLE_KEY_FLAG);
         $fields[$k]->primary_key = (int) (bool) ($fields[$k]->_flags & MYSQLI_PRI_KEY_FLAG);
         $fields[$k]->unique_key = (int) (bool) ($fields[$k]->_flags & MYSQLI_UNIQUE_KEY_FLAG);
         $fields[$k]->not_null = (int) (bool) ($fields[$k]->_flags & MYSQLI_NOT_NULL_FLAG);
         $fields[$k]->unsigned = (int) (bool) ($fields[$k]->_flags & MYSQLI_UNSIGNED_FLAG);
         $fields[$k]->zerofill = (int) (bool) ($fields[$k]->_flags & MYSQLI_ZEROFILL_FLAG);
         $fields[$k]->numeric = (int) (bool) ($fields[$k]->_flags & MYSQLI_NUM_FLAG);
         $fields[$k]->blob = (int) (bool) ($fields[$k]->_flags & MYSQLI_BLOB_FLAG);
     }
     return $fields;
 }
   
<?php 
if ($action == "depto") {
    $resultado = "select  " . $consulta . " from tipo_bienes,\n\t\t\t\t\t\tunidades,descripciones,departamentos, ingresos,equipos,bienes,traslados where ingresos.id_table_equipo=equipos.id_table_equipo and \n\t\t\t\t\t\tdescripciones.id_table_equipo=equipos.id_table_equipo and equipos.id_bien=bienes.id_bien and \n\t\t\t\t\t\tunidades.id_table_unidad=equipos.id_table_unidad and tipo_bienes.id_tipo_bien=equipos.id_tipo_bien \n\t\t\t\t\t\tand unidades.id_table_unidad=equipos.id_table_unidad and departamentos.id_table_depto=unidades.id_table_depto\n\t\t\t\t\t\t and " . $depto_unidad . " and bienes.nombre like '%{$bien}%' and STR_TO_DATE(substring(ingresos.fecha_adquisicion,1,10),'%d/%m/%Y') between STR_TO_DATE('{$fecha_one}','%d/%m/%Y') \n\t\t\t\t\t\t and STR_TO_DATE('{$fecha_two}','%d/%m/%Y') and bienes.nombre like '%{$bien}%' and traslados.id_table_equipo=equipos.id_table_equipo order by equipos.id_equipo";
} else {
    if ($action == "unidad") {
        $resultado = "select  " . $consulta . " from traslados, tipo_bienes,\n\t\t\t\t\t\tunidades,descripciones, ingresos,equipos,bienes where ingresos.id_table_equipo=equipos.id_table_equipo and \n\t\t\t\t\t\tdescripciones.id_table_equipo=equipos.id_table_equipo and equipos.id_bien=bienes.id_bien and \n\t\t\t\t\t\tunidades.id_table_unidad=equipos.id_table_unidad and tipo_bienes.id_tipo_bien=equipos.id_tipo_bien \n\t\t\t\t\t\tand unidades.id_table_unidad=equipos.id_table_unidad \n\t\t\t\t\t\t and " . $depto_unidad . " and bienes.nombre like '%{$bien}%' and STR_TO_DATE(substring(ingresos.fecha_adquisicion,1,10),'%d/%m/%Y') between STR_TO_DATE('{$fecha_one}','%d/%m/%Y') \n\t\t\t\t\t\t and STR_TO_DATE('{$fecha_two}','%d/%m/%Y')  and traslados.id_table_equipo=equipos.id_table_equipo  and order by equipos.id_equipo";
    } else {
        if ($action == "all") {
            $resultado = "select  " . $consulta . " from traslados,tipo_bienes,\n\t\t\t\t\t\tunidades,descripciones, ingresos,equipos,bienes where ingresos.id_table_equipo=equipos.id_table_equipo and \n\t\t\t\t\t\tdescripciones.id_table_equipo=equipos.id_table_equipo and equipos.id_bien=bienes.id_bien and \n\t\t\t\t\t\tunidades.id_table_unidad=equipos.id_table_unidad and tipo_bienes.id_tipo_bien=equipos.id_tipo_bien \n\t\t\t\t\t\tand unidades.id_table_unidad=equipos.id_table_unidad \n\t\t\t\t\t\t and bienes.nombre like '%{$bien}%' and STR_TO_DATE(substring(ingresos.fecha_adquisicion,1,10),'%d/%m/%Y') between STR_TO_DATE('{$fecha_one}','%d/%m/%Y') \n\t\t\t\t\t\t and STR_TO_DATE('{$fecha_two}','%d/%m/%Y')  and traslados.id_table_equipo=equipos.id_table_equipo order by equipos.id_equipo";
        }
    }
}
if ($resultado2 = $link->query($resultado)) {
    if (($cant_row = $resultado2->num_rows) > 0) {
        $consulta2 = mysqli_fetch_fields($resultado2);
        $i = 1;
        $num_registro_page = 1;
        $dinero = 0;
        $page = 1;
        $new_page = 1;
        while ($row = $resultado2->fetch_assoc()) {
            if ($new_page == 1) {
                page_header();
                echo "<table><tr></tr><tr></tr></table>";
                echo "<table border='1' cellspacing='0' id='table_reporte'  style='margin:auto; text-align:center;'>";
                echo "<tr>";
                echo utf8_decode("<th>N°</th>");
                $th = 0;
                foreach ($consulta2 as $columna) {
                    $th++;
Example #26
0
function db_list_fields($result)
{
    if ($result instanceof mysqli_stmt) {
        $meta = mysqli_stmt_result_metadata($result);
        $fields = mysqli_fetch_fields($meta);
    } else {
        $fields = mysqli_fetch_fields($query);
    }
    return array_map(function ($field) {
        return $field->name;
    }, $fields);
}
Example #27
0
 function GetTableFields($table)
 {
     if (!isset($this->column_cache[$table])) {
         $this->column_cache[$table] = array();
         $this->DoConnect();
         $dbResult = $this->query("SELECT * FROM `" . $this->ForSql($table) . "` LIMIT 0");
         $resultFields = mysqli_fetch_fields($dbResult->result);
         foreach ($resultFields as $field) {
             switch ($field->type) {
                 case MYSQLI_TYPE_TINY:
                 case MYSQLI_TYPE_SHORT:
                 case MYSQLI_TYPE_LONG:
                 case MYSQLI_TYPE_INT24:
                 case MYSQLI_TYPE_CHAR:
                     $type = "int";
                     break;
                 case MYSQLI_TYPE_DECIMAL:
                 case MYSQLI_TYPE_NEWDECIMAL:
                 case MYSQLI_TYPE_FLOAT:
                 case MYSQLI_TYPE_DOUBLE:
                     $type = "real";
                     break;
                 case MYSQLI_TYPE_DATETIME:
                 case MYSQLI_TYPE_TIMESTAMP:
                     $type = "datetime";
                     break;
                 case MYSQLI_TYPE_DATE:
                 case MYSQLI_TYPE_NEWDATE:
                     $type = "date";
                     break;
                 default:
                     $type = "string";
                     break;
             }
             $this->column_cache[$table][$field->name] = array("NAME" => $field->name, "TYPE" => $type);
         }
     }
     return $this->column_cache[$table];
 }
Example #28
0
$q_body = "FROM \n   (SELECT Persons.id_person, id_person_combat_card,  name_person, name_group, \n           card_marshal, expire_marshal  \n    FROM Persons_CombatCards, Persons, Groups \n    WHERE Persons_CombatCards.id_person=Persons.id_person \n    AND Persons.id_group = Groups.id_group \n    AND Persons_CombatCards.expire_marshal >= curdate() \n    AND id_combat={$ic}) AS PCC\n           LEFT JOIN\n    (SELECT COUNT(*) as num_count, id_person \n    FROM Persons_Marshals, Marshals\n    WHERE Persons_Marshals.id_marshal=Marshals.id_marshal\n    AND Marshals.id_combat={$ic}\n    GROUP BY id_person) AS PCount\n    ON PCount.id_person = PCC.id_person ";
// Now we have to add the individual warrants
while ($warr = mysqli_fetch_assoc($warrs)) {
    extract($warr);
    $q_head = $q_head . ", if (PA{$id_marshal}.id_person IS NULL,'No', 'Yes') as '{$name_marshal}' ";
    $q_body = $q_body . "LEFT JOIN \n                   (SELECT id_person\n                    FROM Persons_Marshals\n                    WHERE Persons_Marshals.id_marshal={$id_marshal}) AS PA{$id_marshal}\n                    ON PA{$id_marshal}.id_person=PCC.id_person ";
}
$query = $qlink . $q_head . $q_body . "WHERE num_count is not NULL ORDER BY name_person";
if (DEBUG) {
    echo "Warrants Query is<p> {$query}";
}
// This part borrowed from report_showtable, minus ability to download file
$data = mysqli_query($cxn, $query) or die("Couldn't execute query to build table.");
// Displays a table with sortable columns based on the data stored in $data.
echo form_title("Active Marshals for {$name_combat}");
$fields = mysqli_fetch_fields($data);
//    echo "<table class='table table-condensed table-bordered'>";
echo '<table class="sortable table table-condensed table-bordered">';
echo '<thead>';
foreach ($fields as $field) {
    echo '<th>' . $field->name . '</th>';
}
echo '</thead>';
while ($row = mysqli_fetch_assoc($data)) {
    echo '<tr>';
    foreach ($row as $field) {
        echo '<td>' . $field . '</td>';
    }
    echo '</tr>';
}
echo '</table>';
function func_mysqli_stmt_get_result($link, $engine, $bind_type, $sql_type, $bind_value, $offset, $type_hint = null)
{
    if (!mysqli_query($link, "DROP TABLE IF EXISTS test_mysqli_stmt_get_result_types_table_1")) {
        printf("[%04d] [%d] %s\n", $offset, mysqli_errno($link), mysqli_error($link));
        return false;
    }
    if (!mysqli_query($link, sprintf("CREATE TABLE test_mysqli_stmt_get_result_types_table_1(id INT, label %s, PRIMARY KEY(id)) ENGINE = %s", $sql_type, $engine))) {
        // don't bail - column type might not be supported by the server, ignore this
        return false;
    }
    if (!($stmt = mysqli_stmt_init($link))) {
        printf("[%04d] [%d] %s\n", $offset + 1, mysqli_errno($link), mysqli_error($link));
        return false;
    }
    if (!mysqli_stmt_prepare($stmt, "INSERT INTO test_mysqli_stmt_get_result_types_table_1(id, label) VALUES (?, ?)")) {
        printf("[%04d] [%d] %s\n", $offset + 2, mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
        return false;
    }
    $id = null;
    if (!mysqli_stmt_bind_param($stmt, "i" . $bind_type, $id, $bind_value)) {
        printf("[%04d] [%d] %s\n", $offset + 3, mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
        mysqli_stmt_close($stmt);
        return false;
    }
    for ($id = 1; $id < 4; $id++) {
        if (!mysqli_stmt_execute($stmt)) {
            printf("[%04d] [%d] %s\n", $offset + 3 + $id, mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
            mysqli_stmt_close($stmt);
            return false;
        }
    }
    mysqli_stmt_close($stmt);
    $stmt = mysqli_stmt_init($link);
    if (!mysqli_stmt_prepare($stmt, "SELECT id, label FROM test_mysqli_stmt_get_result_types_table_1")) {
        printf("[%04d] [%d] %s\n", $offset + 7, mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
        mysqli_stmt_close($stmt);
        return false;
    }
    if (!mysqli_stmt_execute($stmt)) {
        printf("[%04d] [%d] %s\n", $offset + 8, mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
        mysqli_stmt_close($stmt);
        return false;
    }
    $result = mysqli_stmt_result_metadata($stmt);
    if (!($res = mysqli_stmt_get_result($stmt))) {
        printf("[%04d] [%d] %s\n", $offset + 9, mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
        mysqli_stmt_close($stmt);
        return false;
    }
    $num = 0;
    $fields = mysqli_fetch_fields($result);
    while ($row = mysqli_fetch_assoc($res)) {
        $bind_res =& $row['label'];
        if (!gettype($bind_res) == 'unicode') {
            if ($bind_res !== $bind_value && (!$type_hint || $type_hint !== gettype($bind_res))) {
                printf("[%04d] [%d] Expecting %s/'%s' [type hint = %s], got %s/'%s'\n", $offset + 10, $num, gettype($bind_value), $bind_value, $type_hint, gettype($bind_res), $bind_res);
                mysqli_free_result($res);
                mysqli_stmt_close($stmt);
                return false;
            }
        }
        $num++;
    }
    if ($num != 3) {
        printf("[%04d] [%d] %s, expecting 3 results, got only %d results\n", $offset + 11, mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt), $num);
        mysqli_free_result($res);
        mysqli_stmt_close($stmt);
        return false;
    }
    mysqli_free_result($res);
    mysqli_stmt_close($stmt);
    return true;
}
Example #30
0
 function write_data_mysqli($table_name)
 {
     global $db;
     $sql = "SELECT *\n\t\t\tFROM {$table_name}";
     $result = mysqli_query($db->db_connect_id, $sql, MYSQLI_USE_RESULT);
     if ($result != false) {
         $fields_cnt = mysqli_num_fields($result);
         // Get field information
         $field = mysqli_fetch_fields($result);
         $field_set = array();
         for ($j = 0; $j < $fields_cnt; $j++) {
             $field_set[] = $field[$j]->name;
         }
         $search = array("\\", "'", "", "\n", "\r", "", '"');
         $replace = array("\\\\", "\\'", '\\0', '\\n', '\\r', '\\Z', '\\"');
         $fields = implode(', ', $field_set);
         $sql_data = 'INSERT INTO ' . $table_name . ' (' . $fields . ') VALUES ';
         $first_set = true;
         $query_len = 0;
         $max_len = get_usable_memory();
         while ($row = mysqli_fetch_row($result)) {
             $values = array();
             if ($first_set) {
                 $query = $sql_data . '(';
             } else {
                 $query .= ',(';
             }
             for ($j = 0; $j < $fields_cnt; $j++) {
                 if (!isset($row[$j]) || is_null($row[$j])) {
                     $values[$j] = 'NULL';
                 } else {
                     if ($field[$j]->flags & 32768 && !($field[$j]->flags & 1024)) {
                         $values[$j] = $row[$j];
                     } else {
                         $values[$j] = "'" . str_replace($search, $replace, $row[$j]) . "'";
                     }
                 }
             }
             $query .= implode(', ', $values) . ')';
             $query_len += strlen($query);
             if ($query_len > $max_len) {
                 $this->flush($query . ";\n\n");
                 $query = '';
                 $query_len = 0;
                 $first_set = true;
             } else {
                 $first_set = false;
             }
         }
         mysqli_free_result($result);
         // check to make sure we have nothing left to flush
         if (!$first_set && $query) {
             $this->flush($query . ";\n\n");
         }
     }
 }