maxID in PDO

(ID) member
(1)   0 
(2)   0
(3)   1
(4)   0
(5)   2
(6)   1
(7)   0
(8)   3

I have the table above
I have the code below in my php file.

$maxID = $dbc->prepare ('SELECT max(ID) as maxID
FROM test WHERE member > ?');

$maxID->execute([-1]);
$maxID=$maxID->fetch();

echo $maxID'['maxID];

The result of the code above is “8”.

I like to remove where clause because it has no relation with my target ID, i.e. maxID.

The below is one of my trials for it.

$maxID = $dbc->prepare ('SELECT max(ID) as maxID
FROM test');

$maxID=$maxID->fetch();

echo $maxID'['maxID];

However, my trial above produces Warning : Trying to access array offset on value of type bool.

How can I get the maxID “8” without member?

your SQL is fine

the error is produced by your python code

You try to fetch without an execute. That couldn’t work. Add a execute before and it’s fine

Also it is very bad Style to use the same variable for totally different types. The return of prepare is not a maxID but a statement. Name it maxIDStatement or something like that.

$maxIDresult = $dbc->prepare ('SELECT max(ID) as maxID
FROM test');

$maxIDresult->execute();
$maxIDvalue=$maxIDresult->fetch();

Thank you, the code above works fine.