I hope you're doing well. I have a question related to using MySQL and PHP, specifically in regards to using returned rows as PHP variable names and assigning values from a CSV.
Here's the situation: I have a CSV file that contains data in rows and columns. I need to import this data into a MySQL database. I have successfully done that using the LOAD DATA INFILE statement in MySQL.
Now, what I want to achieve is to use the column names from the CSV file as variable names in my PHP code. This way, I can easily refer to the data in the various columns without hardcoding the column names in my PHP code.
For example, if my CSV file has the following columns: "name", "age", and "city", I would like to be able to do something like this in my PHP code:
$name = $row['name'];
$age = $row['age'];
$city = $row['city'];
To achieve this, I believe I need to fetch the column names from the MySQL result set and use them as variable names in PHP. However, I'm not sure how to do this.
So, my question is: How can I dynamically use the column names returned from MySQL as variable names in PHP? Is there a way to achieve this?
If any of you have experienced something similar or have any ideas or suggestions, I would greatly appreciate your help. Thank you in advance!