2009年2月18日星期三

Re: [fw-db] Insert using Zend DB and an adapter

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkmc4hoACgkQ7bkAtAithutqPACgtgi026OnGWZztxg2NHA8NCsN
4VcAn1krcfuWQuo21CsWeXvrFTbprY0e
=rSUa
-----END PGP SIGNATURE-----
prickett wrote:
> I'm trying to insert a record into a MySql table that has no key. I'm using
> an adapter and the following code:
>
> Zend_Registry::get( "dbAdapter" )->insert( "USERS" , array( "username" =>
> $this->username , "password" => $this->password ) );
>
>
> This, however, results in a key violation.
>
> I see that when you do an insert from a table object (instead of from an
> adapter) you have the ability to say there is no key:
>
> class BugStatus extends Zend_Db_Table_Abstract{
> protected $_sequence = false;
> }
>
> Is there a way to do this via the adapter too?
>
> TIA

What you're doing looks fine. You don't need a key for an insert (in the
same way you would for and update).

What is the actual "key violation". Are you sure it's not a duplicate
key because you have username/password (or some other fields) set as
unique/primary in the database?

--

Brenton Alker

http://blog.tekerson.com/

没有评论: