I want to get the next auto increment id with PHP. I run the query in mysql and need the result:
column name: auto_increment value = 122
but I am getting a Notice:
Trying to get property 'auto_increment' of non-object
public function findNextAutoIncrementId()
{
$db = config::getConnexion();
$sql = 'SELECT `auto_increment` FROM INFORMATION_SCHEMA.TABLES
WHERE table_name = newsarticle';
$req = $db->prepare($sql);
$req->execute();
$result = $req->fetch(PDO::FETCH_OBJ);
return $result;
}
// when i use it i get Notice: Trying to get property 'auto_increment' of non-object
$result=$sujetC->findNextAutoIncrementId();
echo "this is : ".$result->auto_increment;
[Edit] : When I asked this question I wanted to find the next 'newsarticle' object that will be created to do some functions at it just after the insert operation and before showing it. What I should have made was to create a function that search for the specific 'newsarticle' after it has been created with the specific attributes