Page 1 of 1

Compare MSSQL field with MySQL Field

Posted: Tue Dec 05, 2006 6:03 am
by JimiH
Hi I have the following connections which work

Code: Select all

<?php 
error_reporting(E_ALL);

//mySQL connection

$db_name="vsi_projects";
$connection=mysql_connect("localhost","root","***") or die("I Couldn't connect");
$db=mysql_select_db($db_name,$connection) or die("I Couldn't select your database");
$mytable="projects"; // Table name


//msSQL connection

$server="EU-SKE-SMS-01";
$username="administrator";
$password="***";
$db = "Adept_SQL";
$mstable = "fm60fil";
$sqlconnect=mssql_connect($server, $username, $password);
$sqldb=mssql_select_db($db,$sqlconnect);
Lets say I want to match a field value "VSI_NUMBER" from"projects" (mySQL database) with
another field value "L_DN" from "fm60fil" (MSSQL database)

How would that be achieved?

Thanks

Geoff

Comparing Fields

Posted: Tue Dec 05, 2006 8:34 am
by timclaason
I'd just write a method to get each value. For instance:

Code: Select all

$VSI_NUMBER = $myClass->getMySQLValue("VSI_NUMBER");
$L_DN = $myClass->getMSSQLValue("L_DN");

if($VSI_NUMBER == $L_DN)
  print("There is a match");
else
   print("The fields do not match");
Then for the methods getMySQLValue() and getMSSQLValue(), just do the query to return that row.

The above code assumes you'll only want 1 record from each of the tables. If you have multiple records to return from your SQL queries, it's going to be a bit different.

Posted: Tue Dec 05, 2006 12:02 pm
by ok
You can't do it in a one SQL query (if that was your question).

Posted: Wed Dec 06, 2006 3:34 am
by JimiH
Hi
Then for the methods getMySQLValue() and getMSSQLValue(), just do the query to return that row.
can you elaborate on this please are they user defined functions?

You can't do it in a one SQL query (if that was your question).
Is there another way to achive this, can you link a MSSQL table within MySQL?

Thanks

Geoff

Elaborating

Posted: Wed Dec 06, 2006 10:55 am
by timclaason
You would have a function called getMySQLValue(), and it would look something like this:

Code: Select all

function getMySQLValue($field) {
$query = "SELECT " . $field . " FROM projects LIMIT 1"; //Or however you would want to do the query
$SQL = mysql_query($query, $db_link);

while($row = mysql_fetch_array($SQL)) {
   return $row['".$field."'];
}

}//End Function
Then you would do a similar function for the MSSQL field, but use the proper fetch_array.

Then, in your code:

Code: Select all

$VSI_NUMBER = getMySQLValue("VSI_NUMBER");
And similar for the MSSQL value.