This question already has answers here:
How to test if a MySQL query was successful in modifying database table data?
(5 answers)
Closed 1 year ago.
I created function that delete some data from my database. This is part of it:
mysqli_query($con, "DELETE FROM appsdata WHERE ownerID=123");
But I want to check how many rows were deleted. Mysql_query returns always true, no matter if something was deleted :/
You can use mysqli_affected_rows:
mysqli_affected_rows($mysqli_link);
or
$mysqli->affected_rows
http://php.net/manual/en/mysqli.affected-rows.php
Related
This question already has answers here:
mysqli_insert_id: What if someone inserts another row just before I call this?
(2 answers)
Closed 6 years ago.
is it safe to use mysqli_insert_id() when the database is heavily used and more than one id maybe inserted in the same time, or it will get only the id that inserted by a query from this user..
mysqli_insert_id() is specific to the database connection , it returns the ID of the row which you inserted most recently.
This question already has an answer here:
MySQL and the chance of the wrong id being returned by LAST_INSERT_ID()
(1 answer)
Closed 8 years ago.
I've a database with hundreds of records which inserted in each seconds, I have the below insert query and I want to know the insert id of this query:
$currQuery = $pdo->prepare("INSERT INTO some_table (...... )");
$currQuery->execute("....");
$queryInsertId = $pdo->lastInsertId();
I just want to know that is it safe to use lastInsertId() while I having hundreds of new records in every seconds? any ideas?
Yes it is safe. It returns the last insert id for the connection.
This question already has answers here:
How can I make sure that PDO's lastInsertId() is not that of another simultaneous insert?
(2 answers)
can I trust mysql_insert_id() to return correct value, multithreading paranoia
(2 answers)
Closed 8 years ago.
in PHP if I use
$last_id = $db->lastInsertId();
The variable $last_id does will get the value of the last row I've inserted in that instance or the latest row of the entire db?
if there are many users that connect and update database at the same time, the last id that I need in my application, will probably not fill the same as the latest of entire db.
Thanks in advance for response.
$last_id = $db->lastInsertId(); returns last inserted id for this DB conection.remember PDO will always return you the last ID inserted by the current active database connection.
This question already has answers here:
UPDATE/DELETE in mysql and get the list of affected row ids?
(3 answers)
Closed 9 years ago.
Title pretty much says it. I am using the deprecated mysql_ functions. I've got a query like:
UPDATE `table`
SET `row` = 'newtext'
WHERE `row` = 'oldtext'
Is there an easy way to get all effected row's primary key? Some glorious combination of mysql_insert_id and mysql_affected_rows? How can I do this without looping and doing each update one row at a time?
As a solution to your problem please refer the following sample code snippet
UPDATE `table` SET `row` = 'newtext' WHERE `row` = 'oldtext'
select id from table where row='oldtext'
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
PHP: how to get last inserted ID of a table?
I use mysql_query() in PHP to insert a new record in my Database.
It will auto generate a row, with a user Id, can I use the result to get that Id?
mysql_insert_id()
Have you considered upgrading to PDO?