public static function iimysqli_stmt_get_result($stmt)
 {
     /**    EXPLANATION:
      * We are creating a fake "result" structure to enable us to have
      * source-level equivalent syntax to a query executed via
      * mysqli_query().
      *
      *    $stmt = mysqli_prepare($conn, "");
      *    mysqli_bind_param($stmt, "types", ...);
      *
      *    $param1 = 0;
      *    $param2 = 'foo';
      *    $param3 = 'bar';
      *    mysqli_execute($stmt);
      *    $result _mysqli_stmt_get_result($stmt);
      *        [ $arr = _mysqli_result_fetch_array($result);
      *            || $assoc = _mysqli_result_fetch_assoc($result); ]
      *    mysqli_stmt_close($stmt);
      *    mysqli_close($conn);
      *
      * At the source level, there is no difference between this and mysqlnd.
      **/
     $metadata = mysqli_stmt_result_metadata($stmt);
     $ret = new iimysqli_result();
     if (!$ret) {
         return NULL;
     }
     $ret->nCols = mysqli_num_fields($metadata);
     $ret->columns = $metadata->fetch_fields();
     $ret->stmt = $stmt;
     mysqli_free_result($metadata);
     return $ret;
 }
示例#2
0
文件: SQLi.php 项目: sete-pw/images
 /**
  * Возвращяет строку в виде ассоциативного массива
  * @param  stmt Запрос
  * @return array
  */
 private function stmtRowAssoc($stmt)
 {
     if ($stmt instanceof \mysqli_stmt) {
         $data = mysqli_stmt_result_metadata($stmt);
         if (false !== $data) {
             $args = [$stmt];
             $field = [];
             while ($f = $data->fetch_field()) {
                 $f = $f->name;
                 $field[$f] = $f;
                 $args[] =& $field[$f];
             }
             call_user_func_array(mysqli_stmt_bind_result, $args);
             if ($stmt->fetch()) {
                 return $field;
             } else {
                 return false;
             }
         } else {
             return false;
         }
     } else {
         return false;
     }
 }
示例#3
0
 private function stmt_assoc(&$stmt, array &$out)
 {
     $data = mysqli_stmt_result_metadata($stmt);
     $fields = array($this->_STMT);
     $out = array();
     while ($field = mysqli_fetch_field($data)) {
         $fields[] =& $out[$field->name];
     }
     call_user_func_array('mysqli_stmt_bind_result', $fields);
 }
function stmt_bind_assoc(&$stmt, &$out)
{
    $data = mysqli_stmt_result_metadata($stmt);
    $fields = array();
    $out = array();
    $fields[0] = $stmt;
    $count = 1;
    while ($field = mysqli_fetch_field($data)) {
        $fields[$count] =& $out[$field->name];
        $count++;
    }
    call_user_func_array(mysqli_stmt_bind_result, $fields);
}
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;
}
 public function __construct($res, $connection)
 {
     $this->res = $res;
     $this->connection = $connection;
     $this->meta = \mysqli_stmt_result_metadata($this->res);
     if (!$this->meta) {
         //occurs on insert
         //throw new \Exception("Could not retrieve meta for prepare statement");}
         return;
     }
     while ($field = $this->meta->fetch_field()) {
         $this->binds[$field->table . '.' . $field->name] =& $this->binds[$field->table . '.' . $field->name];
     }
     //fix for ambiguous fieldnames
     \mysqli_free_result($this->meta);
     call_user_func_array(array($this->res, 'bind_result'), $this->binds);
     //you need 2 append the parameters - thats the right way to do that.
     $this->res->store_result();
 }
