How can I insert a new column in my table using php and mysql?
Get the solution ↓↓↓I'm trying to add the column "test" in my table "reservation" but it doesn't work
do you have an idea why?
$create = $bdd->prepare('ALTER TABLE reservation ADD test INT NULL');
Database:
Answer
Solution:
The mysql syntax seems correct, but did you try querying it instead of creating a prepared statement?
(Also, please elaborate by posting error messages, more code, context of the problem, etc.)
From what I see, you're not executing the statement.
$create = $bdd->prepare('ALTER TABLE reservation ADD test INT NULL');
$create->execute();
If you're not going to insert user created data, you can also try querying the database instead:
$create = $bdd->query('ALTER TABLE reservation ADD test INT NULL');
Not sure if this third one is required, but I usually add "COLUMN" to the query. It may depend on what DB engine you're using (Don't quote me on that)
ALTER TABLE reservation ADD COLUMN test INT NULL
Good luck!
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: undefined array key php
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.