thinkphp插入数据库操作错误
thinkphp MySQL 数据库
thinkphp从excel读取数据插入mysql,生成sql语句正确,单独能执行,用$model->execute($sql),执行时,凡是字符串都只插入了首字符。生成sql语句是这样 insert into table values('','ABCDEF'),没有列举完,只是举例,单独执行插入成功,在thinkphp里面执行,字符串ABCDEF只插入了一个A。在tp里面打印出最后执行的sql语句也是对的
回复讨论(解决方案)
直接执行也是同样的结果吗? 我本来还以为会是数据库字段类型和长度限制了 要是直接执行也这样 那得追踪到TP的最终mysql_query的地方检察mysql_query之前的$sql
直接执行也是同样的结果吗? 我本来还以为会是数据库字段类型和长度限制了 要是直接执行也这样 那得追踪到TP的最终mysql_query的地方检察mysql_query之前的$sql
能说详细一些吗?谢谢你
直接执行也是同样的结果吗? 我本来还以为会是数据库字段类型和长度限制了 要是直接执行也这样 那得追踪到TP的最终mysql_query的地方检察mysql_query之前的$sql
能说详细一些吗?谢谢你
其实是你这边应该描述的详细一点
没有无解的"灵异问题" 一定是哪里有问题
依我浅见,或者是TP对SQL语句的处理出了问题,或者是mysql的数据结构/类型有问题. 没能想出其他可能
所以先试试手动写SQL语句直接在mysql执行, 看看结果,你现在说插入成功,插入后的结果呢?也是想要的吗?
如果手动插入结果正确 那就在TP框架内顺藤摸瓜找到TP插入mysql的语句 将此时的SQL语句打印出来 看跟你手写的SQL语句是否一致.
然后才好进一步看....
当然,可能有大神遇到过这种问题能一下指出原因 不过在此之前可以先试试这样找找原因
其实是你这边应该描述的详细一点
$res = $order_insert->execute($sql);
echo $order_insert->getLastSql();
在执行execute的时候,$sql是正常的,复制出来单独执行,结果也是想要的。 当执行完,用$order_insert->getLastSql();获取最后一条执行的sql语句,sql语句也是正常的,对这个sql字符串直接复制到execute执行也是能正常插入数据,就是当做参数执行时,出现上面说的情况
你怎么不在当做参数执行时,也看一下 $order_insert->getLastSql() 呢 其实是你这边应该描述的详细一点
$res = $order_insert->execute($sql);
echo $order_insert->getLastSql();
在执行execute的时候,$sql是正常的,复制出来单独执行,结果也是想要的。 当执行完,用$order_insert->getLastSql();获取最后一条执行的sql语句,sql语句也是正常的,对这个sql字符串直接复制到execute执行也是能正常插入数据,就是当做参数执行时,出现上面说的情况
你怎么不在当做参数执行时,也看一下 $order_insert->getLastSql() 呢
看了的,就是把组装出来的sql语句当做参数给execute,然后执行后,再获取最后一条执行的sql语句,打印出来是完整的sql语句 insert into table value('','ABCDEF');这样的语句,但是数据库的表里面对应ABCDEF这个字符只插入了一个字符A
这个会不会是数据库的字段问题啊,直接把sql在mysql执行还会这样?
这个会不会是数据库的字段问题啊,直接把sql在mysql执行还会这样?
不是字段问题哈,直接执行插入是正常的!
已经找到问题,是读取excel的时候,要加一句setOutputEncoding

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



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-

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.

PHP logging is essential for monitoring and debugging web applications, as well as capturing critical events, errors, and runtime behavior. It provides valuable insights into system performance, helps identify issues, and supports faster troubleshoot

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' =>

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

Article discusses late static binding (LSB) in PHP, introduced in PHP 5.3, allowing runtime resolution of static method calls for more flexible inheritance.Main issue: LSB vs. traditional polymorphism; LSB's practical applications and potential perfo

The article discusses adding custom functionality to frameworks, focusing on understanding architecture, identifying extension points, and best practices for integration and debugging.

Alipay PHP...
