The execution results of the same SQL statement and php program are different from those of the database.

Source: Internet
Author: User
The execution results of the same SQL statement are different from those of the database. the code for solving the output SQL statement and result set is as follows:
$ SQL = $ sql1. $ SQL _initbest; echo $ SQL; // initRows4 ($ start_date, $ end_date, $ objActSheet); // $ months = getIntMonth ($ start_date, $ end_date1 ); // $ count_1 = 3 * $ months + 3; // There are 3 columns each month // echo $ sql1. $ SQL _initbest; $ query = mssql_query ($ SQL ); // $ c = 0; // $ arr = Array ('A', 'B', 'C', 'D', 'e', 'e', 'F ', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'n', 'O', 'P ', 'q', 'R', 'S', 'T', 'u', 'V', 'W', 'X', 'y ', 'Z'); // $ count_4 = 0; // month counter // $ n = 4; // $ arr1 = array (); while ($ row = mssql_fetch_array ($ query) {print_r ($ row); echo"

";

Note the data in the red box in the output result.

Copy the SQL statement to the database. the execution result is as follows:

I'm sure it's the same SQL statement. why?


Reply to discussion (solution)

Is the data updated from time to time?

1) paste the SQL statement and run it in the mysql editor.
2) output SQL statements in the program and print the result set.

1) paste the SQL statement and run it in the mysql editor.
2) output SQL statements in the program and print the result set.
All of them are on the post and use the ms-SQL database.

Select class2, medium, large, January2014_qn = medium/large, medium, small, February2014_qn = medium/large, medium, large, March2014_qn = Medium/small from (select db_bi.class2, january2014_Number_stores = count (distinct case when left (db_bi.qsq, 6) <= '000000' then db_bi.dbno_bi else null end), SUM (case left (CMD .. pai_xjjx_sale.outdate, 6) when '000000' then CMD .. pai_xjjx_sale.nb else 0 end), February2014_Number_stores = count (distinct case when left (db_bi.qsq, 6) <= '000000' then db_bi.dbno_bi else null end ), february2014_Quantity_sold = SUM (case left (CMD .. pai_xjjx_sale.outdate, 6) when '000000' then CMD .. pai_xjjx_sale.nb else 0 end), March2014_Number_stores = count (distinct case when left (db_bi.qsq, 6) <= '000000' then db_bi.dbno_bi else null end ), march2014_Quantity_sold = SUM (case left (CMD .. pai_xjjx_sale.outdate, 6) when '000000' then CMD .. pai_xjjx_sale.nb else 0 end), April2014_Number_stores = count (distinct case when left (db_bi.qsq, 6) <= '000000' then db_bi.dbno_bi else null end ), april2014_Quantity_sold = SUM (case left (CMD .. pai_xjjx_sale.outdate, 6) when '000000' then CMD .. pai_xjjx_sale.nb else 0 end) from db_bi, CMD .. pai_xjjx_sale, BI_Product_Information where db_bi.dbno = CMD .. pai_xjjx_sale.store and BI_Product_Information.colthno = CMD .. pai_xjjx_sale.colthno and CMD .. export _xjjx_sale.outdate> = '2017-01 'and CMD .. pai_xjjx_sale.outdate <= '2017-04 'and charindex ('withdrawn', db_bi.names) = 0 and db_bi.class2 in ('A', 'B', 'C', 'o ') and closeif <> 1 and flags_bi in ('1', '2', '3', '4') and CMD .. pai_xjjx_sale.endprice <> 0 group by db_bi.class2) a order by class2

When class2 is set to B or C, the corresponding values are different.
Are you sure the table data has not changed?

Is the data updated from time to time?
Data is not updated in real time

When class2 is set to B or C, the corresponding values are different.
Are you sure the table data has not changed?
The value of class2 is different from that of B and C. It can be determined that the table data has not changed.

This is a tragedy... several of them are the same SQL program and the results executed directly in the database compiler are different (it is determined that the database is not updated in real time)
Test the following code:

 = '1970-01' and CMD .. pai_xjjx_sale.outdate <= '2017-04 'and charindex ('withdrawn', db_bi.names) = 0 and db_bi.class2 in ('A', 'B', 'C', 'o ') and closeif <> 1 and flags_bi in ('1', '2', '3', '4') and CMD .. pai_xjjx_sale.endprice <> 0 group by db_bi.class2) aorder by class2 "; $ query = mssql_query ($ SQL); while ($ row = mssql_fetch_array ($ query) {print_r ($ row ); echo"

";}?>

Result

Check whether the database is the same
Php is not used to query the database in use (the value is larger), while the console is used to query the backup database.

Check whether the database is the same
Php is not used to query the database in use (the value is larger), while the console is used to query the backup database.
It is determined that it is the same database and several similar problems have been found. The execution results of the same SQL statement using programs are different from those directly executed on the console.

Check whether the database is the same
Php is not used to query the database in use (the value is larger), while the console is used to query the backup database.
Found the cause, and found this sentence in SQL

And charindex ('withdrawn ', db_bi.names) = 0

This condition does not work when the php program queries the database. it cannot be changed to not like. how can this problem be solved?

Solved the problem of changing 'withdrawn'
". Iconv ('utf-8', 'gbk', 'withdrawn ')."

I think you have different time conditions.

Check whether the database is the same
Php is not used to query the database in use (the value is larger), while the console is used to query the backup database.
Ask another question
When exporting the data to an excel file, I used the number_format function to process the data. then, the final sum called the sum function ru of excel.

$objActSheet->setCellValue($arr[$j].$n,"=SUM($x1:$x2)");

The result of the sum is incorrect, as shown below.

How can we ensure that the data format and sum result are correct?

Do not use the number_format function to format data.
The cell format should be used for control, such

$sheet->getStyle('D6')            ->getNumberFormat()            ->setFormatCode('#,##0');

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.