if (!($res = mysqli_store_result($link))) {
     printf("[012 - %d] [%d] %s\n", $res_num, mysqli_errno($link), mysqli_error($link));
     continue;
 }
 $num_rows = 0;
 while ($row = mysqli_fetch_array($res)) {
     $num_rows++;
     if ($row['num'] != $res_num) {
         printf("[013 - %d] Expecting %s got %s\n", $res_num, $res_num, $row['num']);
     }
     if ($row['somechar'] != "a") {
         printf("[014 - %d] Expecting a got %s\n", $res_num, $row['somechar']);
     }
     if (1 == $num_rows) {
         /* simple metadata check */
         if (!($lengths = mysqli_fetch_lengths($res))) {
             printf("[015 - %d] [%d] %s\n", $res_num, mysqli_errno($link), mysqli_error($link));
         }
         if (count($lengths) != 2) {
             printf("[016 - %d] Expecting 2 column lengths got %d [%d] %s\n", $res_num, count($lengths));
         }
         foreach ($lengths as $k => $length) {
             if ($length <= 0) {
                 printf("[017 - %d] Strange column lengths for column %d, got %d expecting any > 0\n", $res_num, $k, $length);
             }
         }
     }
 }
 if ($num_rows != 1) {
     printf("[018 - %d] Expecting 1 row, got %d rows\n", $num_rows);
 }
