Dynamic Table Creation MSSQL to MySQL

I am creating a test data manager application using php and mysql.I fetched some records from a table in mssql server.I want to store these records in mysql database so that the table is created dynamically in Mysql database along with column names acording to the columns fetched from ms sql…Can someone help me ASAP?

You only need to use a SQL create instruction and as for the name of the fields, since you already fetched the data, you’ve got them there

I want to create the tables dynamically in mysql i.e.Without writing a query

You want to create tables without queries?

Errrr… not possible :slight_smile:

Pssh you must know evil sorceries and magix is all.


OK editing to make this post useful to OP: If we’re understanding your desire correctly, and you wish to create tables without queries, the answer is “you cannot do that” - that’s how tables are made.

If you explain your problem in more depth, perhaps there is a solution - but that’s not it :smile:

1 Like

See what i wanna do is " Suppose i fire a query on ms sql database to fetch some records in my php web application…Now i have created a “export to mysql” button under the fetched records on my webpage…I want that on clicking this button,the records get stored in mysql database from mssql database dynamically.(Here dynamically means that the table and columns doesnot exist in mysql database.They must get created automatically acording to the records fetched from mssql database.

What does your “export to mysql” code look like so far?

1 Like

I haven’t written a code for export to mysql so far because i have no idea of how to create tables dynamically in mysql…We can’t write specific code for records fetched as the records would keep varying acording to the quries fired on mssql database

Got PHP?

Using PDO it shoud be possible to use PDO to bridge the two. i.e.
MS SQL → PDO → MySQL

Can you please explain it in a bit more detail

I didn’t go into detail before knowiing your answer to

Ya , I have got php…I am developed my application in php only.My back end is mysql…I have to fetch data from mssql and store it in mysql through php

Create this simple file and run it. Do you see the drivers you need?

<?php
print_r(PDO::getAvailableDrivers());
?>

The output is

Array ( [0] => mysql [1] => sqlite )

Just the default drivers then. That complicates things unless you have the ability to install what you need - not likely if you’re on a shared host.

How are you able to use the MS SQL database now without it?

My code looks like this to access mssql database

<?php error_reporting(E_ALL ^ E_DEPRECATED); include('adodb5/adodb.inc.php'); include('adodb5/adodb-pager.inc.php'); $ADODB_FETCH_MODE = ADODB_FETCH_NUM; $db = ADONewConnection('odbc_mssql'); $db->debug = true; $dsn = "Driver={SQL Server};Server=Servername;Database=dbname;"; $db->Connect($dsn, username,password); $sql="select * from tablename"; $pager = new ADODB_Pager($db,$sql); $pager->Render($rows_per_page=6); ?>

I’ve no experience using the ADODB but the good news is it will work with both db engines.

From what I see at
http://adodb.sourceforge.net/docs-adodb.htm#ex2
you can use ->FetchField() to get table info you’ll need to use to create the MySQL tables.
(maybe this would come in useful http://adodb.sourceforge.net/docs-datadict.htm)

If you run a SHOW TABLES (or the MS SQL equivalent, if it’s different) query against the database you’ll hopefully get the tables you need, and then using FetchField() on those be able to get the table schemas.

1 Like

Ya the link which you have provided is appearing to be useful for my problem.Actually, i am also a beginner in php.So,I am finding difficulty in its implementation.But let me check.
Thank you very much for the helpful response

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.