dongxianshuai8927 2012-06-05 16:26
浏览 39
已采纳

通过php调用存储过程奇怪的错误

I have been coding a registration page(login system) in php and mysql for a website. I'm using two stored procedures for the same. First stored procedure checks wether the email address already exists in database.Second one inserts the user supplied data into mysql database. User has EXECUTE permission on both the procedures.When is execute them individually from php script they work fine. But when i use them together in script second Stored procedure(insert) not working.

Stored procedure 1.

DELIMITER $$
CREATE PROCEDURE reg_check_email(email VARCHAR(80))
BEGIN
SET @email = email;
SET @sql = 'SELECT email FROM user_account WHERE user_account.email=?';
PREPARE stmt FROM @sql;
EXECUTE stmt USING @email;
END$$
DELIMITER;

Stored procedure 2

DELIMITER $$
CREATE PROCEDURE reg_insert_into_db(fname VARCHAR(40), lname VARCHAR(40), email      VARCHAR(80), pass VARBINARY(32), licenseno VARCHAR(80), mobileno VARCHAR(10))
BEGIN
SET @fname = fname, @lname = lname, @email = email, @pass = pass, @licenseno =    licenseno, @mobileno = mobileno;
SET @sql = 'INSERT INTO user_account(email,pass,last_name,license_no,phone_no)    VALUES(?,?,?,?,?)';
PREPARE stmt FROM @sql;
EXECUTE stmt USING @email,@pass,@lname,@licenseno,@mobileno;
END$$
DELIMITER;

When i test these from php sample script insert is not working , but first stored procedure(reg_check_email()) is working. If i comment off first one(reg_check_email), second stored procedure(reg_insert_into_db) is working fine.

 <?php
 require("/wamp/mysql.inc.php");
 $r = mysqli_query($dbc,"CALL reg_check_email('ravi@gmail.com')");
 $rows = mysqli_num_rows($r);
 if($rows == 0) {
     $r = mysqli_query($dbc,"CALL   reg_insert_into_db('a','b','ravi@gmail.com','c','d','e')");
     }
 ?>

i'm unable to figure out the mistake.

Thanks in advance, ravi.

  • 写回答

1条回答 默认 最新

  • doulie0178 2012-06-05 16:55
    关注

    I faced the similar kind of issues, while executing stored procedures and queries using php script.

    You should try mysqli_multi_query for executing your SPs.
    After calling procedures. use mysqli_free_result to consume results.
    You can refer this link as well. Hope, it'll help you.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制