Tuesday, February 22, 2011

Query Foxpro Qatabase(db4) using PHP

see sample script below:
note: you must first install the Microsoft FoxPro VFP Driver

String used to connect to database:

$conn=odbc_connect(“Driver={Microsoft FoxPro VFP Driver (*.dbf)};SourceDB=m:;SourceType=DBF;Exclusive=No;”,”,”);
if (!$conn) {exit(“Connection Failed: ” . $conn);}

Assign and Execute Query:

$sql=”SELECT * FROM m:/table.dbf where name = ‘Mark’ “;
$rs=odbc_exec($conn,$sql);
if (!$rs) {exit(“Error in SQL”);}

Gather/Show Data:

while (odbc_fetch_row($rs))
{
$name=odbc_result($rs,”name”);
$address=odbc_result($rs,”address”);
$age=odbc_result($rs,”age”);
echo “Name: ” . $name . “
”;
echo “Address: ” . $address . “
”;
echo “Age: ” . $age . “
”;
}

Close Connection:

odbc_close($conn);

No comments:

Post a Comment