1

I'm new to php and I'm trying to learn how to use stored procedure. I have this stored procedure (mysql):

CREATE DEFINER=`root`@`localhost` PROCEDURE `get_dati_user`(
 IN  v_Mail_UT VARCHAR(45),
 IN  v_PW_UT VARCHAR(20),
 OUT v_Cod_Workgroup VARCHAR(25),
 OUT v_Nome_UT VARCHAR(25),
 OUT v_Cog_UT VARCHAR(25),
 OUT v_Permessi_Utente VARCHAR(45),
 OUT v_Data_Iscrizione VARCHAR(45),
 OUT v_Tel_UT VARCHAR(45),
 OUT v_count int
)
BEGIN

select count(1) into v_count 
from t_utenti where login=v_login and pwd =v_pass;

if (v_count >0) THEN
 SELECT
     `tab01_utenti`.`Cod_Workgroup`,
     `tab01_utenti`.`Nome_UT`,
     `tab01_utenti`.`Cog_UT`,
     `tab01_utenti`.`Permessi_Utente`,
     `tab01_utenti`.`Data_Iscrizione`,
     `tab01_utenti`.`Tel_UT`

  into
  v_Cod_Workgroup,
  v_Nome_UT,
  v_Cog_UT,
  v_Permessi_Utente, 
  v_Data_Iscrizione, 
        v_Tel_UT
  
  FROM tab01_utenti where v_Mail_UT=Mail_UT and v_PW_UT=PW_UT;
END IF;

And I need to write a php script to include in my html login form. Can someone help me please? I already established the connection with the database but I dont get how to continue. I tried with:

<?php  
include 'connectdb.php';
error_reporting(E_ALL);
ini_set('display_errors', 'On');


$sql = 'CALL get_dati_user(?, ?)';
$stmt = $conn->prepare($sql);

// username and password sent from form 
$v_Email_UT=$_POST['v_Email_UT']; 
$v_PW_UT=$_POST['v_PW_UT']; 

$stmt->bindParam(1, $v_Email_UT, PDO::PARAM_STR|PDO::PARAM_INPUT_OUTPUT, 45);
$stmt->bindParam(2, $v_PW_UT, PDO::PARAM_STR|PDO::PARAM_INPUT_OUTPUT, 20);
$stmt->bindParam(3, $v_Cod_Workgroup, PDO::PARAM_STR|PDO::PARAM_INPUT_OUTPUT, 25);
//$stmt->bindParam(4, $v_Nome_UT, PDO::PARAM_STR|PDO::PARAM_INPUT_OUTPUT, 25);
//$stmt->bindParam(5, $v_Cog_UT_UT, PDO::PARAM_STR|PDO::PARAM_INPUT_OUTPUT, 25);
//$stmt->bindParam(6, $v_Permessi_Utente, PDO::PARAM_STR|PDO::PARAM_INPUT_OUTPUT, 45);
//$stmt->bindParam(7, $v_Data_Iscrizione, PDO::PARAM_STR|PDO::PARAM_INPUT_OUTPUT, 45);
//$stmt->bindParam(8, $v_Tel_UT, PDO::PARAM_STR|PDO::PARAM_INPUT_OUTPUT, 45);
//$stmt->bindParam(9, $v_count, PDO::PARAM_INT, 10);

$stmt->execute();



?>

But I get an error "SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens". Can I get some help pls?

  • 1
    Possible duplicate of [SQLSTATE\[HY093\]: Invalid parameter number: number of bound variables does not match number of tokens on line 102](https://stackoverflow.com/questions/20585535/sqlstatehy093-invalid-parameter-number-number-of-bound-variables-does-not-ma) – James May 28 '18 at 11:49
  • 2 question marks in $sql, yet you try to bind 3 params? – delboy1978uk May 28 '18 at 12:05
  • Thanks for the reply. What should I put instead of ?,? I need to pass all the variables – Domenico Schitti May 29 '18 at 08:01

0 Answers0