Jump to content

[SOLVED] Using parameterized queries on an MDB


fr34k

Recommended Posts

I'm connecting to a database using the following method:

 

$connection = new COM("ADODB.Connection");
$connection->open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\path\to\my\database.mdb;");

 

I'm pretty much stuck with using Access and linking straight to the file in the connection string.

 

Using this connection, I want to be able to utilize parameterized queries/prepared statements.  I can't figure out how, exactly, to do this.  I haven't even really found anything coherent on doing this in PHP with an Access MDB.  I have found articles on doing this in ASP, but my efforts to port the code have been fruitless.

 

Any help would be immensely appreciated!

majority of PHP users run MySQL or Oracle or PROTEGSQL there is ODBC interactions with php and those might be of aid.

 

Access is not a database language rather a piece of software to view a database.  I do believe it uses ODBC or MSDBC or something like that.

Access is not a database language rather a piece of software to view a database.

 

I didn't mean to imply that Access was a DB language.  I was just saying that I'm stuck with using an MDB created from Access, instead of using anything else, like MySQL.

 

there is ODBC interactions with php and those might be of aid.

 

I've tried toying with the ODBC functionality in PHP and haven't met with much success.  One thing I attempted to use was odbc_prepare, but couldn't quite get things ironed out.  I wish I could give more detail, but the script is currently at the office and I won't be until tomorrow morning.  :P

I've finally figured it out.  I still didn't have any luck with odbc_prepare, but I did finally piece ASP ideas into PHP.

 

An example with a long string parameter...

 

<?
$dbConn = new COM("ADODB.Connection") or die("Cannot start ADO connection");
$dbCmd = new COM("ADODB.Command") or die("Cannot create ADO command object");
$dbConn->Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=c:\\path\\to\\my\\database.mdb");
$dbCmd->ActiveConnection = $dbConn;

$param1 = $dbCmd->CreateParameter("@param1", 201, 1, strlen($param1Value), $param1Value);

$dbCmd->CommandText = "UPDATE table SET field = @param1 WHERE ID = " . $recordId;
$dbCmd->Parameters->Append($param1);
$dbCmd->Execute();
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.