Jump to content


Photo

Inserting Problem


  • Please log in to reply
No replies to this topic

#1 jayR

jayR
  • Members
  • PipPip
  • Member
  • 26 posts

Posted 01 June 2006 - 03:00 PM

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.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users