user1658035
user1658035

Reputation: 21

PHP prepared statement always returns 1

I tryed to call a function from a prepared Statement

stmt= $conn->prepare("SELECT create_user(?,?,?)");
$tt="test";
$stmt->bind_param("sss",$tt,$tt,$tt);
$stmt->execute();
echo "RETURN VALUE".$stmt->fetch();

the returnvalue shouldn't be 1 the function is working if i call it that way directly in mysql console the function is working correctly and is also applying the changes but the return value is allways 1 no matter what it's returning on the console I tried to execute another Statement to check if there is a mistake in my function there are 4 rows in the table

$stmt=$conn->prepare("SELECT Count(Name) from users");
$stmt->execute();
echo $stmt->fetch();

the result is the (it's 1 again) same if i do $stmt->store_result(); before fetching the result I'm working with mySQL DB

Upvotes: 0

Views: 228

Answers (1)

miglio
miglio

Reputation: 2058

you have to try something like this:

$stmt=$conn->prepare("SELECT Count(Name) as count from users");
$stmt->execute();
$stmt->bind_result($count);
$stmt->fetch();
echo $count

Upvotes: 4

Related Questions