Tuesday, March 27, 2012

Access database with php access

Hello all,

forgive me if this isn't the right forum for this isue

I'm using the following php code:

$db = realpath("database/userdatabase.mdb") or die('<b>Connectie met database mislukt</b>');

$conn = new COM("ADODB.Connection");
$conn->Open("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=$db");

$conn->Execute("INSERT INTO TblNews(Title, Nieuws, Date, Author) VALUES ('Testing', 'tekst', '16Oktober2006', 'Ikke')");

$conn->Execute("INSERT INTO TblNews VALUES (20,'Testing', 'tekst', '16 Oktober 2006', 'Ikke')");


The 2nd insert command works perfectly but the first gives an error all the time!
The table has a NewsID with auto_increment on..

The error:
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] Syntax error in INSERT INTO statement.' in d:\www\tiedtzat.nl\www\nieuw\testdb.php:19 Stack trace: #0 d:\www\tiedtzat.nl\www\nieuw\testdb.php(19): com->Execute('INSERT INTO Tbl...') #1 {main} thrown in site.com\testdb.php on line 19

Thanks for the help in advance! :)

Hi,

if the driver does not bring back any detailed information you should try to execute the query within access to see a more detailed error information. As from your queries ir could be taht your second queries fills a not nullable field which is not filled within the first query. Which columns are you filling in the second query that you don′t dill in the first one ?

HTH, Jens K. Suessmeyer.

http://www.sqlserver2005.de

|||

Hey,

I found the problem!
I was using Date as one of the fields in the table which access doesn't seem to accept :)

Thanks for your help!

|||

Hi TrojanH: (sorry for my English I only speak Spanish) I'm traying too use PHP with Ms Accesss database and ADODB.Connection but have not found a manual about ADO and PHP. and I'not able mannage the recordset , I need know how do a seek, like mysql_data_seek or know the record number etc,

if it's possible can you tellme where to find info?

Thanks.

|||

Hello Gabriel,

As you might have noticed, information about adodb.connection is very hard to find on the Internet so I don't have much information...

What I use in php is this:

$db = realpath("database/db.mdb") or die('<b>Connection failed</b>');

$conn = new COM("ADODB.Connection");
$conn->Open("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=$db");

$rs = $conn->Execute("Select blabla... yadi yadi");

while(!$rs->EOF){

$blabla = $rs->Fields("blabla")->value;

$rs->MoveNext(); // Dont forget this!!!

}

good luck!|||

TrojanH:

that is the only way I know to view-manage the base. but I need more than this,

Thank.

|||

Gabriel wrote:

TrojanH:

that is the only way I know to view-manage the base. but I need more than this,

Thank.

The Execute performs all actions including update, delete etc...

I don't know what you need to know exactly but that probably goes beyond my knowledge about access databases Sad

|||

Hi again:

Actualy I know how to do SELECT, INSERT, UPDATE & DELETE.

But I need functions link : "mysql_data_seek()", "mysql_num_rows()", or " Select * from tabla LIMIT $ini, $reg "

This kind of funtions that allow to manage data.

|||

Gabriel wrote:

"mysql_num_rows()"

You could try the standard count(*) function in sql

Gabriel wrote:

" Select * from tabla LIMIT $ini, $reg "

As far as I know, there is no 'LIMIT' in sql (only mysql) and sql will only accept stuff like "Select TOP 10 * FROM..."

Sorry, cant help you any further with this... I hope this works for you Smile

No comments:

Post a Comment