致命错误:无法在[关闭]中使用mysqli_result类型的对象作为数组

致命错误:无法在[关闭]中使用mysqli_result类型的对象作为数组

问题描述:

part1: why i have this error
Fatal error: Cannot use object of type mysqli_result as array in
can anyone help me with this ?
when i run this query i get that error

 $checkuser = $c->query("select * from user where(email = 'test@test.com' or mobile = '0933' or username = 'test') limit 1") or die("$c->error");

$c is function to do this=

function db(){
$dbname = 'ro****';
$dbuser = 'roy*****2_fb';
$dbpass = '#******s';
$dbhost = 'localhost';
$mysqli = new mysqli($dbhost, $dbuser, $dbpass, $dbname) or die('Cant connect to Database Server');
$mysqli->query("SET NAMES utf8");
$mysqli->query("SET CHARACTER_SET utf8");
return $mysqli;
}

$c = db();

part2:
and guys there is anyway to get $header in code below:

<?php
$header = 1;
?>
<div id="content">
</div>
<script>$.ajax({url:mypage.php,success:function(loaddataa){
$('#content').html(loaddataa);</script>

and in mypage.php

<? echo $header ?>

but its not get $header when its loaded with ajax
i actully try to load page without header and footer and do query just 1 time in header but i cant get in pages loaded with ajax
its have anyway?

Use simply PDO:

/* Connect to an ODBC database using driver invocation */
$pdo = 'mysql:dbname=testdb;host=127.0.0.1';
$user = 'dbuser';
$password = 'dbpass';

try {
    $connection = new PDO($pdo, $user, $password);
} catch (PDOException $e) {
    echo 'Connection failed: ' . $e->getMessage();
}

function getFruit($connection) {
    $sql = 'SELECT name, color, calories FROM fruit ORDER BY name';
    foreach ($connection->query($sql) as $row) {
        print $row['name'] . "\t";
        print $row['color'] . "\t";
        print $row['calories'] . "
";
    }
}

getFruit($connection);

File client.php:

<?php
    // Array
    $header = array(
        'test' => 'PHP',
        'happy' => 'test'
    );

    // Encode
    $header = base64_encode(json_encode($header));
?>

<div id="content"></div>

<script>
    $.ajax({
        type: "POST",
        url: "mypage.php",
        data: { header: "<?=$header?>" }
    }).done(function(source) {
        $('#content').html(source);
    });       
</script>

And mypage.php:

<?php
    // Get
    $header = $_POST['header'];

    // Decode
    $header = json_decode(base64_decode($header));

    // Array
    var_dump($header);
?>