In General You have suggested is correct (at least logically correct) solution. But personally, I see You have two key points:
1. Why do You need to get data from the database that have just to the same and recorded? Moreover, such relatively perverse way, and even more 2 query (query + subquery). If you want to get the last record from the database, a query like:
SELECT * FROM table ORDER BY id DESC LIMIT 1;
So we get the last record, not the one we put there, and the one that will physically last at the time of query execution that is completely identical to Your version, but in 1 query (no subqueries).
There is another option of the query in one request:
SELECT * FROM table WHERE id = LAST_INSERT_ID();
According to this variant, can't say for sure that we will get the last existing record in the database at the time of the query, or specifically, the last record we inserted in the DB... but it works definitely not worse than Your example :)
1.1. Why don't we just output the data that we just recorded in the database? It's just the same data that we need, but they have already received.
2. Usually, in this situation, give the output of var_dump()
(or similar functions) to understand why data are not displayed. But to understand this, we must first acknowledge that we have a variable at all... at least it can help other developers, and You can more accurately formulate a question, for example, "it was expected that the result will be a scalar type and there is some reason the cursor of query result from database"
. That is,
<br / >
- greatly facilitate the solution of such problems in the future.