Jump to content

Inserting Problem


jayR

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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.