How can I insert a new column in my table using php and mysql?

26
March 16, 2019, at 05:10 AM

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 1

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!

READ ALSO
Getting error when trying to edit subpage in Grav

Getting error when trying to edit subpage in Grav

Whenever I try to add or edit a subpage (ie

47
Zend Expressive API does not return contents of objects

Zend Expressive API does not return contents of objects

I'm creating a small API, mostly for learning purposes, but, I might implement it into a project I'm working onSo far, I have installed the zend expressive skeleton application and set up my models and entities

18
What change Language codeigniter

What change Language codeigniter

I want to rend my codeigniter multilanguage and I would create a button that it can change in config/configphp $config[language]== "? "

29
Chaining webdriver methods

Chaining webdriver methods

I'd like to implement a class to carry out some common webdriver functions, but I keep getting: the driver server has died

33