Greetings!
Here is my stored procedure
IF EXISTS (
SELECT *
FROM guidance.dbo.vw_brw_StudentInfo
WHERE stud_nID = @ID
AND stud_sLastName = @LastName
AND stud_sFirstName =@Firstname
AND datediff(d,stud_dBirthDate,@bday) =0
)
INSERT INTO guidance.tbl_regStudent
(stud_id,passwords,stud_email,acode)
VALUES (@ID,@email,@email,@regcode)
END
And my php is
$st = $this->db->prepare("USE guidance EXEC guidance.CheckStudentExist {$sql}");
$attribute_value = array();
foreach($attributes as $key => &$value) {
$k = ':'.$key;
echo $key.' '.$value.'<br/>';
$attribute_value[] = $st->bindParam($k, $value, PDO::PARAM_STR);
}
$val = join("<br/> ", $attribute_value);
$st->execute();
$st->nextRowset();
$col = $st->fetchColumn();
if ($col >0)
{
echo 'Existing ';
}
else { echo 'not exist';}
My problem is it always print 'not exist' even if my data is correct and my insert query is executed.
These are my attempts:
- I added $st->nextRowset()
because it fixed the error ‘he active result for the query contains no fields’. - When I test my queries in SQL 2008 R2, there is error that says ‘Invalid object name.’
- I am expecting that my fetchcolumn returns an int value. I choose IF EXIST over COUNT.
Any idea? thank you.