Comments (9)
Hi, I am sorry you are having problems getting started. It doesn't really sound like your problem is anything to do with this library, but more to do with correctly loading libraries into your application. However, I am happy to try and help if I can.
First of all, I would recommend installing this via composer as suggested in the docs, which is the standard package manager for PHP. You can do this using composer require mrjgreen/db-sync
.
If you are unsure how to use composer, you can get started here.
If this isn't an option for you, then you are most likely going to have to include each library file manually. This is going to be tricky, but should be possible. If this is the direction you are going to go, then please feel free to post the code you have tried to use here, and I'll try and make suggestions.
from db-sync.
Thanks for your response.
First, composer not an option. I cannot install stuff on my godaddy account (except you can help on how to use composer on a shared-hosting godaddy hosting without them yelling all over)
With regards to what I have tried, I noticed some namespaces whose file are not in the downloaded zip (master). These namespaces are
use Database\Connection;
use Database\Query\Builder;
use Database\Query\Expression;
use Database\Query\Grammars\MySqlGrammar;
...etc
So I think I need those files.
What I have tried so far:
test.php
<?php
require( "DbSync/DbSync.php" );
require( "DbSync/Hash/HashInterface.php" );
require( "DbSync/Hash/HashAbstract.php" );
require( "DbSync/Hash/ShaHash.php" );
require( "DbSync/Hash/CrcHash.php" );
require( "DbSync/Hash/Md5Hash.php" );
require( "DbSync/Transfer/TransferInterface.php" );
require( "DbSync/Transfer/Transfer.php" );
require( "DbSync/Table.php" );
require( "DbSync/ColumnConfiguration.php" );
use DbSync\DbSync;
use DbSync\Transfer;
use DbSync\Hash\ShaHash;
use DbSync\Table;
use DbSync\ColumnConfiguration;
$blockSize = 4;
$transferSize = 4;
$sync = new DbSync(new \DbSync\Transfer\Transfer(new ShaHash(), $blockSize, $transferSize));
// $sync->setLogger(new YourPsrLogger());
$sync->dryRun(true);
$sync->delete(false);
$sourceConnection = "localhost";
$sourceDb = 'iqpluskn_iuokada;';
$sourceTable = 'SIStudentMaster';
$targetConnection = "localhost";
$targetDb = "iqpluskn_iuokada";
$targetTable = "payments_outgoing";
$syncColumns = 'id';
$ignoreColumns = 'date';
$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
$sourceTable->setWhereClause(new WhereClause("column_name = ?", ['value']));
$targetTable->setWhereClause(new WhereClause("column_name > ?", ['value']));
$sync->sync($sourceTable, $targetTable, $columnConfig);
?>
Also, as you may have seen, I do not know how to use $sourceTable->setWhereClause(new WhereClause("column_name = ?", ['value']));
. What I want to achieve is to compare if date column in SourceTable is greater than the date column in TargetTable.
from db-sync.
You do not install composer on your remote server, so GoDaddy has nothing to do with this. Composer is something you use locally to install and manage your package dependencies.
You are right, this library has a dependency on https://github.com/mrjgreen/database. Composer will automatically install this for you.
I suggest you take a look at how to get started with composer for windows. This is the best advice I can offer at this stage, and it is absolutely the best way for you to achieve what you are trying to do.
from db-sync.
So how do I use $sourceTable->setWhereClause(new WhereClause("column_name = ?", ['value']));
to be able to compare if date column in SourceTable is greater than the date column in TargetTable before so that the newer row replaces the old one (and then non-existing rows are also inserted)?
from db-sync.
Unless you have very specific requirements, you will most likely not need to use the WhereClause
feature. The whole idea behind this tool is that it automatically compares and syncs differences in data between the source and target databases.
Is there a specific reason you need to check a date column?
from db-sync.
Yes, I have a specific reason.
I have a remote server that stores records in users
table.
These same records on the remote server is also available locally on my local server.
This means that I have the users
table on the remote and my local server.
users
table has a column called last_updated_datetime
that stores value for last update.
So sometimes I do stuff locally that updates this record and I want to update such changes on the remote server. Therefore I need a tool that will update remote record when localserver.lastup.last_updated_datetime
> remoteserver.last_updated_datetime
; and then also add any new entry in the localserver.lastup.users
to remoteserver.users
.
Can this tool handle this? If not, no any tool that can handle it?
from db-sync.
Okay - this sounds like a fairly strange requirement and possibly a little risky, both in terms of data integrity and security. I strongly suspect there is an architectural solution to your problem that would perhaps lead to a better set up, but if you do need to do this, then I would recommend the following:
- Create a new table on the remote server, that is a duplicate of
users
, E.G.users_sync
- Sync from
local.users
toremote.users_sync
without any data restrictrions - Run a SQL query on the remote server:
REPLACE INTO users
SELECT users_sync.* FROM users_sync
LEFT JOIN users USING(id)
WHERE users.last_updated IS NULL OR users_sync.last_updated > users.last_updated
from db-sync.
Whao!
You're either a genius, a wizard, or simply a juju master master!..all of the above!
Thanks pal. You just saved the day!
from db-sync.
My Table has a primary key, but when I run The DbSyn, it returns an error table does not have a primary key what can I do.
Thanks in advance
from db-sync.
Related Issues (20)
- Syntax error or access violation: 1064 HOT 2
- Correct db-sync code for PHP version (correcting DbSync\Transfer error) HOT 6
- symfony/console issue with Laravel 5.2.* HOT 3
- could not find driver HOT 2
- Laravel 5.6 and Symfony Console HOT 4
- Specify options in Php? HOT 1
- could we sync tables with same host but different port for different db HOT 1
- php, php-mysql packages HOT 1
- Base table or view not found: 1146 Table 'TestDatabase;.wp_bp_activity' HOT 4
- Using PHP Non-CommandLine - Sync All tables HOT 2
- Delete from source does not sync to Destination HOT 1
- RuntimeException table does not have a primary key HOT 18
- Error if using a column that is not id as primary key HOT 1
- Support different database names HOT 1
- Table sync sql error duplicate entries
- Feature request: ordering field HOT 1
- Sync multiple tables HOT 1
- ') < ()) t limit 1' added into the query HOT 3
- Column not found: 1054 Unknown column '*fieldname*' in 'field list'
- How to use as PHP page HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from db-sync.