mrjgreen/db-sync

Base table or view not found: 1146 Table 'TestDatabase;.wp_bp_activity'

Closed this issue · 4 comments

I am trying to sync WordPress database once successful, I will be using this script with my custom tables.

Following is my code

setLogger(new Psr\Log\NullLogger()); $sync->dryRun(true); $sync->delete(false); $factory = new Database\Connectors\ConnectionFactory(); $sourceConnection = $factory->make(array( 'driver' => 'mysql', 'host' => 'localhost', 'username' => 'root', 'password' => 'password', 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', 'database' => 'TestDatabase', 'prefix' => '', 'strict' => false, )); $sourceDb = 'TestDatabase;'; $sourceTable = 'wp_bp_activity'; $targetConnection = $factory->make(array( 'driver' => 'mysql', 'host' => 'localhost', 'username' => 'root', 'password' => 'password', 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', 'prefix' => '', 'strict' => false, )); $targetDb = "TestDatabase"; $targetTable = "XXwp_bp_activity"; $sourceTable = new Table($sourceConnection, $sourceDb, $sourceTable); $targetTable = new Table($targetConnection, $targetDb, $targetTable); // if you only want specific columns //$columnConfig = new ColumnConfiguration($syncColumns, $ignoreColumns); // optionally apply a where clause - this can be useful when sync-ing large tables, where // you can make use of a column to rule out large portions of the data // that you know haven't changed, such as columns with "on update CURRENT_TIMESTAMP" etc.. //$sourceTable->setWhereClause(new WhereClause("column_name = ?", ['value'])); //$targetTable->setWhereClause(new WhereClause("column_name > ?", ['value'])); $sync->sync($sourceTable, $targetTable, $columnConfig); ?>

I tried with and without 'database' => 'TestDatabase' and 'strict' => false or true

but I get following error.

Fatal error: Uncaught exception 'Database\Exception\QueryException' with message 'SQLSTATE[42S02]: Base table or view not found: 1146 Table 'TestDatabase;.wp_bp_activity' doesn't exist driver: mysql host: localhost username: root charset: utf8 collation: utf8_unicode_ci database: TestDatabase prefix: strict: SQL: SHOW INDEX FROM TestDatabase;.wp_bp_activity WHERE key_name = 'PRIMARY'' in /var/www/testing.com/dbsync/src/Exception/ExceptionHandler.php:49 Stack trace: #0 /var/www/testing.com/dbsync/src/Connection.php(360): Database\Exception\ExceptionHandler->handle('SHOW INDEX FROM...', Array, Object(PDOException)) #1 /var/www/testing.com/dbsync/src/Connection.php(326): Database\Connection->execute('SHOW INDEX FROM...', Array, true) #2 /var/www/testing.com/dbsync/src/Connection.php(234): Database\Connection->run('SHOW INDEX FROM...', Array, true) #3 /var/www/testing.com/dbsync/src/Table.php(100): Database\Connection->fetchAll('SHOW INDEX FROM. in /var/www/testing.com/dbsync/src/Exception/ExceptionHandler.php on line 49

Hi Joe,

Thanks for pointing out the issue. 👍
Now the PHP is able to run but I do not see the destination table populated with data.
I see no error, no warning.

$sourceTable = new Table($sourceConnection, $sourceDb, $sourceTable);
$targetTable = new Table($targetConnection, $targetDb, $targetTable);

I am not using column config because I want to transfer all the columns and no filter is required.

Is there a debug log which I can enable and see what activity is performed.

// if you only want specific columns
//$columnConfig = new ColumnConfiguration($syncColumns, $ignoreColumns);

//$sourceTable->setWhereClause(new WhereClause("column_name = ?", ['value']));
//$targetTable->setWhereClause(new WhereClause("column_name > ?", ['value']));

//$sync->sync($sourceTable, $targetTable, $columnConfig);
$sync->sync($sourceTable, $targetTable);

Hi Joe,

You are correct. DryRun was set as True.
I am able to run db-sync