function stmt_bind_assoc(&$stmt, &$out)
{
    $data = mysqli_stmt_result_metadata($stmt);
    $fields = array();
    $out = array();
    $fields[0] = $stmt;
    for ($i = 1; $field = mysqli_fetch_field($data); $i++) {
        $fields[$i] =& $out[$field->name];
    }
    call_user_func_array('mysqli_stmt_bind_result', $fields);
}
示例#8
0
文件: db.php 项目: teju/Android
function execSQL($query, $params, $close)
{
    global $error_message;
    global $conn;
    // LOG
    LOG_MSG('DEBUG', "execSQL(): START");
    LOG_MSG('DEBUG', " QUERY=[" . $query . "]");
    LOG_MSG('DEBUG', " PARAMS\n[" . print_r($params, true) . "]");
    $log_query = preg_replace("/\t/", " ", $query);
    $log_query = preg_replace("/\n/", " ", $log_query);
    $log_query = preg_replace("/[\\s]+/", " ", $log_query);
    LOG_MSG('INFO', " QUERY=[{$log_query}] PARAMS=[" . implode("|", $params) . "]");
    // Reset result set before starting
    $resp = array("STATUS" => "ERROR");
    // For DMLs
    $resp[0]['STATUS'] = "ERROR";
    // For Selects
    $error_message = "There was an error proccessing your request. Please check and try again";
    // INIT STATEMENT
    if (!($stmt = mysqli_stmt_init($conn))) {
        LOG_MSG('ERROR', "execSQL(): Error initializing statement: [" . mysqli_errno($conn) . ": " . mysqli_error($conn) . "]. ");
        $resp['SQL_ERROR_CODE'] = mysqli_errno($conn);
        return $resp;
    }
    LOG_MSG('DEBUG', "execSQL():\t Init query");
    // PREPARE
    if (!mysqli_stmt_prepare($stmt, $query)) {
        LOG_MSG('ERROR', "execSQL(): Error preparing statement: [" . mysqli_errno($conn) . ": " . mysqli_error($conn) . "].");
        $resp['SQL_ERROR_CODE'] = mysqli_errno($conn);
        return $resp;
    }
    LOG_MSG('DEBUG', "execSQL():\t Prepared query");
    // BIND PARAMS
    if (!empty($params)) {
        // Bind input params
        if (!call_user_func_array(array($stmt, 'bind_param'), refValues($params))) {
            LOG_MSG('ERROR', "execSQL(): Error binding input params: [" . mysqli_errno($conn) . ": " . mysqli_error($conn) . "].");
            $resp['SQL_ERROR_CODE'] = mysqli_errno($conn);
            mysqli_stmt_close($stmt);
            // Close statement
            return $resp;
        }
    }
    LOG_MSG('DEBUG', "execSQL():\t Bound query parameters");
    // EXECUTE
    $qry_exec_time = microtime(true);
    $status = mysqli_stmt_execute($stmt);
    $qry_exec_time = number_format(microtime(true) - $qry_exec_time, 4);
    if (!$status) {
        LOG_MSG('ERROR', "execSQL(): Error executing statement: [" . mysqli_errno($conn) . ": " . mysqli_error($conn) . "].");
        $resp['SQL_ERROR_CODE'] = mysqli_errno($conn);
        mysqli_stmt_close($stmt);
        // Close statement
        return $resp;
    }
    LOG_MSG('INFO', "      Executed query in {$qry_exec_time} secs");
    // DMLs (insert/update/delete)
    // If CLOSE, then return no of rows affected
    if ($close) {
        unset($resp[0]);
        $error_message = "";
        $resp["STATUS"] = "OK";
        $resp["EXECUTE_STATUS"] = $status;
        $resp["NROWS"] = $conn->affected_rows;
        $resp["INSERT_ID"] = $conn->insert_id;
        mysqli_stmt_close($stmt);
        // Close statement
        LOG_MSG('INFO', "      Status=[OK] Affected rows [" . $resp['NROWS'] . "]");
        LOG_MSG('DEBUG', "execSQL(): UPDATE/INSERT response:\n[" . print_r($resp, true) . "]");
        LOG_MSG('DEBUG', "execSQL(): END");
        return $resp;
    }
    // SELECT
    $result_set = mysqli_stmt_result_metadata($stmt);
    while ($field = mysqli_fetch_field($result_set)) {
        $parameters[] =& $row[$field->name];
    }
    // BIND OUTPUT
    if (!call_user_func_array(array($stmt, 'bind_result'), refValues($parameters))) {
        LOG_MSG('ERROR', "execSQL(): Error binding output params: [" . mysqli_errno($conn) . ": " . mysqli_error($conn) . "].");
        $resp[0]['SQL_ERROR_CODE'] = mysqli_errno($conn);
        mysqli_free_result($result_set);
        // Close result set
        mysqli_stmt_close($stmt);
        // Close statement
        return $resp;
    }
    LOG_MSG('DEBUG', "execSQL():\t Bound output parameters");
    // FETCH DATA
    $i = 0;
    while (mysqli_stmt_fetch($stmt)) {
        $x = array();
        foreach ($row as $key => $val) {
            $x[$key] = $val;
        }
        $results[] = $x;
        $i++;
    }
    $results[0]["NROWS"] = $i;
    $error_message = "";
    // Reset Error message
    $results[0]["STATUS"] = "OK";
    // Reset status
    mysqli_free_result($result_set);
    // Close result set
    mysqli_stmt_close($stmt);
    // Close statement
    LOG_MSG('INFO', "      Status=[OK] Affected rows [" . $results[0]['NROWS'] . "]");
    LOG_MSG('DEBUG', "execSQL(): SELECT Response:\n[" . print_r($results[0], true) . "]");
    LOG_MSG('DEBUG', "execSQL(): END");
    return $results;
}
if (!is_object($res_meta = mysqli_stmt_result_metadata($stmt)) || 'mysqli_result' != get_class($res_meta)) {
    printf("[005] Expecting object/mysqli_result got %s/%s, [%d] %s\n", gettype($res), $res, mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
}
var_dump(mysqli_fetch_assoc($res));
var_dump(mysqli_fetch_assoc($res_meta));
mysqli_free_result($res);
mysqli_free_result($res_meta);
mysqli_stmt_close($stmt);
// !mysqli_stmt_prepare($stmt, "SELECT id, label, id + 1 as _id,  concat(label, '_') _label FROM test as _test ORDER BY id ASC LIMIT 3") ||
if (!($stmt = mysqli_stmt_init($link)) || !mysqli_stmt_prepare($stmt, "SELECT id , label, id + 1 AS _id, label AS _label, null AS _null, CONCAT(label, '_') _label_concat  FROM test _test ORDER BY id ASC LIMIT 3") || !mysqli_stmt_execute($stmt)) {
    printf("[006] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
}
if (!is_object($res = mysqli_stmt_get_result($stmt)) || 'mysqli_result' != get_class($res)) {
    printf("[007] Expecting object/mysqli_result got %s/%s, [%d] %s\n", gettype($res), $res, mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
}
if (!is_object($res_meta = mysqli_stmt_result_metadata($stmt)) || 'mysqli_result' != get_class($res_meta)) {
    printf("[008] Expecting object/mysqli_result got %s/%s, [%d] %s\n", gettype($res), $res, mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
}
if (($tmp1 = mysqli_num_fields($res)) !== ($tmp2 = mysqli_num_fields($res_meta))) {
    printf("[009] %s/%s !== %s/%s\n", gettype($tmp1), $tmp1, gettype($tmp2), $tmp2);
}
/*
if (($tmp1 = mysqli_field_count($link)) !== ($tmp2 = $res->field_count()))
	printf("[010] %s/%s !== %s/%s\n", gettype($tmp1), $tmp1, gettype($tmp2), $tmp2);

if (($tmp1 = $res_meta->field_count()) !== $tmp2)
	printf("[011] %s/%s !== %s/%s\n", gettype($tmp1), $tmp1, gettype($tmp2), $tmp2);
*/
if (($tmp1 = mysqli_field_tell($res)) !== ($tmp2 = $res_meta->current_field)) {
    printf("[012] %s/%s !== %s/%s\n", gettype($tmp1), $tmp1, gettype($tmp2), $tmp2);
}
示例#10
0
文件: db.php 项目: vinod-co/centa
 function GetMultiRow()
 {
     global $mysqli;
     $this->_BuildQuery();
     //echo "QRY : " . $this->query . "<BR>";
     $stmt = $mysqli->prepare($this->query);
     $this->_BindWhere($stmt);
     $stmt->execute();
     $data = mysqli_stmt_result_metadata($stmt);
     $fields = array();
     $out = array();
     $fields[0] = $stmt;
     while ($field = mysqli_fetch_field($data)) {
         $fields[] =& $out[$field->name];
     }
     call_user_func_array('mysqli_stmt_bind_result', $fields);
     $results = array();
     while ($stmt->fetch()) {
         $row = array();
         foreach ($out as $key => $value) {
             $row[$key] = $value;
         }
         $results[] = $row;
     }
     return $results;
 }
示例#11
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);
}
        printf("[006] Unexpected field '%s', dumping info\n");
        var_dump($field);
    }
}
if (!empty($field_names)) {
    printf("[007] Field descriptions missing for the following columns\n");
    var_dump($field_names);
}
mysqli_free_result($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);
 /**
  * Fetch the result
  * @param resource $result
  * @param int|NULL $arrayIndexEndValue
  * @return array
  */
 function _fetch($result, $arrayIndexEndValue = NULL)
 {
     if ($this->use_prepared_statements != 'Y') {
         return parent::_fetch($result, $arrayIndexEndValue);
     }
     $output = array();
     if (!$this->isConnected() || $this->isError() || !$result) {
         return $output;
     }
     // Prepared stements: bind result variable and fetch data
     $stmt = $result;
     $meta = mysqli_stmt_result_metadata($stmt);
     $fields = mysqli_fetch_fields($meta);
     /**
      * Mysqli has a bug that causes LONGTEXT columns not to get loaded
      * Unless store_result is called before
      * MYSQLI_TYPE for longtext is 252
      */
     $longtext_exists = false;
     foreach ($fields as $field) {
         if (isset($resultArray[$field->name])) {
             $field->name = 'repeat_' . $field->name;
         }
         // Array passed needs to contain references, not values
         $row[$field->name] = "";
         $resultArray[$field->name] =& $row[$field->name];
         if ($field->type == 252) {
             $longtext_exists = true;
         }
     }
     $resultArray = array_merge(array($stmt), $resultArray);
     if ($longtext_exists) {
         mysqli_stmt_store_result($stmt);
     }
     call_user_func_array('mysqli_stmt_bind_result', $resultArray);
     $rows = array();
     while (mysqli_stmt_fetch($stmt)) {
         $resultObject = new stdClass();
         foreach ($resultArray as $key => $value) {
             if ($key === 0) {
                 continue;
                 // Skip stmt object
             }
             if (strpos($key, 'repeat_')) {
                 $key = substr($key, 6);
             }
             $resultObject->{$key} = $value;
         }
         $rows[] = $resultObject;
     }
     mysqli_stmt_close($stmt);
     if ($arrayIndexEndValue) {
         foreach ($rows as $row) {
             $output[$arrayIndexEndValue--] = $row;
         }
     } else {
         $output = $rows;
     }
     if (count($output) == 1) {
         if (isset($arrayIndexEndValue)) {
             return $output;
         } else {
             return $output[0];
         }
     }
     return $output;
 }
}
if (empty($tmp[0]) || empty($tmp[1]) || $tmp[0] != $field0_direct) {
    printf("[012] mysqli_fetch_fields() return value is suspicious\n");
    var_dump($tmp);
}
if (!mysqli_field_seek($res, 1)) {
    printf("[013] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
}
if (!is_object($field1_direct = mysqli_fetch_field_direct($res, 1))) {
    printf("[014] Expecting object, got %s/%s, [%d] %s\n", gettype($field1_direct), $field1_direct, mysqli_errno($link), mysqli_error($link));
}
if ($tmp[1] != $field1_direct) {
    printf("[015] mysqli_fetch_field_direct() differs from mysqli_fetch_fields()\n");
    var_dump($field1_direct);
    var_dump($tmp);
}
if (1 !== ($tmp = mysqli_field_tell($res))) {
    printf("[016] Expecting int/1, got %s/%s, [%d] %s\n", gettype($tmp), $tmp, mysqli_errno($link), mysqli_error($link));
}
mysqli_free_result($res);
mysqli_stmt_close($stmt);
if (NULL !== ($tmp = mysqli_stmt_result_metadata($stmt))) {
    printf("[017] Expecting NULL, got %s/%s\n");
}
/* Check that the function alias exists. It's a deprecated function,
	but we have not announce the removal so far, therefore we need to check for it */
if (!is_null($tmp = @mysqli_stmt_result_metadata())) {
    printf("[018] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
}
mysqli_close($link);
print "done!";
示例#15
0
 public static function getColumnMeta($index, $sql)
 {
     if ($sql && $index >= 0) {
         $newmeta = array();
         if (get_class($sql) == "mysqli_result") {
             $mt = mysqli_fetch_field_direct($sql, $index);
         } else {
             $fd = mysqli_stmt_result_metadata($sql);
             $mt = mysqli_fetch_field_direct($fd, $index);
         }
         $newmeta["name"] = $mt->name;
         $newmeta["native_type"] = $mt->type;
         $newmeta["len"] = $mt->length;
         return $newmeta;
     }
     return false;
 }
示例#16
0
文件: SQL.php 项目: Vidov/CMS
 protected function SelectQuery($con, $query, $params)
 {
     $stmt = $this->PrepareQuery($con, $query, $params);
     if (!$stmt) {
         return;
     }
     mysqli_execute($stmt);
     // SELECT * FROM Users
     $rows = mysqli_stmt_result_metadata($stmt);
     while ($field = mysqli_fetch_field($rows)) {
         $fields[] =& $row[$field->name];
         $az[] = $field->name;
     }
     call_user_func_array(array($stmt, 'bind_result'), $fields);
     $i = 0;
     while (mysqli_stmt_fetch($stmt)) {
         foreach ($az as $key => $value) {
             $arr[$i][$value] = $row[$value];
         }
         $i++;
     }
     if ($arr) {
         return $arr;
     } else {
         $this->DB_false($query, $params);
         return FALSE;
     }
 }
}
if (empty($tmp[0]) || empty($tmp[1]) || $tmp[0] != $field0_direct) {
    printf("[012] mysqli_fetch_fields() return value is suspicious\n");
    var_dump($tmp);
}
if (!mysqli_field_seek($res, 1)) {
    printf("[013] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
}
if (!is_object($field1_direct = mysqli_fetch_field_direct($res, 1))) {
    printf("[014] Expecting object, got %s/%s, [%d] %s\n", gettype($field1_direct), $field1_direct, mysqli_errno($link), mysqli_error($link));
}
if ($tmp[1] != $field1_direct) {
    printf("[015] mysqli_fetch_field_direct() differs from mysqli_fetch_fields()\n");
    var_dump($field1_direct);
    var_dump($tmp);
}
if (1 !== ($tmp = mysqli_field_tell($res))) {
    printf("[016] Expecting int/1, got %s/%s, [%d] %s\n", gettype($tmp), $tmp, mysqli_errno($link), mysqli_error($link));
}
mysqli_free_result($res);
mysqli_stmt_close($stmt);
if (NULL !== ($tmp = mysqli_stmt_result_metadata($stmt))) {
    printf("[017] Expecting NULL, got %s/%s\n");
}
/* Check that the function alias exists. It's a deprecated function,
	but we have not announce the removal so far, therefore we need to check for it */
mysqli_close($link);
print "done!";
error_reporting(0);
$test_table_name = 'test_mysqli_stmt_result_metadata_table_1';
require_once "clean_table.inc";
 function addColumns($sqliR, $tabName = "")
 {
     // Analyse structure of sqli result (columns of result table) and create $Columns accordingly
     $this->LastQueryColumns = array();
     if (!$sqliR) {
         return;
     }
     if (!$this->Values) {
         $this->Values = array();
     }
     if ($sqliR === true) {
         return;
     }
     // no data returned, ex INSERT query
     if (!method_exists($sqliR, 'fetch_fields')) {
         // prepared statement mode
         //echo '<br> = = MySQLi detected PS mode<br>';
         $sqliR = mysqli_stmt_result_metadata($sqliR);
         // sometimes $sqliR->result_metadata is not defined, ex easyPHP12 PHP5.4
         $this->modeMySQLiPrepared = true;
     }
     $f = $sqliR->fetch_fields();
     $count = count($f);
     //echo "MySQLi result = num columns: $count<br>";
     for ($i = 0; $i < $count; $i++) {
         $name = $f[$i]->name;
         $this->LastQueryColumns[] = $name;
         if (!isset($this->Values[$name])) {
             $this->Values[$name] = array();
         }
         // add new column
     }
 }
示例#19
0
 private function bind_assoc()
 {
     if (!($meta = mysqli_stmt_result_metadata($this->sth))) {
         return;
     }
     $fields = array();
     $this->data = array();
     $fields[0] = $this->sth;
     $count = 1;
     while ($field = mysqli_fetch_field($meta)) {
         $fields[$count] =& $this->data[$field->name];
         $count++;
     }
     call_user_func_array('mysqli_stmt_bind_result', $fields);
 }
示例#20
0
 private function stmt_bind_assoc(&$out)
 {
     $data = mysqli_stmt_result_metadata($this->stmt);
     if ($data) {
         $fields = array();
         $out = array();
         $fields[0] = $this->stmt;
         $count = 1;
         while ($field = mysqli_fetch_field($data)) {
             $fields[$count] =& $out[$field->name];
             $count++;
         }
         call_user_func_array("mysqli_stmt_bind_result", $fields);
         return true;
     } else {
         return false;
     }
 }
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;
}
示例#22
0
文件: 047.php 项目: alphaxxl/hhvm
<?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());
}
 protected function _execute()
 {
     if ($this->bind_params_changed) {
         if (!$this->bind_params()) {
             $this->_set_stmt_error(null, EhrlichAndreas_Pdo_Abstract::ERRMODE_SILENT, 'execute');
             return false;
         }
         $this->bind_params_changed = false;
     }
     if (!$this->send_lobs() || !mysqli_stmt_execute($this->_result)) {
         $this->_set_stmt_error(null, EhrlichAndreas_Pdo_Abstract::ERRMODE_SILENT, 'execute');
         return false;
     }
     $data = mysqli_stmt_result_metadata($this->_result);
     // store the result
     if ($data) {
         if (!$this->bind_result($data)) {
             $this->_set_stmt_error(null, EhrlichAndreas_Pdo_Abstract::ERRMODE_SILENT, 'execute');
             return false;
         }
         if ($this->getAttribute(EhrlichAndreas_Pdo_Adapter_Abstract::MYSQL_ATTR_USE_BUFFERED_QUERY)) {
             if (!mysqli_stmt_store_result($this->_result)) {
                 $this->_set_stmt_error(null, EhrlichAndreas_Pdo_Abstract::ERRMODE_SILENT, 'execute');
                 return false;
             }
         }
     }
     return true;
 }
