Hello,
I made a class to connect with database but now I have run into a little problem. I need to get the id of last inserted row, but I dont know how to accomplish it.
Here is my connection class:
<?php
class Connection{
public function __construct($config){
$this->mysqli = new mysqli($config['host'], $config['username'], $config['password'], $config['db']);
if(mysqli_connect_errno()){
die("Connection error: " . mysqli_connect_errno());
}
}
public function query($sql){
$this->result = $this->mysqli->query($sql);
if($this->result == true){
return true;
}else{
die("<strong>There was a problem with the query: </strong> " . $sql);
}
}
public function get(){
$data = array();
while ($row = $this->result->fetch_array(MYSQLI_ASSOC)){ //MYSQLI_NUM numbritega jarjestamiseks
$data[] = $row;
}
$this->result->close();
return $data;
}
public function __destruct(){
$this->mysqli->close();
}
}
As you can see I use the same function for selecting and insering but select doesnt return lastInsertId. Please help me modify this class so I can get the row id when I insert data.