MySql空结果集返回不同的格式

时间:2020-11-27 18:05:41

I am trying to execute two simple select queries on two different tables in mysql server. This I am doing this by running a php script. Both the queries are supposed to return an empty result set. But they are returning different formats.

我试图在mysql服务器中的两个不同的表上执行两个简单的选择查询。这是我通过运行PHP脚本来做到这一点。两个查询都应该返回一个空结果集。但他们正在返回不同的格式。

City table is returning a simple null value where as Dealer table is returning all columns with null values.

City表返回一个简单的空值,其中Dealer表返回所有具有空值的列。

Output:

{**"dealer"**:[{"car_make":null,"state":null,"city":null,"company_name":null,"company_address":null,"phone":null,"mobile":null,"fax":null,"email":null,"website":null,"Data_Version":null}],**"city"**:null}

PHP Script

<?php

$data_version = 5;

require 'DbConnect.php';


$query = ("SELECT * FROM `Dealer` WHERE `Data_Version` > $data_version");


if ($query_run = mysql_query($query)){

    while ($query_row = mysql_fetch_assoc($query_run)){

        $out [] = $query_row;

    }

}
else{
    echo 'Fail';
} 


$query1 = ("SELECT * FROM `City` WHERE `Data_Version` > $data_version");


if ($query_run1 = mysql_query($query1)){

    while ($query_row1 = mysql_fetch_assoc($query_run1)){

        $out1 [] = $query_row1;

    }

}
else{
    echo 'Fail';
} 


$Output=array('dealer'=>$out,'city'=>$out1); 

    echo(json_encode($Output));

?>

So due to the varying formats i am not able to handle it. What is the reason for such varying formats? What should I do to have same kind of results??

因此,由于格式不同,我无法处理它。这种不同格式的原因是什么?我应该怎么做才能得到同样的结果?

Table Schemea

Dealer table "car_make","state","city","company_name","company_address","phone","mobile","fax","email","website","Data_Version"

经销商表“car_make”,“state”,“city”,“company_name”,“company_address”,“phone”,“mobile”,“fax”,“email”,“website”,“Data_Version”

City Table

city, state, Data_Version

city,state,Data_Version

(All fields are Varchar(50) )

(所有字段均为Varchar(50))

Output of printing

输出打印

Array ( [dealer] => Array ( [0] => Array ( [car_make] => [state] => [city] => [company_name] => [company_address] => [phone] => [mobile] => [fax] => [email] => [website] => [Data_Version] => ) )[city] => )

数组([经销商] =>数组([0] =>数组([car_make] => [状态] => [城市] => [company_name] => [company_address] => [手机] => [手机] = > [fax] => [email] => [website] => [Data_Version] =>))[city] =>)

1 个解决方案

#1


0  

It might be possible due to two reasons:-

这有可能是由于两个原因: -

There is no row that match your query in city table so it return null value.

在city表中没有与您的查询匹配的行,因此它返回null值。

In case of dealer table it might be returning a row in which all values are currently null.

在经销商表的情况下,它可能返回一行,其中所有值当前为空。

Please check!

#1


0  

It might be possible due to two reasons:-

这有可能是由于两个原因: -

There is no row that match your query in city table so it return null value.

在city表中没有与您的查询匹配的行,因此它返回null值。

In case of dealer table it might be returning a row in which all values are currently null.

在经销商表的情况下,它可能返回一行,其中所有值当前为空。

Please check!