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 > ?');


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');


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');


Thank you, the code above works fine.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.