Ajay Makwana
Ajay Makwana

Reputation: 2372

I want to `Add columns` to my database using `PDOquery`. But my query returns some error

I want to Alter my database table (Add Columns) using query. I have done this :

This is my first query (Run Successfully) :

$database->pdoQuery("ALTER TABLE tbl_mytable ADD column1 varchar(100)");

This is my second query (gives an error) :

$database->pdoQuery("ALTER TABLE tbl_mytable ADD column2 text");

I have got this error message:

Executed Query -> ALTER TABLE tbl_mytable ADD column2 text
ERROR:"SQLSTATE[HY000]: General error: 315"

Can any one solve my problem? Any help would get appreciated.

Upvotes: 3

Views: 57

Answers (2)

Nimesh Vagadiya
Nimesh Vagadiya

Reputation: 632

$db->query("ALTER TABLE tbl_mytable ADD column2 text NOT NULL AFTER column1");

Upvotes: 1

schellingerht
schellingerht

Reputation: 5796

You didn't say which versions you're using.

Your query is not wrong, but it could be your (older) MySQL version. Add backticks to your query:

$database->pdoQuery("ALTER TABLE `tbl_mytable` ADD `column2` text");

Upvotes: 1

Related Questions