MySQL and PHP getting the number of rows inserted..

camelCase

The Case of the Mysterious Camel.
Reaction score
362
I couldn't think of a way to describe it from the title, so..
Here's my predicament.

I have a stored procedure.
This stored procedure starts a transaction and inserts a row into table A and a row into table B.
The transaction will insert the rows only if the data meets a certain requirement.

From a PHP script, I call the stored procedure using a prepared statement.
I now have a problem trying to figure out if the transaction inserted any rows or not.

mysqli_stmt_affected_rows() always returns zero; regardless if the transaction succeeded or not.
 

Ghan

Administrator - Servers are fun
Staff member
Reaction score
888
Are you using PDO to prepare your statements? PDOStatement objects have a function to return the number of rows affected.
 

camelCase

The Case of the Mysterious Camel.
Reaction score
362
No, I'm not.
I'm just doing something like:
Code:
$prepared = $conn->prepare($query_calling_stored_procedure);
$prepared->bind_param($some_param, $some_param);
$prepared->execute();
echo mysqli_stmt_affected_rows($prepared); //Always returns zero, no matter what =/
$prepared->close();

I also have another question that's PHP related (but not to this problem).
I kind of want to check if a string input ($_POST/$_GET) is a floating-point type.
Right now, I'm using a preg_match: [ljass]$is_float_input = preg_match("/^[0-9]*.?[0-9]*$/", $s);[/ljass]
The problem is that empty strings count as a floating-point input =/
[ljass]if (preg_match("/^[0-9]*.?[0-9]*$/", "") echo "Empty String Is Floating Point"; //This will echo[/ljass]

I could just check the length of the input with strlen() and then use the preg_match() but I'm wondering if I could do it with just preg_match() alone.
(New to regular expressions)
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top