Herdy
Herdy

Reputation: 179

call mysql procedure using PDO got general error

Hello i have question about PDO, i have a mysql procedure like this :

CREATE PROCEDURE `user_regis`(IN `name` VARCHAR(50), IN `hp` VARCHAR(12), IN `email` VARCHAR(30), IN `username` VARCHAR(20), IN `password  VARCHAR(20) )

    BEGIN

        IF (SELECT NOT EXISTS (SELECT * FROM USER WHERE USER_USERNAME = username AND USER_EMAIL = email)) THEN

            INSERT INTO USER
              (USER_ID, USER_NAME, USER_HP, USER_EMAIL, USER_USERNAME, USER_PASSWORD) 
            VALUES 
              (null,name,hp,email,username,password) ;

            INSERT INTO `VOUCHER`(`VOUCHER_CODE`, `USER_USERNAME`, `VOUCER_STATUS`, `VOUCHER_EXPIRY`) 
            VALUES((SELECT CONCAT('TRVL',ROUND(RAND()*1000000))),username,1,(SELECT NOW() + INTERVAL 48 HOUR) ) ;

            SELECT * FROM USER WHERE USER_USERNAME = username ;

        END IF;

    END

and then i call my procedure using PDO :

$regis = $this->pdo->query('call user_regis(a,a,a,a,a)');
if($regis->fetchColumn > 0){ echo "hai" ; }

but i got an error :

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error in

can someone explain me why ? thanks for your help

Upvotes: 0

Views: 149

Answers (1)

erik258
erik258

Reputation: 16304

Based on our conversation in comments, I think you should move the SELECT down below the END IF line so it's executed regardless of whether the IF condition is met.

You'll also have to provide whatever required parameters to the stored procedure.

Upvotes: 0

Related Questions