<?php

require_once "connect.inc";
require_once 'table.inc';
$bind_res = $id = null;
if (!($stmt = mysqli_stmt_init($link)) || !mysqli_stmt_prepare($stmt, "SELECT id, label FROM test") || !mysqli_stmt_execute($stmt) || !($result = mysqli_stmt_result_metadata($stmt)) || !mysqli_stmt_bind_result($stmt, $id, $bind_res) || !($fields = mysqli_fetch_fields($result))) {
    printf("FAIL 1\n");
}
while (mysqli_stmt_fetch($stmt)) {
}
mysqli_free_result($result);
mysqli_stmt_close($stmt);
if (!($stmt = mysqli_stmt_init($link)) || !mysqli_stmt_prepare($stmt, "SELECT id, label FROM test") || !mysqli_stmt_execute($stmt) || !($result = mysqli_stmt_result_metadata($stmt)) || !mysqli_stmt_bind_result($stmt, $id, $bind_res)) {
    printf("FAIL 2\n");
}
print "OK: 1\n";
if (!($fields = mysqli_fetch_fields($result))) {
    printf("Aua 3\n");
}
print "OK: 2\n";
while (mysqli_stmt_fetch($stmt)) {
}
mysqli_free_result($result);
mysqli_stmt_close($stmt);
mysqli_close($link);
print "done!";
示例#25
0
function iimysqli_stmt_get_result($stmt)
{
    $metadata = mysqli_stmt_result_metadata($stmt);
    $ret = new iimysqli_result();
    if (!$ret) {
        return NULL;
    }
    $ret->nCols = mysqli_num_fields($metadata);
    $ret->stmt = $stmt;
    mysqli_free_result($metadata);
    return $ret;
}
 protected function _execute()
 {
     if ($this->bind_params_changed) {
         if (!$this->bind_params()) {
             $this->_set_stmt_error(null, PDO::ERRMODE_SILENT, 'execute');
             return false;
         }
         $this->bind_params_changed = false;
     }
     if (!$this->send_lobs() || !mysqli_stmt_execute($this->_result)) {
         $this->_set_stmt_error(null, PDO::ERRMODE_SILENT, 'execute');
         return false;
     }
     // store the result
     if ($data = mysqli_stmt_result_metadata($this->_result)) {
         if (!$this->bind_result($data)) {
             $this->_set_stmt_error(null, PDO::ERRMODE_SILENT, 'execute');
             return false;
         }
         if ($this->getAttribute(phppdo_base::MYSQL_ATTR_USE_BUFFERED_QUERY)) {
             if (!mysqli_stmt_store_result($this->_result)) {
                 $this->_set_stmt_error(null, PDO::ERRMODE_SILENT, 'execute');
                 return false;
             }
         }
     }
     return true;
 }
