Mysql
 sql >> Database >  >> RDS >> Mysql

PHP mysqli ha preparato l'istruzione per la procedura memorizzata senza parametro

Il modo in cui le stored procedure funzionano con le istruzioni preparate è un po' più complicato. Manuale PHP afferma che devi usare le variabili di sessione (sessioni MySQL, non PHP)

Quindi potresti farlo con

$connect=&ConnectDB();
// bind the first parameter to the session variable @uid
$stmt = $connect->prepare('SET @uid := ?');
$stmt->bind_param('s', $uid);
$stmt->execute();

// bind the second parameter to the session variable @userCount
$stmt = $connect->prepare('SET @userCount := ?');
$stmt->bind_param('i', $userCount);
$stmt->execute();

// execute the stored Procedure
$result = $connect->query('call IsUserPresent(@uid, @userCount)');

// getting the value of the OUT parameter
$r = $connect->query('SELECT @userCount as userCount');
$row = $r->fetch_assoc();               

$toRet = ($row['userCount'] != 0);

Osservazione:

Consiglio di riscrivere questa procedura come una funzione con un parametro IN che restituisce INT.