开发者

query execution error check

开发者 https://www.devze.com 2023-02-19 02:19 出处:网络
hello please help me out regarding this function function delete($serviceid) { $result = $this->query=(\"delete from service where service_id=\'$serviceid\'\");

hello please help me out regarding this function

  function delete($serviceid) 
    {
    $result = $this->query=("delete from service where service_id='$serviceid'");
    $exe=$this->executeNonQuery();
    if ($exe){
    return $success = "Record deleted successfully.";
    } else {
    return $error = "Unable to process at this time.开发者_开发技巧";
    }
    }

$exe is always 1 even if the record is not deleted as may b its because of , it only check that query is executed or not , how can i check if the record is deleted then show success message


I don't know what DB class you are using, but there are generally separate methods for accessing the number of affected rows, and whether or not the command was 'successful' (only from the viewpoint of the DB interface).

Look for something in your API documentation for number of affected rows or something similar.

If you could post more details, we can give you a specific answer.

EDIT: Now that we know you are using mysqli, you can use mysql->affected_rows() to get the number of rows deleted. See http://php.net/manual/en/mysqli.affected-rows.php

function affectedRows() {
    return mysqli_affected_rows($this->conn);
}

Add that to your "Person" class.

And then, switch to PDO and prepared statements. What you are doing is very insecure.


check for mysql_affected_rows()

Reference


We definitely need more information on the class that $this is an instance of in order to know how it's query functions work. However, if that class is using a mysql connection, the mysql_affected_rows() function should return the number of rows that were deleted.

A quick test would be to substitute that function instead of checking the value of $exe:

if (mysql_affected_rows()){
   return $success = "Record deleted successfully.";
}

Check this out for more details: http://us2.php.net/mysql_affected_rows

0

精彩评论

暂无评论...
验证码 换一张
取 消