Hi! Could we please enable some services and cookies to improve your experience and our website?
Online Sandbox for SQL and PHP: Write, Run, Test, and Share SQL Queries and PHP Code
create table clients (id int);
insert into clients values (1),(2);
create table client_2_data (id int);
create table client_1_data (id int, `updated` datetime DEFAULT NULL);
<?php
$ca=$mysqli->query('SELECT * FROM `clients`');
$c=$ca->fetch_assoc();
try {
$mysqli->query('ALTER TABLE `client_'.$c['id'].'_data` ADD COLUMN `updated` datetime DEFAULT NULL');
}catch (Exception $e) {
echo "Caught for {$c['id']}\n $e";
}
$c=$ca->fetch_assoc();