English 中文(简体)
如何知道在 Mysql 中删除的行数?
原标题:How to know the number of rows deleted in mysql?

如何知道代码符中删除的行没有行, 前提是 $this- gt; db- gt; db- gt; effect_ rows () 每次在成功或失败时返回 < code> 。

最佳回答

如何知道代码编辑器中删除的行没有删除的行, 前提是 $this- gt; db- gt; db- gt; effect_ rows () 每次在成功或失败时也返回 $this- gt; db- gt; effect_ rows () 。

我不使用 CodeIgniter, 但通常情况下, impacted_rows () 应该返回受影响的行数。 这意味着, 如果查询成功, 它应该 ways 是一个整数。 如果返回 0, 如果 & gt; 0, 则不删除行数 。

问题回答
$this->db->where($conditions)->delete( mytable );
return $this->db->affected_rows(); 

您是否测试过它, 根据代码编辑网站, 有一个黑客返回正确的行数, 默认打开。

http://codigniter.com/user_guide/database/ helps.html

根据Codigniter 用户guide ,它返回正确的行数:

"Note: In MySQL "DELETE FROM TABLE" returns 0 affected rows. The database class has a small hack that allows it to return the correct number of affected rows. By default this hack is enabled but it can be turned off in the database driver file."

因此,这项工作应:

 $this->db->delete( 1 ,  your_table );
 echo ($this->db->affected_rows()." rows were deleted");

如果它不起作用,那么就做做一个非理想的变通办法

$count = $this->db->count_all( your_table );
$this->db->delete( 1 ,  your_table );
$new_count = $this->db->count_all( your_table );
if ($new_count > $count)
{
    echo (($new_count-$count)." rows was deleted");
}
else
{
    echo "nothing deleted";
}

That would help if you were more specific, with example... But you can perform a SELECT COUNT(*) before deletion and after and compare the two results.





相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

php return a specific row from query

Is it possible in php to return a specific row of data from a mysql query? None of the fetch statements that I ve found return a 2 dimensional array to access specific rows. I want to be able to ...

Character Encodings in PHP and MySQL

Our website was developed with a meta tag set to... <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> This works fine for M-dashes and special quotes, etc. However, I ...

Pagination Strategies for Complex (slow) Datasets

What are some of the strategies being used for pagination of data sets that involve complex queries? count(*) takes ~1.5 sec so we don t want to hit the DB for every page view. Currently there are ~...

Averaging a total in mySQL

My table looks like person_id | car_id | miles ------------------------------ 1 | 1 | 100 1 | 2 | 200 2 | 3 | 1000 2 | 4 | 500 I need to ...