PHP调用MYSQL存储过程 不报错的解决方法
前两天跟同事一起开发一套库存管理系统,我负责写页面程序,同事负责写存储过程,写程序时一切进展很顺利,直到开发完成,我用PHP调用他的存储过程时问题发生了。
以后开发时需要注意以下几点:
1、连接MYSQL数据库时要注意后两个参数
define('CLIENT_MULTI_RESULTS', 131072); //定义常量
$conn=mysql_connect("localhost","root","123456",1,CLIENT_MULTI_RESULTS);
$db=mysql_select_db("db01",$conn);
2、调用存储过程方法
很简单共有两种方法
(1)无返回值
mysql_query("call nj_keep_accounts_sp($id)",$conn); // 存储过程名称: nj_keep_accounts_sp 参数:$id
(2)有返回值
$id=$_GET["id"];
$r=mysql_query("call nj_keep_accounts_sp($id)",$conn);
while($rs=@mysql_fetch_array($r)){
echo($rs["t_id"]);
}
3、如果调试的时不报错,经常执行不稳定,一会好用一会不好用请注意
我在测试的时候发生过这种事情,发现代码本身无错误,存储过程在MYSQL里执行也没有出错,问题发生在哪呢?
经过两天的测试最终发现,写存储过程的时候调试过程中在执行开始、中间、结尾部份都加了测试返回值。问题就发生在这里。
我把没用的返回值(如:select @a)类似这种代码全注释之后才发现以前的问题全部解决了,程序也好用了。
摘自 newsera

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











session_start()iscrucialinPHPformanagingusersessions.1)Itinitiatesanewsessionifnoneexists,2)resumesanexistingsession,and3)setsasessioncookieforcontinuityacrossrequests,enablingapplicationslikeuserauthenticationandpersonalizedcontent.

In MySQL, add fields using ALTERTABLEtable_nameADDCOLUMNnew_columnVARCHAR(255)AFTERexisting_column, delete fields using ALTERTABLEtable_nameDROPCOLUMNcolumn_to_drop. When adding fields, you need to specify a location to optimize query performance and data structure; before deleting fields, you need to confirm that the operation is irreversible; modifying table structure using online DDL, backup data, test environment, and low-load time periods is performance optimization and best practice.

MySQL functions can be used for data processing and calculation. 1. Basic usage includes string processing, date calculation and mathematical operations. 2. Advanced usage involves combining multiple functions to implement complex operations. 3. Performance optimization requires avoiding the use of functions in the WHERE clause and using GROUPBY and temporary tables.

Installing MySQL on macOS can be achieved through the following steps: 1. Install Homebrew, using the command /bin/bash-c"$(curl-fsSLhttps://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)". 2. Update Homebrew and use brewupdate. 3. Install MySQL and use brewinstallmysql. 4. Start MySQL service and use brewservicesstartmysql. After installation, you can use mysql-u

To safely and thoroughly uninstall MySQL and clean all residual files, follow the following steps: 1. Stop MySQL service; 2. Uninstall MySQL packages; 3. Clean configuration files and data directories; 4. Verify that the uninstallation is thorough.

Efficient methods for batch inserting data in MySQL include: 1. Using INSERTINTO...VALUES syntax, 2. Using LOADDATAINFILE command, 3. Using transaction processing, 4. Adjust batch size, 5. Disable indexing, 6. Using INSERTIGNORE or INSERT...ONDUPLICATEKEYUPDATE, these methods can significantly improve database operation efficiency.

Composer is a dependency management tool for PHP, and manages project dependencies through composer.json file. 1) parse composer.json to obtain dependency information; 2) parse dependencies to form a dependency tree; 3) download and install dependencies from Packagist to the vendor directory; 4) generate composer.lock file to lock the dependency version to ensure team consistency and project maintainability.

The reasons why MySQL is widely used in various projects include: 1. High performance and scalability, supporting multiple storage engines; 2. Easy to use and maintain, simple configuration and rich tools; 3. Rich ecosystem, attracting a large number of community and third-party tool support; 4. Cross-platform support, suitable for multiple operating systems.
