Jump to content

$statement->execute(). Is there a num_rows_effected() method?


simplyi

Recommended Posts

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!

 

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.

 

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.