Switch Code from Accessing SQL Server to Access Database

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
jaykappy
Forum Newbie
Posts: 3
Joined: Fri Aug 15, 2008 8:55 am

Switch Code from Accessing SQL Server to Access Database

Post 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;               
     }
User avatar
jaoudestudios
DevNet Resident
Posts: 1483
Joined: Wed Jun 18, 2008 8:32 am
Location: Surrey

Re: Switch Code from Accessing SQL Server to Access Database

Post by jaoudestudios »

Why would you want to move to access? Surely you would want to go from SQL to MySql?

Back me up guys!
jaykappy
Forum Newbie
Posts: 3
Joined: Fri Aug 15, 2008 8:55 am

Re: Switch Code from Accessing SQL Server to Access Database

Post 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>";
?>
User avatar
ghurtado
Forum Contributor
Posts: 334
Joined: Wed Jul 23, 2008 12:19 pm

Re: Switch Code from Accessing SQL Server to Access Database

Post 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 ;) )
User avatar
jaoudestudios
DevNet Resident
Posts: 1483
Joined: Wed Jun 18, 2008 8:32 am
Location: Surrey

Re: Switch Code from Accessing SQL Server to Access Database

Post by jaoudestudios »

(hows that for backup ;) )
haha thanks.

But easy guys!
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Switch Code from Accessing SQL Server to Access Database

Post 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.
(#10850)
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: Switch Code from Accessing SQL Server to Access Database

Post by Eran »

And it doesn't require a separate service. +1 for SQLite
Post Reply