数据库批量写入判断问题
我所做的功能是一个订单导入的功能,就把xls里面的数据导入到mysql,每次1000条左右.
现在的问题是,每一条记录有个编码,我先要查一下这个编码系统中有没有建好,建好的,就导入,如果没有建好就这一整批都不导入系统,请问应该怎么做呢??
回复讨论(解决方案)
没看明白,每条记录一个编码,但是这个编码没有建好,怎么就一整批不能导入,不是这条不能导入吗?
如果是我想的那一条不能导入,可以这样做:
先把那1000条数据从XLS文件里读出,同时把编码表从数据库读出,以编码为主键建立一个数组,然后循环读取你那1000条数据,每次用这条数据的编码查找编码数组中是否存在,不存在则跳过,存在则保存入数据库。当然你可以编写SQL语句最后一次性保存。
jzh2004大大能不能详细说明一下啊
我再说一下,我们会从网上下载一个订单明细下来,就是每天销售的订单明细,每条记录里面有个物料编码,我做的这个页面就是把订单明细导入到一个PHP ERP系统里面,但是有时候新的物料同事会忘记在ERP里面添加上去。我就是想做个判断,先判断订单明细里面这1000条记录,在ERP系统里面是不是全部都有,只要一个没有都就停止导入。
纯粹是没事找事,自找麻烦!
实现起来很简单,对于每条内容
先检查编码是否存在(select)
根据结果再插入(insert)
显然你们的系统使用了外键(纯属自己给自己造麻烦)
其实直接插入也没有关系,反正不是出错就是插入无效

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Long URLs, often cluttered with keywords and tracking parameters, can deter visitors. A URL shortening script offers a solution, creating concise links ideal for social media and other platforms. These scripts are valuable for individual websites a

Following its high-profile acquisition by Facebook in 2012, Instagram adopted two sets of APIs for third-party use. These are the Instagram Graph API and the Instagram Basic Display API.As a developer building an app that requires information from a

Laravel simplifies handling temporary session data using its intuitive flash methods. This is perfect for displaying brief messages, alerts, or notifications within your application. Data persists only for the subsequent request by default: $request-

This is the second and final part of the series on building a React application with a Laravel back-end. In the first part of the series, we created a RESTful API using Laravel for a basic product-listing application. In this tutorial, we will be dev

Laravel provides concise HTTP response simulation syntax, simplifying HTTP interaction testing. This approach significantly reduces code redundancy while making your test simulation more intuitive. The basic implementation provides a variety of response type shortcuts: use Illuminate\Support\Facades\Http; Http::fake([ 'google.com' => 'Hello World', 'github.com' => ['foo' => 'bar'], 'forge.laravel.com' =>

The PHP Client URL (cURL) extension is a powerful tool for developers, enabling seamless interaction with remote servers and REST APIs. By leveraging libcurl, a well-respected multi-protocol file transfer library, PHP cURL facilitates efficient execution of various network protocols, including HTTP, HTTPS, and FTP. This extension offers granular control over HTTP requests, supports multiple concurrent operations, and provides built-in security features.

Do you want to provide real-time, instant solutions to your customers' most pressing problems? Live chat lets you have real-time conversations with customers and resolve their problems instantly. It allows you to provide faster service to your custom

The 2025 PHP Landscape Survey investigates current PHP development trends. It explores framework usage, deployment methods, and challenges, aiming to provide insights for developers and businesses. The survey anticipates growth in modern PHP versio
