doubi5127 2013-07-27 11:22
浏览 385
已采纳

致命错误:无法在[关闭]中使用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?

  • 写回答

1条回答 默认 最新

  • duankeng9477 2013-07-27 11:30
    关注

    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);
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan