simplyi Posted January 13, 2010 Share Posted January 13, 2010 After running a Prepared Statement to insert to data into database. What is the best way and quick way to check if the row has been affected and data is recorder or updated? Example: $sql = "INSERT INTO news (title) VALUES (?)"; $statement = $this->conn->prepare($sql); if(!$statement) throw new Exception($statement->error) ; $statement->bind_param("s",$newsVO->title); $returnValue = $statement->execute(); As far as I understand a statement can be executed for Insert and return value would be ‘1’. But does it actually mean that the value is inserted? Or it means that the statement is executed successfully? With Prepared Statements is there a num_rows_effected() method to learn that rows have actually been effected? Thank you! Link to comment https://forums.phpfreaks.com/topic/188390-statement-execute-is-there-a-num_rows_effected-method/ Share on other sites More sharing options...
trq Posted January 13, 2010 Share Posted January 13, 2010 What DAO are you using? Link to comment https://forums.phpfreaks.com/topic/188390-statement-execute-is-there-a-num_rows_effected-method/#findComment-994536 Share on other sites More sharing options...
simplyi Posted January 13, 2010 Author Share Posted January 13, 2010 Hi thorpe! Thank you for your reply. I do not know what exactly you mean by what DAO do I use... but here is connection code from my Data Access Object. public function openConnection() { $this->conn = new mysqli($this->dbhost, $this->dbuser, $this->dbpass,$this->dbname); if( mysqli_connect_errno( ) ) throw new Exception( SERVER_ERROR . ( DEBUG ? ' error: ' . mysqli_connect_error( ) : '' ) ) ; } I user mysqli to work with MySQL database from PHP. Link to comment https://forums.phpfreaks.com/topic/188390-statement-execute-is-there-a-num_rows_effected-method/#findComment-994538 Share on other sites More sharing options...
trq Posted January 13, 2010 Share Posted January 13, 2010 You are using the mysqli extension within some wrapper. mysqli provies mysqli_num_rows. Link to comment https://forums.phpfreaks.com/topic/188390-statement-execute-is-there-a-num_rows_effected-method/#findComment-994547 Share on other sites More sharing options...
trq Posted January 13, 2010 Share Posted January 13, 2010 Sorry, wrong function. mysqli_stmt_affected_rows, mysqli_stmt also returns the number of effected rows when executing update, delete etc etc. Link to comment https://forums.phpfreaks.com/topic/188390-statement-execute-is-there-a-num_rows_effected-method/#findComment-994551 Share on other sites More sharing options...
simplyi Posted January 14, 2010 Author Share Posted January 14, 2010 thorpe, Thank you! Link to comment https://forums.phpfreaks.com/topic/188390-statement-execute-is-there-a-num_rows_effected-method/#findComment-994581 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.