When I run SQL query in phpMyAdmin directly it works; however, running the same query from PHP file does not affect the database table and no errors are thrown also.
ALTER TABLE tender_230115 ADD avt DECIMAL(10,2) NOT NULL AFTER vpm
PHP Version 5.3.28. Database connection is indeed established. When I run:
$test_query = "ALTER TABLE tender_230115 ADD avt DECIMAL(10,2) NOT NULL AFTER vpm";
$upload_test = $conn->query($test_query);
Nothing is affected in the database table, while var_dump($upload_test) = bool(false).
Quotes and backticks do not help also. Using the mysqli driver.
Piggy backing off of what @Keo and @Mihai said above, your code needs to be:
$existing_tender = "tender_230115";
$existing_user = "avt";
$penultimate_name = "vpm";
$insert_column = "ALTER TABLE `$existing_tender` ADD `$existing_user` DECIMAL(10,2) NOT NULL AFTER `$penultimate_name`";
$upload = $conn->query($insert_column);
To see more information on an error that happened, you can add the following code below the code above:
var_dump($conn->error);
Edit with what the author specified his issue was. This was pulled from the comments below on this answer. Placing it here so that it's more clear what the actual issue was:
Ok, so something else to look into is permissions. Is the mysql user in PhpMyAdmin the same as the user you are using in PHP? For example, you might login to PhpMyAdmin with your personal account, however you might have a different project account that you are using for your mysqli connection. If this is the case, ensure that your project mysql account has permissions to ALTER tables.