I know how one can execute MySQL queries / commands from bash:
mysql -u[user] -p[pass] -e "[mysql commands]"
or
mysql -u[user] -p[pass] `<<`QUERY_INPUT [mysql commands] QUERY_INPUT
How can I capture how many rows were affected by the query?
I tried doing:
variable='`mysql -u[user] -p[pass] -e "[mysql commands]"`'
It does execute the command but it does not return the number of affected rows.
mysql_affected_rows() may be called immediately after executing a statement with mysql_real_query() or mysql_query() . It returns the number of rows changed, deleted, or inserted by the last statement if it was an UPDATE , DELETE , or INSERT . For SELECT statements, mysql_affected_rows() works like mysql_num_rows() .
Using MySQLi If you want to fetch all the rows, but still know the number of rows then you can use num_rows or count() .
Put
SELECT ROW_COUNT();
as the last statement in your batch and parse the output
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With