• Home
  • About Me
  • Contact
  • Things to do Before I Turn 30

the bofe blog

a twenty something IT professional with a few things to say

Feeds:
Posts
Comments

FreeTDS odbc_exec SQL STATE 00000 PHP Error

September 13, 2006 by bofe

This is just for posterity’s sake and a fix anyone who runs into this problem.

Scenario:

LAMP Box—we need to do queries on an external SQL Server Box.

Enter FreeTDS—not going to get into the details of the install, but you’ll have to reconfigure PHP and add a DSN to your php.ini or use php_set.

Let’s say you’re doing an insert to a system that isn’t really stellar in it’s database design. The tables primary key (ID) is set to a type of INTEGER, and it’s not an identity field. Translation for the MySQL folks: “no auto_increment”. Translation for the MSAccess crowd: “no Autonumber”. Translation for people who don’t understand relational databases: “I can’t believe you’re still reading. The rest of this post will make you want to gouge your eyes out, visit Wikipedia:Unusual Articles for some decent reading”.

Instead of being able have the system determine the value of ID, we have to do it ourself.

$result = odbc_exec(“SELECT MAX ( ID ) as INSERT_ID from TABLE;”);

Since we’re only retrieving one row, it’s not really appropriate to loop through our result, so we obtain the value of the result thusly:

$data = odbc_result($result, “INSERT_ID”);

Now none of your queries will work from this point on in your code. To fix this:

odbc_free_result($result);

Just free the result.

Ah, the lessons learned today.

Posted in Personal | Tagged Geek, Personal | No Comments Yet

  • Pages

    • About Me
    • Contact
    • Things to do Before I Turn 30
  • Recent Comments

    • Some Betty on Why the hate?
    • stinkypie on Why the hate?
    • stinkypie on Why the hate?
    • JohnO on Why the hate?
    • Yee on a pancake on Why the hate?
    • adam on Why the hate?
    • JohnO on Why the hate?
    • deezil on Why the hate?
    • Yee on a pancake on Why the hate?
    • Dave on Why the hate?
  • Recently Popular

    • Guide to Backing up your Virtual Machines with VMware Consolidated Backup (VCB)
    • Sync Google Calendar and Facebook Events
    • How to Use Excel 2007 and Goal Seek to calculate what the minimum grade you need on a final exam
    • VMware Consolidated Backup: Explained
    • Firefox 3 Constantly Crashes -- advice?
    • modifying osCommerce - [part 2 - Functions, Cases, Blocks Oh My]
    • Problem with Orphaned Users/Logins in SQL Server 2005 Migration
    • Facebook 12 Step Program
    • Sortables with Scriptaculous, PHP, and MySQL in 6 Easy Steps
    • point(x,y) versus point(lat, long) or What I Learned Today
  • Archives

  • Tags

    4815162342 advertising ajax apple bofehax byebye css dba delicious links development drm facebook finance firefox Geek gis Google imadork linux mememe Meta metoo money murray Music mysql owensboro Personal personal finance personalfinance philosophy php rss scriptaculous sqlserver sqlserver2005 Tablet PC Uncategorized vmware web Weblogs Web Standards whitewhine work wtf
  • Meta

    • Log in
    • Entries RSS
    • Comments RSS
    • WordPress.com

Blog at WordPress.com.

Theme: Mistylook by Sadish.