
Bug #13604 odbc_primarykeys with Access
Submitted: 2001-10-08 16:58 UTC Modified: 2002-09-09 01:00 UTC
Avg. Score:4.6 ± 1.0
Reproduced:15 of 15 (100.0%)
Same Version:5 (33.3%)
Same OS:8 (53.3%)
From: phperror at gustl dot at Assigned:
Status: No Feedback Package: ODBC related
PHP Version: 4.0.6 OS: W98, W98SE
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2001-10-08 16:58 UTC] phperror at gustl dot at

i don't get odbc_primarykeys () working with access-dbs. example:

    $dsn = "accessdsn"; $user = ""; $pass = ""; $db = "accessdb";
#    $dsn = "mssqldsn"; $user = ""; $pass = ""; $db = "mssqldb";
#    $dsn = "mysqldsn"; $user = ""; $pass = ""; $db = "mysqldb";

$con = odbc_connect ($dsn, $user, $pass) or die ("no connect to $dsn");

$res = odbc_tables ($con, $db, "", "%", "'TABLE'") or die ("no tables in $db of $dsn");
odbc_result_all ($res);

echo "<h2>Tables in db $db of $dsn</h2>";
while (odbc_fetch_row ($res)) {
  $qualifiers [] = odbc_result ($res, 1);
  $owners     [] = odbc_result ($res, 2);
  $tables     [] = odbc_result ($res, 3);
print_r ($tables);

reset ($tables);
while (list ($i, $table) = each ($tables)) {
  echo "<h2>keys of ".$table." (".$qualifiers [$i].", ".$owners [$i].")</h2>";
  $res = odbc_primarykeys ($con, $qualifiers [$i], $owners [$i], $table);
  if ($res)
    odbc_result_all ($res);
    echo (odbc_error ().": ".odbc_errormsg ()."<BR>");
##  must close, otherwise php 4.05RC1, 4.06 crashes
odbc_close ($con);
echo ("ende");


in PHP4.06 I get the following php errormsg:
Warning: SQL error: , SQL state 00000 in SQLPrimaryKeys in c:/arbeit/test/odbc2.php4 on line 23
I tried all the combinations of setting the parameters with spaces and/or "%", no chance.

Gustav Graf


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2002-06-06 13:00 UTC] josh at engledental dot com
I get the same error when trying to run odbc_specialcolumns.  SQL state 00000 is success, so I guess its the ODBC driver which isn't handling things correctly?  Any ideas?
 [2002-07-29 12:55 UTC] jeff dot albert at ualberta dot ca
I'm having the same problem with win2k, Apache, and PHP 4.2.2, accessing any of a number of Access databases; the error seems to occur with any attempt access any of the following functions:


incidentally, occasionally the tables functions will actually cause php.exe to crash outright. Here's the simplest example of code that causes the problem:

$con = odbc_connect("dev", "", "");
$result = odbc_columnprivileges($con, "", "", "", "%");

jeff albert
 [2002-07-29 13:58 UTC]
Jeff please limit yourself to one bug report per bug.  If you have issues with other ODBC functionality, feel free to open a seperate bug report.  
 [2002-08-05 20:38 UTC]
Using the latest CVS I cannot get your sample code to work at all.  It seems the $tables is never populated on my end.  Any chance you can post a sample schema, or see if this is still happening?
 [2002-09-09 01:00 UTC] php-bugs at lists dot php dot net
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 [2003-07-12 03:04 UTC] sa_kelkar at yahoo dot com
I have same problem with odbc_primarykeys when i am using with the DB2. Please guide me

my code is
	//include '';


echo $m;
 [2006-08-11 03:45 UTC] kaspernj at gmail dot com

I have the exact same problem with the latest CVS of PHP 5.1, Access-database saved with Access 2003, Windows XP 32bit with SP2 and all the latest updates (11-08-2006).

The warning I get is this:
Warning: odbc_primarykeys(): SQL error: , SQL state 00000 in SQLPrimaryKeys in D:\phpprogs\knj_sqladmin\DBConn.php on line 357

...with the following code:
   $f_gpk = odbc_primarykeys($this->conn, "", "", $tablename);

$this->conn is being used many times, before it fails on "odbc_primarykeys()", so I have established a connection to the Access database - I am sure. It is possible to read the tables data.

odbc_columns() works as espected.
odbc_tables() works as espected.
 [2007-05-26 12:16 UTC] ahmedmatah at yahoo dot com
 [2009-05-09 20:28 UTC] joost at cnoc dot nl
This is not so strange, since MS Access doesn't support the odbc  SQLPrimaryKeys-api call. So this will never work as long as Microsoft doesn't fix this.
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.