note 68056 added to function.odbc-primarykeys
| From: | ewildeahtbsmdevelopmentdawtcom at osu1 dot php dot net | Date: | Tue, 11 Jul 2006 22:39:37 +0000 |
| Subject: | note 68056 added to function.odbc-primarykeys | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-114681@lists.php.net to get a copy of this message | ||
I was trying to find the primary keys from an SQLServer database through the ODBC interface.
Funnily enough, the odbc_primarykeys function doesn't work with SQLServer (at least not my
implementation of it). Fortunately, the sp_keys query is passed through and the answer returned.
This code works (providing you know which database you're dealing with, which is a whole
'nother story).
// If this is SQLServer, we need to do a special operation to get the
// primary keys.
//
// Looks like the implementers of the ODBC interface just blew this
// one off, since the database has a query to return the info and the
// info even comes back with the same column names.
if ($DBType == "SQLServer")
$KeySel = odbc_exec($DBConn, "sp_pkeys ".$TableName);
// Otherwise, ask the database through ODBC for the primary key
// names.
else $KeySel = odbc_primarykeys($DBConn, $DatabaseName,
$DatabaseUser, $TableName);
while ($KeySel && ($KeyRec = odbc_fetch_array($KeySel)))
$KeyCol[$KeyRec["KEY_SEQ"]] = $KeyRec["COLUMN_NAME"];
----
Server IP: 64.71.164.2
Probable Submitter: 68.162.206.60
----
X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER
autolearn=no version=2.64
----
Manual Page -- http://www.php.net/manual/en/function.odbc-primarykeys.php
Edit -- http://master.php.net/note/edit/68056
Del: integrated -- http://master.php.net/note/delete/68056/integrated
Del: useless -- http://master.php.net/note/delete/68056/useless
Del: bad code -- http://master.php.net/note/delete/68056/bad+code
Del: spam -- http://master.php.net/note/delete/68056/spam
Del: non-english -- http://master.php.net/note/delete/68056/non-english
Del: in docs -- http://master.php.net/note/delete/68056/in+docs
Del: other reasons-- http://master.php.net/note/delete/68056
Reject -- http://master.php.net/note/reject/68056
Search -- http://master.php.net/manage/user-notes.php