jquery-file-upload 的php mysql插入问题
最近用jquery-file-upload 来改善网站上传的体验
https://github.com/blueimp/jQuery-File-Upload/wiki/PHP-MySQL-database-integration
上传时按照他的参考文档,立马就完成了,一开始也按照他的sql 架构先试试
结果上传后,也能成功插入,json传回页面一切正常!
但问题来了,他的sql 架构...有个叫url
但作者好像在PHP的SQL中没有处理
那我就改改吧,....
先新增了一些基本配置
$dir = $_COOKIE["uid"].'/'.date("Y").'/'.date("m").'/'.date("d").'/';$dirUP = "../../../att/".$dir;$dirLink = $dir;$options=array( 'upload_dir' => $dirUP, 'upload_url' => $dirLink, 'delete_type' => 'POST', 'db_host' => 'localhost', 'db_user' => 'root', 'db_pass' => '*****', 'db_name' => '*****', 'db_table' => 'files');
应该就是这段了....
我尝试多次,加入url字段都不成功 [原本的文档代码]
protected function handle_file_upload($uploaded_file, $name, $size, $type, $error, $index = null, $content_range = null) { $file = parent::handle_file_upload( $uploaded_file, $name, $size, $type, $error, $index, $content_range ); if (empty($file->error)) { $sql = 'INSERT INTO `'.$this->options['db_table'] .'` (`name`, `size`, `type`, `title`, `description`)' .' VALUES (?, ?, ?, ? , ?)'; $query = $this->db->prepare($sql); $query->bind_param( 'sisss', $file->name, $file->size, $file->type, $file->title, $file->description ); $query->execute(); $file->id = $this->db->insert_id; } return $file; }
都给我显示:
Warning: mysqli_stmt::bind_param(): Number of elements in type definition string doesn't match number of bind variables in
这是什么意思,说我的数量有问题? 是指我加少了吗?
我已经改成...这样,5处的type字段也都加了url也说是数量问题?
protected function handle_file_upload($uploaded_file, $name, $size, $type,$url, $error, $index = null, $content_range = null) { $file = parent::handle_file_upload( $uploaded_file, $name, $size, $type,$url, $error, $index, $content_range ); if (empty($file->error)) { $sql = 'INSERT INTO `'.$this->options['db_table'] .'` (`name`, `size`, `type`, `url`, `title`, `description`)' .' VALUES (?, ?, ?, ?,? , ?)'; $query = $this->db->prepare($sql); $query->bind_param( 'sisss', $file->name, $file->size, $file->type, $file->url, $file->title, $file->description ); $query->execute(); $file->id = $this->db->insert_id; } return $file; }
我需要保存成
$url = $_COOKIE["uid"].'/'.date("Y").'/'.date("m").'/'.date("d").'/'. filename
要怎么改? 直接用$file->url就可以吗?
另外...因为这玩意,还弄到一个append取值问题,熟jq的朋友也可以去这帮帮小弟吧
http://bbs.csdn.net/topics/390862894
回复讨论(解决方案)
警告:mysqli_stmt::bind_param():在类型定义字符串不匹配的绑定变量的元素个数
这还不清楚吗?
$query->bind_param(
' sisss', //怎么只有 5 个类型声明?
$file->name, //1
$file->size, //2
$file->type, //3
$file->url, //4
$file->title,//5
$file->description //6 共6个
);
警告:mysqli_stmt::bind_param():在类型定义字符串不匹配的绑定变量的元素个数
这还不清楚吗?
$query->bind_param(
' sisss', //怎么只有 5 个类型声明?
$file->name, //1
$file->size, //2
$file->type, //3
$file->url, //4
$file->title,//5
$file->description //6 共6个
);
喔...原来这个问题
已成功解决了!
以前用完mysql_query后就转用pdo了,没用过mysqli,PDO好像就没怎么提过这写法
谢谢,学习了

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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

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











MySQL and phpMyAdmin are powerful database management tools. 1) MySQL is used to create databases and tables, and to execute DML and SQL queries. 2) phpMyAdmin provides an intuitive interface for database management, table structure management, data operations and user permission management.

What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

Compared with other programming languages, MySQL is mainly used to store and manage data, while other languages such as Python, Java, and C are used for logical processing and application development. MySQL is known for its high performance, scalability and cross-platform support, suitable for data management needs, while other languages have advantages in their respective fields such as data analytics, enterprise applications, and system programming.

Article summary: This article provides detailed step-by-step instructions to guide readers on how to easily install the Laravel framework. Laravel is a powerful PHP framework that speeds up the development process of web applications. This tutorial covers the installation process from system requirements to configuring databases and setting up routing. By following these steps, readers can quickly and efficiently lay a solid foundation for their Laravel project.

IIS and PHP are compatible and are implemented through FastCGI. 1.IIS forwards the .php file request to the FastCGI module through the configuration file. 2. The FastCGI module starts the PHP process to process requests to improve performance and stability. 3. In actual applications, you need to pay attention to configuration details, error debugging and performance optimization.

In MySQL, the function of foreign keys is to establish the relationship between tables and ensure the consistency and integrity of the data. Foreign keys maintain the effectiveness of data through reference integrity checks and cascading operations. Pay attention to performance optimization and avoid common errors when using them.

Safely handle functions and regular expressions in JSON In front-end development, JavaScript is often required...

The main difference between MySQL and MariaDB is performance, functionality and license: 1. MySQL is developed by Oracle, and MariaDB is its fork. 2. MariaDB may perform better in high load environments. 3.MariaDB provides more storage engines and functions. 4.MySQL adopts a dual license, and MariaDB is completely open source. The existing infrastructure, performance requirements, functional requirements and license costs should be taken into account when choosing.
