Re: save LAST_INSERT_ID to variable

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




On 02/01/2022 11:19, gordonisnz@xxxxxxxxx wrote:
I'm researching the LAST_INSERT_ID command for MYSQL.

from what i have seen - I can save it as a 'variable' as @variable =
LAST_INSERT_ID();

Question: What is the difference between @THIS_VARIABLE and
$that_variable (with a dollar $ sign)??

I cannot find ANY examples/tutorials that say we can save it as a  $variable.

You appear to be mixing too different languages / concepts here.

You can save a value to a variable in SQL, which uses @variable.

You can save a value to a variable in PHP, which uses $variable.

In the case of a value saved in SQL, the value can only be used in further SQL queries on the same SQL connection and cannot be used for other purposes (for example, using in a URL to forward the user to or creating a job queue message).

SQL variables are useful for scripting something in SQL, but if you're already using a scripting language such as PHP to perform a larger task, I think it's generally best to keep as much logic as possible there. (Additionally, in my experience many developers aren't familiar with SQL variables, so it reduces overhead for others maintaing the code in future)



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux