Compare MSSQL field with MySQL Field

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
JimiH
Forum Commoner
Posts: 92
Joined: Thu Jun 15, 2006 6:10 am

Compare MSSQL field with MySQL Field

Post 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
timclaason
Forum Commoner
Posts: 77
Joined: Tue Dec 16, 2003 9:06 am
Location: WI

Comparing Fields

Post 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.
User avatar
ok
Forum Contributor
Posts: 393
Joined: Wed May 31, 2006 9:20 am
Location: The Holy Land

Post by ok »

You can't do it in a one SQL query (if that was your question).
JimiH
Forum Commoner
Posts: 92
Joined: Thu Jun 15, 2006 6:10 am

Post 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
timclaason
Forum Commoner
Posts: 77
Joined: Tue Dec 16, 2003 9:06 am
Location: WI

Elaborating

Post 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.
Post Reply