Connecting to various databases using PHP

How to connect to Microsoft Access?

$db =& ADONewConnection(’access’);

$dsn = “Driver={Microsoft Access Driver (*.mdb)};Dbq=c:/nil/db1.mdb;Uid=Admin;Pwd=;”;
$db->Connect($dsn);

How to connect to Microsoft Excel using ODBC_CONNECT?

$excelFile = realpath(’c:/nil/InfoCaptor/dashboards/test_data.xls’);
$excelDir = dirname($excelFile);
$connection = odbc_connect(”Driver={Microsoft Excel Driver (*.xls)};DriverId=790;Dbq=$excelFile;DefaultDir=$excelDir” , ”, ”);

$result=odbc_exec($connection, ’select * from [detail_data$]‘);

echo “<table align=\”center\” border=\”1\” borderColor=\”\” cellpadding=\”0\” cellspacing=\”0\”>\n”;
echo “<tr> “;
// — print field name
$colName = odbc_num_fields($result);
for ($j=1; $j<= $colName; $j++)
{
echo “<th align=\”left\” bgcolor=\”#CCCCCC\” > <font color=\”#990000\”> “;
echo odbc_field_name ($result, $j );
echo “</font> </th>”;
}
$j=$j-1;
$c=0;
// end of field names
while(odbc_fetch_row($result)) // getting data
{
$c=$c+1;
if ( $c%2 == 0 )
echo “<tr bgcolor=\”#d0d0d0\” >\n”;
else
echo “<tr bgcolor=\”#eeeeee\”>\n”;
for($i=1;$i<=odbc_num_fields($result);$i++)
{
echo “<td>”;
echo odbc_result($result,$i);
echo “</td>”;
if ( $i%$j == 0 )
{
$nrows+=1; // counting no of rows
}
}
echo “</tr>”;
}

echo “</td> </tr>\n”;
echo “</table >\n”;
// –end of table

echo “<br/><center> Total Records: $nrows </center> <br/>”;
odbc_close ($conn);

How to connect Excel using php ADODB library?

include(”../adodb5/adodb.inc.php”);
include(”../adodb5/toexport.inc.php”);

$db =& ADONewConnection(’odbc’);

$excelFile = realpath(’c:/nil/InfoCaptor/dashboards/test_data.xls’);
$excelDir = dirname($excelFile);
$db->PConnect(”Driver={Microsoft Excel Driver (*.xls)};DriverId=790;Dbq=$excelFile;DefaultDir=$excelDir” , ”, ”);
$rs = $db->Execute(’select * from [detail_data$]‘);
print rs2csv($rs); # return a string, CSV format
$db->Close();

 

How to connect to Oracle?

 

How to connect to SQL Server?

 

How to connect to MySQL?

 

How to connect to DB2?

 

How to connect to PostGresSQL?

 

How to connect to SQLITE?

A new Reporting and Dashboard Platform

In the meanwhile Download

Dashboard Software

Responses are currently closed, but you can trackback from your own site.

Comments are closed.