Beispiel #2
0
$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());
}
if (!mysqli_query($link, "DROP TABLE IF EXISTS test_047_table_1")) {
    printf("[c002] Cannot drop table, [%d] %s\n", mysqli_errno($link), mysqli_error($link));
}
mysqli_close($link);
 function mysql_fetch_lengths($result)
 {
     if (!is_myresource($result, true)) {
         $msg = sprintf('expects parameter 1 to be mysql result object, %s given', gettype($result));
         trigger_error(mysql_trigger_msg($msg, current(debug_backtrace())), E_USER_WARNING);
         return false;
     }
     return mysqli_fetch_lengths($result);
 }
    var_dump(mysqli_fetch_lengths($res));
}
var_dump(mysqli_fetch_lengths($res));
if (!($res = mysqli_real_query($link, "SELECT CONCAT(id, id) AS _c, label FROM test ORDER BY id DESC LIMIT 2"))) {
    printf("[012] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
}
if (!is_object($res = mysqli_store_result($link, MYSQLI_STORE_RESULT_COPY_DATA))) {
    printf("[013] Expecting object, got %s/%s. [%d] %s\n", gettype($res), $res, mysqli_errno($link), mysqli_error($link));
}
printf("Copy\n");
var_dump(mysqli_fetch_lengths($res));
$fields_copy = $res->fetch_fields();
while ($row = $res->fetch_assoc()) {
    var_dump(mysqli_fetch_lengths($res));
}
var_dump(mysqli_fetch_lengths($res));
/* There's no need for in-depth testing here. If you want in-depth switch mysqlnd
	globally to copy mode and run all the tests */
foreach ($fields as $k => $field_info) {
    if ($fields_copy[$k] != $field_info) {
        printf("[014] Metadata seems to differ, dumping\n");
        var_dump($field_info);
        var_dump($fields_copy[$k]);
    }
}
/* fetch all */
if (!($res = mysqli_real_query($link, "SELECT id, label FROM test ORDER BY id DESC LIMIT 2"))) {
    printf("[015] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
}
if (!is_object($res = mysqli_store_result($link, MYSQLI_STORE_RESULT_COPY_DATA))) {
    printf("[016] Expecting object, got %s/%s. [%d] %s\n", gettype($res), $res, mysqli_errno($link), mysqli_error($link));
Beispiel #5
0
 public function fetchOne()
 {
     if ($this->usemysqli) {
         switch ($this->fetchMode) {
             case __ARRAY:
                 $result = mysqli_fetch_array($this->result);
                 break;
             case __ASSOCARRAY:
                 $result = mysqli_fetch_assoc($this->result);
                 break;
             case __FIELDDIRECT:
                 $result = mysqli_fetch_field_direct($this->result, $this->fetchFieldDirectFieldNr);
                 break;
             case __FIELD:
                 $result = mysqli_fetch_field($this->result);
                 break;
             case __FIELDS:
                 $result = mysqli_fetch_fields($this->result);
                 break;
             case __LENGTHS:
                 $result = mysqli_fetch_lengths($this->result);
                 break;
             case __OBJECT:
                 $result = mysqli_fetch_object($this->result);
                 break;
             case __ROW:
                 $result = mysqli_fetch_row($this->result);
                 break;
             default:
                 $result = null;
                 break;
         }
         return $result;
     } else {
         switch ($this->fetchMode) {
             case __ARRAY:
                 $result = mysql_fetch_array($this->result);
                 break;
             case __ASSOCARRAY:
                 $result = mysql_fetch_assoc($this->result);
                 break;
             case __FIELDDIRECT:
                 $result = NULL;
                 break;
             case __FIELD:
                 $result = mysql_fetch_field($this->result);
                 break;
             case __FIELDS:
                 $result = NULL;
                 break;
             case __LENGTHS:
                 $result = mysql_fetch_lengths($this->result);
                 break;
             case __OBJECT:
                 $result = mysql_fetch_object($this->result);
                 break;
             case __ROW:
                 $result = mysql_fetch_row($this->result);
                 break;
             default:
                 $result = null;
                 break;
         }
         return $result;
     }
 }
Beispiel #6
0
 function mysql_fetch_lengths($result)
 {
     if (\Dshafik\MySQL::checkValidResult($result, __FUNCTION__)) {
         // @codeCoverageIgnoreStart
         return false;
         // @codeCoverageIgnoreEnd
     }
     return mysqli_fetch_lengths($result);
 }
$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));
}
if (!is_object($res = new mysqli_result($link))) {
    switch (DB_EXTENSION) {
        case "mysql":
            $ret = mysql_fetch_array($result);
            break;
        case "mysqli":
            $ret = mysqli_fetch_array($result);
            break;
    }
    return $ret;
}
function yog_mysql_fetch_lengths($result)
{
    //Get the length of each output in a result
    $ret = array();
Beispiel #9
0
     $Packet .= pack('C', $Field->decimals);
     SendPacket($Packet);
 }
 $Packet = '';
 $Packet .= "þ";
 $Packet .= pack('v', mysqli_warning_count($mysqli));
 if ($MorePackets || mysqli_more_results($mysqli)) {
     $Packet .= pack('v', 0x8);
 } else {
     $Packet .= pack('v', 0x0);
 }
 // Server Status
 SendPacket($Packet);
 while ($Row = mysqli_fetch_array($result, MYSQL_NUM)) {
     $Packet = '';
     $Lengths = mysqli_fetch_lengths($result);
     for ($i = 0; $i < mysqli_num_fields($result); $i++) {
         if (!isset($Row[$i])) {
             $Packet .= "û";
         } else {
             $Packet .= PackLength($Lengths[$i]) . $Row[$i];
         }
     }
     SendPacket($Packet);
 }
 $Packet = '';
 $Packet .= "þ";
 $Packet .= pack('v', mysqli_warning_count($mysqli));
 if ($MorePackets || mysqli_more_results($mysqli)) {
     $Packet .= pack('v', 0x8);
 } else {
function mysql_compat_fetch_lengths($result)
{
    return mysqli_fetch_lengths($result);
}
Beispiel #11
0
function sql5($sql, $p = '', $nt = '')
{
    static $i, $Acache;
    $i++;
    if (is_array($sql)) {
        extract($sql);
    }
    #
    if (isset($Acache[md5($sql)])) {
        return $Acache[md5($sql)];
    }
    #if(j9&&strpos(u,'607b'))av('DB:'.DB);
    if ($p == 1 or $nt == 1) {
        $close = 1;
        unset($p, $nt);
    }
    if (strpos($sql, '.s3db')) {
        Preg_match('~[^ ]+\\.s3db\\.~i', $sql, $m);
        $p = trim($m[0], '.');
        $sql = str_replace($m[0], '', $sql);
    }
    if (strpos($p, '.s3db')) {
        return sqlite($sql, $p, $close);
    }
    #no=1,bd=ben,pile=id,np=0
    if ($p) {
        if ($y = param($p)) {
            extract($y);
        }
    }
    gt('0:sql5' . $i . __LINE__);
    $_ENV['sql'][] = $sql;
    $x = sql($sql, $bd, $p);
    gt('1:sql5' . $i . __LINE__);
    if (is_numeric($x)) {
        return $x;
    }
    if (!$x) {
        return;
    }
    #retour de Num_rows quand update
    $nr = mysqli_num_rows($_ENV['sqlquery']);
    if ($nr < 1) {
        return;
    }
    #Si resultat vide#Seulement sur un select
    #$if($len>30000000)
    $mem = memory_get_usage();
    if ($mem > 30000000) {
        $len = array_sum(mysqli_fetch_lengths($x));
        DBM('debugmem', "sql:{$sql}, len:{$len}, mem:{$mem}");
    }
    gt('0:sql5while' . $i . __LINE__);
    while ($t = mysqli_fetch_assoc($x)) {
        #Memleak Here ///
        #@mysql_volume_kilobytes:sizeof($R)>90.000.000 ????
        #if($mem>40000000)DBM('debugmem',$sql.pre($t).$mem);
        if ($nc) {
            $R[] = $t;
            continue;
        }
        #2dim Array for 1D Array, no collapse, original form switch
        if ($nr == 1 && $np) {
            $R = $t;
            break;
        }
        #Single Array for Result
        if ($pile) {
            $id = $t[$pile];
            unset($t[$pile]);
            $R[$id] = $t;
            continue;
        }
        //Replaces the key with some value(id)
        if ($nr == 1 && count($t) == 1 && !$no) {
            $R = end($t);
            break;
        }
        #1single results return a string
        if ($nr == 1 && !$no) {
            $R = $t;
            break;
        }
        #1 column returns 1 dimension Array
        if (count($t) == 1 and !$no) {
            $R[] = end($t);
            continue;
        }
        #2dim-1single value//Un seul élément => Dépilé !
        $R[] = $t;
        //todo:MemError allocation here
    }
    #if(j10){print_r(compact('R','t'));die;}
    if ($_ENV['sqlcache'] || $cache) {
        $Acache[md5($sql)] = $R;
    }
    #if(strpos(U,'webcam.php')){print_r(compact('R','sql'));die;}
    gt('1:sql5while' . $i . __LINE__);
    #14ms dans le while
    mysqli_free_result($x);
    if (is_array($R)) {
        $R = array_filter($R);
    }
    return $R;
    gt('1:sql5freeres' . $i . __LINE__);
}