4
I have a bank SqlServer
and I need to send data from a table to a Mysql database via php script.
OPENQUERY will result within the condition I have (php script)?
What’s the best way to do it?
The code I use to connect the banks:
Sqlserver:
$conMsSql = odbc_connect('Banco_MsSql','User_MsSql','Pw_MsSql');
Mysql:
$hostname_mysql = "localhost";
$database_mysql = "banco_mysql";
$username_mysql = "user_mysql";
$password_mysql = "pw_mysql";
$Conn = mysql_pconnect($hostname_mysql, $username_mysql, $password_mysql) or trigger_error(mysql_error(),E_USER_ERROR);
$DBase = mysql_select_db($database_mysql,$Conn) or die(mysql_error());
And it would look something like this:
$query = mysql_query('insert into tabela1 ( col1, col2, col3 )
select sqlserver.tab1.col1, sqlserver.tab1.col2, sqlserver.tab1.col3 from sqlserver.tab1')
Are many records? tried to make two connections to or mssql and another to mysql? if you have source code edit the question and ask it.
– rray
You need to make a routine of it, or you’ll make this import all at once?
– Ivan Ferrer
Will be a routine.
– user26858
You will need to create a
crontab
on the server to run your script at the time you set (as the windows task scheduler), then you need to open the two connections in your script and create a routine that runs mysqldump to create the sql file, it can be with a random hash: 123.sql, already processing the data. Then import this 123.sql file into the sql server database, usingmssql_query()
, orsqlrv_query()
.– Ivan Ferrer
When you finish creating the file, you trigger the import event.
– Ivan Ferrer
You don’t necessarily need a php script to do this.
– Ivan Ferrer
You can create a
procedure
in theMySQL
that manages the file in a folder. And capture that file in aprocedure
in theSQL Server
.– Ivan Ferrer
As it is a routine, it will always be running according to the defined execution space time between the processing.
– Ivan Ferrer
I only have Sqlserver database query permission, then select a table and send to Mysql...
– user26858
These fields, tables are equal?
– Ivan Ferrer