mp1234 Posted April 29, 2009 Share Posted April 29, 2009 Hi all, I need help with connecting Databases. actually its more of integrating two databases then connection. i can't use migration tool b/c it is something that needs to happen everyday as the tables in oracles update mysql tables need to be updated too and i though it would be eaiser to do it via php script. I am migrating from mssql to mysql. In one of the tables i have procedure that grabs data from oracle and populates into mssql table. Now, with mysql there is no linked servers functionality. I thought php would be easier to grab certain data from table in oracle and populate mysql table. Has anyone successfully done this? or have a simple quick and dirty type script that connects to oracle grabs data from table and put it in mysql db. Or any other way of doing is also appreciated... I really appreciate it as always ... THanks, Link to comment https://forums.phpfreaks.com/topic/156123-connecting-to-db-with-php/ Share on other sites More sharing options...
radi8 Posted April 29, 2009 Share Posted April 29, 2009 In the PHP.INI be sure to have the mssql adaptors turned on. You can have multiple links and connections open simuultaneously, so the following should work. mssql: <?php $link = mssql_connect($mssql_hostname,$mssql_username,$mssql_password) or DIE("Database failed to respond (Index)."); mssql_select_db($mssql_database)or DIE("Database unavailable"); $sql = "select ..."; $rs = mssql_query($sql); if (mssql_num_rows($rs) > 0){ for($i = 0;$i < mssql_num_rows($rs);$i++){ $rss = mssql_fetch_row($rs); ... } } else {}//$valid=false;} // close the link and flush the dataset mssql_free_result($rs); mssql_close($link); ?> Create your arrays or what not, and then populate the mysql database mysql: <?php $link2 = mysql_connect('localhost', 'mysql_user', 'mysql_password'); if (!$link2) {die('Could not connect: ' . mysql_error());} mysql_select_db('mydb'); /* Update records */ mysql_query("UPDATE mytable SET used=1 WHERE id < 10"); printf ("Updated records: %d\n", mysql_affected_rows()); mysql_query("COMMIT"); mysql_close($link2); ?> Is this what you are looking for? Link to comment https://forums.phpfreaks.com/topic/156123-connecting-to-db-with-php/#findComment-821850 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.