mysqli_fetch_assoc()函数不起作用

时间:2016-07-21 16:46:36

标签: php

{% do data.update({'enabled':'True'}) %}

此代码在Hostinger中运行良好,但是当我迁移到Godaddy时它无法正常工作(没有输出)

此代码与Godaddy合作正常:

<?php
    define('HOST','host');
    define('USER','user name');
    define('PASS','password');
    define('DB','db name');

    $con = mysqli_connect(HOST,USER,PASS,DB);
    $sql = "select * from toursit_guide where cat='Amusement Parks'"; 
    $result = mysqli_query($con,$sql);
    $json = array();

    if($rowcount=mysqli_num_rows($result))
    {
    echo $rowcount;
    while($row=mysqli_fetch_assoc($result))
    {
    $json['tourist_guide'][]=$row;
    }
    }
    mysqli_close($con);
    echo json_encode($json,JSON_PARTIAL_OUTPUT_ON_ERROR); 
?>

我希望用<?php define('HOST','hostname'); define('USER','username'); define('PASS','password'); define('DB','db_name'); $con = mysqli_connect(HOST,USER,PASS,DB); $sql = "select * from vg_main"; $res = mysqli_query($con,$sql); $result = array(); while($row = mysqli_fetch_array($res)) { array_push($result, array('id'=>$row[0], 'cat_name'=>$row[1], 'sub_cat_name'=>$row[2], 'name'=>$row[3], 'icon'=>$row[4], 'description'=>$row[5], 'lat'=>$row[6], 'lon'=>$row[7], 'contact_no'=>$row[8], 'email_id'=>$row[9], 'website'=>$row[10], 'open_time'=>$row[12], 'Address'=>$row[13], 'image'=>$row[14] )); } echo json_encode(array("Output"=>$result)); mysqli_close($con); ?> 来完成,因为许多文件都是用assoc编写的。

0 个答案:

没有答案