Page 1 of 1

Switch Code from Accessing SQL Server to Access Database

Posted: Fri Aug 22, 2008 11:49 am
by jaykappy
I have this code that is access a SQL server. I need to change it to go after an access database.
I am very green to this and would appreciate any help I can get.

Thoughts, examples?

THANKS in advance

Code: Select all

 
$p_num = @$_GET["id"];
$image_type = @$_GET["type"];
 
$myServer = "LO-.LOG.ORG\FF,5502";
$myUser = "GIS";
$myPass = "GIS";
$myDB = "PDSD"; 
 
$conn = new COM ("ADODB.Connection")or die("Cannot start ADO");
$connStr = "PROVIDER=SQLOLEDB;SERVER=".$myServer.";UID=".$myUser.";PWD=".$myPass.";DATABASE=".$myDB; 
$conn->open($connStr);
 
 
    $sql_str = "SELECT * FROM PHOTOS WHERE PID = '".$p_num."' AND Photo_Doc = 'P'";
    $photo_rs = $conn->execute($sql_str); 
    echo "<div class='redbg'> <b><big>Assessing Photos:</big></b></div>";
    echo "<br>";
    If ($photo_rs->EOF)
    {
        echo "No photos exist for this parcel!";
    } else
    {
        $photo_rs->MoveFirst();
        echo "<table border='2' width='100%'>";
        While (!$photo_rs->EOF)
        {
            $p_name = $photo_rs->Fields("Filename")->Value;
            $p_hype = "javascript&#058;window.open('file://S:/GeoImag/Assessing/Photos/".$p_name."','photowindow','width=450,height=350',position='Center')";
            writelinewhype($p_name,"Image",$p_hype);
            $photo_rs->MoveNext();
        }
        echo "</table>";
        $photo_rs->Close();
        $photo_rs = null;               
     }

Re: Switch Code from Accessing SQL Server to Access Database

Posted: Fri Aug 22, 2008 2:40 pm
by jaoudestudios
Why would you want to move to access? Surely you would want to go from SQL to MySql?

Back me up guys!

Re: Switch Code from Accessing SQL Server to Access Database

Posted: Fri Aug 22, 2008 3:24 pm
by jaykappy
This application is going live in the field...I will not have internet connection!

Internally I will be linking to the SQL server...but need something stand alone in the field to display data.

This gets me what I want

Code: Select all

<?php
 
$p_num = @$_GET["id"];
 
$conn=odbc_connect('PDS_Access_db','','');
 
 
$sql="SELECT * FROM dbo_PARCELS WHERE PID = '".$p_num."'";
 
$rs=odbc_exec($conn,$sql);
 
if (!$conn)
  {exit("Connection Failed: " . $conn);}
 
 
if (!$rs)
  {exit("Error in SQL");}
echo "<table><tr>";
//echo "<th>PID</th>";
//echo "<th>Street_Number</th>";
//echo "<th>Street_Name</th></tr>";
 
while (odbc_fetch_row($rs))
{
  $PID=odbc_result($rs,1);
  $House_Nbr=odbc_result($rs,2);
  $Street_Name=odbc_result($rs,3);
  
  //echo "<tr><th><td align=left>PID:</th> $PID</td> \n";  
  //echo "<tr><td><th>Street Number: </th>$House_Nbr</td></tr> \n";
  //echo "<tr><td><th>Street Name: </th>$Street_Name</td></tr> \n";
  
    echo "<tr><th>PID:</th><th>Street Number:</th><th>Street Name:</th></tr>";
    echo "<tr><td>" . $PID . "</td><td>" . $House_Nbr . "</td><td>" . $Street_Name . "</td></tr>";
 
  echo "<br><br>";  
}
odbc_close($conn);
echo "</table>";
?>

Re: Switch Code from Accessing SQL Server to Access Database

Posted: Fri Aug 22, 2008 3:29 pm
by ghurtado
jaykappy wrote:This application is going live in the field...I will not have internet connection!
Well, today is your lucky day, because MySQL does not require an internet connection to work.

(hows that for backup ;) )

Re: Switch Code from Accessing SQL Server to Access Database

Posted: Fri Aug 22, 2008 5:21 pm
by jaoudestudios
(hows that for backup ;) )
haha thanks.

But easy guys!

Re: Switch Code from Accessing SQL Server to Access Database

Posted: Fri Aug 22, 2008 6:13 pm
by Christopher
Actually you might want to look into SQLite. It is used by many applications as their internal database. It is generally SQL compliant and very fast. Plus it is cross platform, unlike Access.

Re: Switch Code from Accessing SQL Server to Access Database

Posted: Fri Aug 22, 2008 6:43 pm
by Eran
And it doesn't require a separate service. +1 for SQLite