SQLSTATE[42000]: Syntax error or access violation: 1110 Column 'ID' specified twice

1,476 views
Skip to first unread message

kreilinger18

unread,
Jun 5, 2011, 6:02:46 PM6/5/11
to redbeanphp
hello!

i am using redbeanphp in one of my zend framework projects. this time
i had a already existing mysql database with much data.

i integrated redbeanphp into this project hooking in in the
Bootstrap.php of my project:
protected function _initRedBeanPHP() {
$config = $this->getOption("resources");
$dsn = "mysql:host=" . $config["db"]["params"]["host"] .
";dbname=" . $config["db"]["params"]["dbname"];

$loader = Zend_Loader_Autoloader::getInstance()-
>registerNamespace("RedBean_");
require_once(APPLICATION_PATH . "/../library/RedBean/rb.php");
$tools = RedBean_Setup::kickstartDev($dsn, $config["db"]
["params"]["username"], $config["db"]["params"]["password"]);
$tools->getRedBean()->freeze(true);

Zend_Registry::set("tools", $tools);
Zend_Registry::set("redbean", $tools->getRedBean());
}

i have a form to let the user change his email adress in the system.
as far as i know, the code for doing so would be something like this:
$rb = Zend_Registry::get("redbean");

$user = $rb->load("user", $this->session->user->ID);
$user->email = $new_email;
$rb->store($user);

when the last line gets executed, i always get this exception:
SQLSTATE[42000]: Syntax error or access violation: 1110 Column 'ID'
specified twice

do you have any ideas why this happens?

gabor

unread,
Jun 5, 2011, 6:22:36 PM6/5/11
to redbeanphp

Hi and welcome to the forum,

You say you are working on an existing database. What is the structure
of the user table? Does it already contain a column named id? You
might want to use the BeanFormatter... http://www.redbeanphp.com/#/Custom_Keys

Cheers,
Gabor

kreilinger18

unread,
Jun 5, 2011, 6:49:48 PM6/5/11
to redbeanphp
the structure is like this:
ID(int,pk)
username(varchar)
email(varchar)
...

i called freeze(true) in the bootstrapping process. shouldn't
therefore redbean stop altering the table and simply update the loaded
bean?

On Jun 6, 12:22 am, gabor <gabordemo...@gmail.com> wrote:
> Hi and welcome to the forum,
>
> You say you are working on an existing database. What is the structure
> of the user table? Does it already contain a column named id? You
> might want to use the BeanFormatter...http://www.redbeanphp.com/#/Custom_Keys

gabor de mooij

unread,
Jun 6, 2011, 2:17:53 AM6/6/11
to redbe...@googlegroups.com
Yes but the table format is different so that is why I guess you need to format the bean, it's trivial though

If I have some time I will send you an example when I am back from work

Cheers
Gabor

Verstuurd vanaf mijn iPhone

> --
> You received this message because you are subscribed to the Google Groups "redbeanphp" group.
> To post to this group, send email to redbe...@googlegroups.com.
> To unsubscribe from this group, send email to redbeanorm+...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/redbeanorm?hl=en.
>

gabor

unread,
Jun 11, 2011, 5:58:29 AM6/11/11
to redbeanphp
As promised, the example....


R::setup("mysql:host=localhost;dbname=oodb","root");

class Formatter implements RedBean_IBeanFormatter {
public function formatBeanID( $type ) {
return 'ID';
}
public function formatBeanTable( $type ) { return $type; }
}

R::$writer->setBeanFormatter( new Formatter );

This should solve the issue. Well I used R instead of $r, but you get
the idea.

Cheers
Gabor

On 6 jun, 08:17, gabor de mooij <gabordemo...@gmail.com> wrote:
> Yes but the table format is different so that is why I guess you need to format the bean, it's trivial though
>
> If I have some time I will send you an example when I am back from work
>
> Cheers
> Gabor
>
> Verstuurd vanaf mijn iPhone
>
Reply all
Reply to author
Forward
0 new messages