示例#27
0
 function _get_field_name()
 {
     if (isset($this->field_names)) {
         return $this->field_names;
     }
     if ($this->prepare_statement) {
         if ($result_metadata = mysqli_stmt_result_metadata($this->prepare_statement)) {
             $field_names = mysqli_fetch_fields($result_metadata);
             if (isset($field_names) && is_array($field_names)) {
                 $this->field_names = array();
                 foreach ($field_names as $cur_field_name) {
                     $this->field_names[] = $cur_field_name->name;
                 }
                 return $this->field_names;
             }
         }
     }
     return array();
 }
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;
}
示例#29
0
 public function executeQueryA($sql, $argv = NULL, $pagesize = 0, $pageno = 0)
 {
     //Logger::trace("MysqlDao.executeQuery executed", LOG_LEVEL_NOTICE);
     if ($pagesize < 0) {
         $pagesize = 0;
     }
     if ($pageno < 0) {
         $pageno = 0;
     }
     $lowstr = strtolower($sql);
     if (!(strtolower(substr($lowstr, 0, 6)) === "select")) {
         throw new DaoException("Invalid query SQL statement.");
     }
     $pos = strpos($lowstr, "from");
     if (!strpos($lowstr, "from")) {
         //Logger::trace("Invalid query SQL statement.", LOG_LEVEL_ERROR);
         //Logger::debug("sql = $sql, argv = $argv");
         throw new DaoException("Invalid query SQL statement.");
     }
     $colstr = substr($lowstr, 6, $pos - 6);
     $pos = 0;
     $colcount = 0;
     while (!($pos === false)) {
         $pos = strpos($colstr, ",", $pos + 1);
         $colcount++;
     }
     $connected = $this->connected();
     $conn = $connected ? $this->conn : $this->connect(FALSE);
     mysqli_query($conn, "set names 'utf8'");
     $allrow = array();
     $stmt = mysqli_prepare($conn, $sql);
     if (mysqli_errno($conn)) {
         $errno = mysqli_errno($conn);
         $error = "MYSQL ERROR #" . $errno . " : " . mysqli_error($conn);
         throw new DaoException($error, $errno);
     }
     //Logger::trace("sql = " . $sql, LOG_LEVEL_VERBOSE);
     if (isset($argv) && count($argv) > 0) {
         $bind_param_cmd = "mysqli_stmt_bind_param(\$stmt, ";
         $paramstr = "";
         $bindstr = "";
         $holdstr = "";
         $i = 0;
         foreach ($argv as $arg) {
             $paramstr .= "\$invar{$i}, ";
             $bindstr .= "\$invar{$i} = \$argv[{$i}]; ";
             $holdstr .= "s";
             $i++;
         }
         $bind_param_cmd = "mysqli_stmt_bind_param(\$stmt, \"{$holdstr}\", " . substr($paramstr, 0, strlen($paramstr) - 2) . "); ";
         $bind_param_cmd .= $bindstr;
         //Logger::trace("bind parameter: " . $bind_param_cmd, LOG_LEVEL_VERBOSE);
         eval($bind_param_cmd);
     }
     mysqli_stmt_execute($stmt);
     if (mysqli_stmt_errno($stmt)) {
         $errno = mysqli_stmt_errno($stmt);
         $error = "MYSQL ERROR #" . $errno . " : " . mysqli_stmt_error($stmt);
         //Logger::trace($error, LOG_LEVEL_ERROR);
         //Logger::debug("sql = $sql ". ($argv));
         throw new DaoException($error, $errno);
     }
     //��ý���Ԫ��� //
     /*&�����   ��j���� �Խ����ֶ�Ϊ����*/
     $data = mysqli_stmt_result_metadata($stmt);
     $fields = array();
     $out = array();
     $fields[0] = $stmt;
     $count = 1;
     while ($field = mysqli_fetch_field($data)) {
         $fields[$count] =& $out[$field->name];
         $count++;
     }
     call_user_func_array(mysqli_stmt_bind_result, $fields);
     //����
     mysqli_stmt_store_result($stmt);
     //��ҳ
     if ($pagesize > 0) {
         mysqli_stmt_data_seek($stmt, $pagesize * $pageno);
     }
     $cnt = 1;
     while (mysqli_stmt_fetch($stmt)) {
         /*���$row���ø�ֵֻ�����һ���¼������
         			�������ѭ�������ݵĸ�ֵ
         		*/
         foreach ($out as $key => $value) {
             $row_tmb[$key] = $value;
         }
         $allrow[] = $row_tmb;
         if ($pagesize > 0) {
             if (++$cnt > $pagesize) {
                 break;
             }
         }
     }
     mysqli_stmt_close($stmt);
     if (!$connected) {
         $this->disconnect($conn);
     }
     return $allrow;
 }