Coder Social home page Coder Social logo

Comments (9)

mrjgreen avatar mrjgreen commented on August 27, 2024

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.

damms005 avatar damms005 commented on August 27, 2024

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.

mrjgreen avatar mrjgreen commented on August 27, 2024

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.

damms005 avatar damms005 commented on August 27, 2024

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.

mrjgreen avatar mrjgreen commented on August 27, 2024

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.

damms005 avatar damms005 commented on August 27, 2024

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.

mrjgreen avatar mrjgreen commented on August 27, 2024

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:

  1. Create a new table on the remote server, that is a duplicate of users, E.G. users_sync
  2. Sync from local.users to remote.users_sync without any data restrictrions
  3. 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.

damms005 avatar damms005 commented on August 27, 2024

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.

njovujsh avatar njovujsh commented on August 27, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.