我正在使用visual fox pro OLE DB Provider(vfpoledb.dll)访问php中的VFP数据库。我想用与使用PDO或其他数据库抽象层相同(或类似)的方式为我要进行的查询准备语句。
有人知道你是否可以以及最好的方式来准备一份声明,以避免注射攻击吗?
$conn = new COM("ADODB.Connection");
$conn->Open('Provider=VFPOLEDB.1;Data Source="' . $path . '";');
// Bad!
$up = $conn->Execute("UPDATE tablename SET fieldname='Testing' WHERE fieldname = '" . $value . "'")
// Good?
...
或者/如果有人知道哪里有可以通过这个COM dll访问的方法的引用,那就太棒了。
这只是未来走这条路的人的最新消息。
我最终使用ADOdb数据库抽象库PHP解决了这个问题http://adodb.sourceforge.net/
一个例子:
// Path to your dbc file
$path = '/path/to/the/file.dbc';
// Create A FoxPro connection
$db = ADONewConnection('vfp');
// Create DSN
$dsn = "Driver={Microsoft Visual FoxPro Driver};SourceType=DBC;SourceDB=" . path . ";Exclusive=No;";
// Contact or die trying
$db->Connect($dsn) or die('Error connect with Visual FoxPro Driver');
// Set fetch mode (this just makes the return values easier to parse)
$db->SetFetchMode(ADODB_FETCH_BOTH);
// Your Query - use ? as the var
$query = "SELECT fieldname_a, fieldname_b FROM tablename WHERE fieldname_c = ? AND fieldname_d = ?";
// Your Query Params
$queryParms = array('valueYouAreSearchingFor_c', 'valueYouAreSearchingFor_d');
// Execute the query
$rs = $db->Execute($query, $queryParms);
// An example looping the results (>= php5)
foreach ($rs as $row) {
// Print out examples
print_r($row);
echo $row["fieldname_a"];
echo $row["fieldname_b"];
}
// Don't forget to clean up after yourself
$rs->Close();