0

hi,
I hav a created a field with unique constraint, so if it got duplicated error must be returned from procedure. Wats wrong here?

$dbconn = new DbConn;
		$dbc = $dbconn->Fn_CreateDbConn();
		$Qry = $dbc->prepare("CALL CMS_School_Insert(:SchoolID,:SchoolName)");	
		$Qry -> bindParam(":SchoolID",$SchoolID);
		$Qry -> bindParam(":SchoolName",$SchoolName);
                try
                {
		    $Qry -> execute();
                 }catch(PDOException $e)
                  {
                      return "Error: ".$e->getMessage();
                  }

Here s my procedure

DELIMITER //

CREATE DEFINER=`root`@`localhost` PROCEDURE `CMS_School_Insert`(_SchoolID INT, _SchoolName VARCHAR(100))
BEGIN
    IF (SELECT COUNT(*) FROM CMT_School WHERE School_ID=_SchoolID) = 0 THEN
        INSERT INTO CMT_School (School_Name) VALUES (_SchoolName);
    ELSE
        UPDATE CMT_School SET School_Name=_SchoolName WHERE School_ID=_SchoolID;
    END IF;
END//
2
Contributors
1
Reply
2
Views
5 Years
Discussion Span
Last Post by pritaeas
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.