top-think / top-think/think-orm

怎么在同个连接上建临时表,并更新以及查询

Open
#400 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
PHP
Stars
437
Forks
188
PR merge metrics
No merged PRs in 30d

Description

如以下原生语句:
$sql = "select distinct bm,0 as j,0 as w,{$tmpfields} into #order_tmp1 from sn_order_pro,sn_order where sn_order.id=sn_order_pro.orderid and sn_order.consenddate>='$w-01-01' and sn_order.ddlx=1 and sn_order.state>3 order by bm asc";
$data = sqlsrv_query($conn, $sql);
............
............
//写入临时表
//年度统计
$sql = "update #order_tmp1 set #order_tmp1.j=t1.num from #order_tmp1,(select bm,sum(pronumsort) as num from sn_order_pro,sn_order where sn_order.id=sn_order_pro.orderid and year(sn_order.consenddate)=".$j." and sn_order.xn=0 and sn_order.ddlx=1 and sn_order.state>3 group by bm) as t1 where #order_tmp1.bm=t1.bm";
sqlsrv_query($conn, $sql);
............
............
//查询统计
$sql = "select #order_tmp1.bm,sn_pro.proname,sn_pro.cplx, #order_tmp1.
from #order_tmp1 left join sn_pro on sn_pro.bm=#order_tmp1.bm";
$data = sqlsrv_query($conn, $sql);

使用think-orm的Db::execute、Db::query方法均会报:table doesn't exist

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing how the connection is created and reused across Db::execute and Db::query, using the temporary-table SQL shown in the issue as the reproduction. Check whether all three operations run in the same connection session; done means the temporary table can be created, updated, and queried without a “table doesn't exist” error.

Written by the indexing model from the issue text.

Assessment

Tech stack
php, sql
Domain
database
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.