Monday, May 21, 2007

connect with ms-access and print the table of data in php

<?php

$db_conn = new COM("ADODB.Connection");

$connstr = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=". realpath("thedata.mdb").";";

$db_conn->open($connstr);

if($db_conn)

{

echo "connected";

}

else

{

echo "not conected";

}

$rS = $db_conn->execute("SELECT * FROM main1");


$cnt=0;

echo"<table>";

while (!$rS->EOF)

{



if($cnt%2 == 0 )

{

print "<tr bgcolor='#C0C0C0'><td>".$rS->Fields(0)."</td><td>". $rS->Fields(1)."</td><td>".$rS->Fields(2)."</td><td>".$rS->Fields(3)."</td><td>".$rS->Fields(4)."</td><td> ".$rS->Fields(5)."</td><td>".$rS->Fields(6)."</td></tr>\n";

}

else

{

print "<tr><td>".$rS->Fields(0)."</td><td>". $rS->Fields(1)."</td><td>".$rS->Fields(2)."</td><td>".$rS->Fields(3)."</td><td>".$rS->Fields(4)."</td><td> ".$rS->Fields(5)."</td><td>".$rS->Fields(6)."</td></tr>\n";

}

$cnt++;

$rS->MoveNext();

}

echo"</table>";

$rS->Close();

$db_conn->Close();

?>



its eassy that you have to just change your database name for run this script

No comments: