Skip to content

Instantly share code, notes, and snippets.

@nklatt
Created November 17, 2015 15:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nklatt/7ae00417df32a4f0485e to your computer and use it in GitHub Desktop.
Save nklatt/7ae00417df32a4f0485e to your computer and use it in GitHub Desktop.
Loop over all tables in a database.
use Illuminate\Database\Capsule\Manager as DB;
$capsule->addConnection(array(
'host' => 'localhost',
'database' => 'information_schema',
'username' => 'usr',
'password' => 'pwd',
'collation' => 'utf8_general_ci',
'charset' => 'utf8',
'driver' => 'mysql',
'prefix' => ''
), 'information_schema');
$table_names =
DB::connection('information_schema')
->table('TABLES')
->select(DB::raw('distinct(TABLE_NAME)'))
->where('TABLE_SCHEMA', '=', 'pmdev_responsive')
->where('TABLE_NAME', 'LIKE', 'ctx_%')
->get();
foreach ($table_names as $table_name) {
// ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment