Jump to content

Archived

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

jayR

Inserting Problem

Recommended Posts

Ok, so I need to connect to my Access database. I found a tutorial and followed it and it works fine. The code I used from that tutorial is this:

<?php
$conn = new COM("ADODB.Connection") or die("Cannot start ADO");

// Microsoft Access connection string.
$conn->Open("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=C:\\filepath\\db.mdb");

// SQL statement to build recordset.
$rs = $conn->Execute("SELECT Priority FROM Priority");
echo "<p>Below is a list of values in the MYDB.MDB database, MYABLE table, MYFIELD field.</p>";

// Display all the values in the records set

while (!$rs->EOF) {
$fv = $rs->Fields("Priority");
echo "Value: ".$fv->value."<br>\n";
$rs->MoveNext();
}

$rs->Close();
?>



Everything prints out well, so I thought I was set. However, when I change the file to something like this:



<?php
$conn = new COM("ADODB.Connection") or die("Cannot start ADO");

// Microsoft Access connection string.
$conn->Open("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=C:\\filepath\\db.mdb");

// SQL statement to build recordset.

$rs = $conn->Execute("insert into Priority(Priority) values ('InsertedData')");

$rs->Close();
?>



I get an error that reads:
Fatal error: Uncaught exception 'com_exception' with message '<b>Source:</b> Microsoft OLE DB Provider for ODBC Drivers<br/><b>Description:</b> [Microsoft][ODBC Microsoft Access Driver] '(unknown)' is not a valid path. Make sure that the path name is spelled correctly and that you are connected to the server on which the file resides.' in C:\wamp\www\access.php:5 Stack trace: #0 C:\wamp\www\access.php(5): com->Open('DRIVER={Microso...') #1 {main} thrown in C:\wamp\www\access.php on line 5



Maybe I misunderstood, but I thought you just put your sql after the Execute(" section and let it do its thing, but thats obviously not working so I'm hoping someone can point me in the right direction. Thanks.

Share this post


Link to post
Share on other sites

×

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.