Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [ZendFramework][inny]Dodawanie rekordu
Forum PHP.pl > Forum > PHP > Frameworki
Animax
Witam,
otóż mam problem z dodawaniem rekordu do bazy (nadpisywanie rekordu działa).

Przy "spłukiwaniu" (screen błędu)

Kod z controllera:
  1. $em = Zend_Registry::get("em");
  2. $account = new Application_Model_Account;
  3. $em->persist($account);
  4. $em->flush();


  1. --
  2. -- Struktura tabeli dla `accounts`
  3. --
  4.  
  5. CREATE TABLE IF NOT EXISTS `accounts` (
  6. `id` int(11) NOT NULL AUTO_INCREMENT,
  7. `name` varchar(32) NOT NULL DEFAULT '',
  8. `password` varchar(255) NOT NULL,
  9. `premdays` int(11) NOT NULL DEFAULT '0',
  10. `lastday` int(10) UNSIGNED NOT NULL DEFAULT '0',
  11. `email` varchar(255) NOT NULL DEFAULT '',
  12. `key` varchar(20) NOT NULL DEFAULT '0',
  13. `blocked` tinyint(1) NOT NULL DEFAULT '0' COMMENT 'internal usage',
  14. `warnings` int(11) NOT NULL DEFAULT '0',
  15. `group_id` int(11) NOT NULL DEFAULT '1',
  16. PRIMARY KEY (`id`),
  17. UNIQUE KEY `name` (`name`)
  18. ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=8 ;
  19.  
  20. --
  21. -- Zrzut danych tabeli `accounts`
  22. --
  23.  
  24. INSERT INTO `accounts` (`id`, `name`, `password`, `premdays`, `lastday`, `email`, `key`, `blocked`, `warnings`, `group_id`) VALUES
  25. (1, '2', '1', 65535, 0, '', '0', 0, 0, 1),
  26. (2, '', '', 0, 0, '', '0', 0, 0, 1);


Model:
  1. <?php
  2. /**
  3.  * @Entity
  4.  * @Table(name="accounts")
  5.  */
  6. class Application_Model_Account
  7. {
  8. /**
  9.   * @Id
  10.   * @Column(type="integer")
  11.   * @GeneratedValue(strategy="AUTO")
  12.   */
  13. private $id;
  14. /** @Column(type="string") */
  15. private $name = "";
  16. /** @Column(type="string") */
  17. private $password = "";
  18. /** @Column(type="integer") */
  19. private $premdays = 0;
  20. /** @Column(type="integer") */
  21. private $lastday = 0;
  22. /** @Column(type="string") */
  23. private $email = "";
  24. /** @Column(type="string") */
  25. private $key = "";
  26. /** @Column(type="integer") */
  27. private $blocked = 0;
  28. /** @Column(type="integer") */
  29. private $warnings = 0;
  30. /** @Column(type="integer") */
  31. private $group_id = 1;
  32.  
  33. public function __construct() {}
  34.  
  35. public function setId($id) {
  36. $this->id = $id;
  37. return $this;
  38. }
  39.  
  40. public function getId() {
  41. return $this->id;
  42. }
  43.  
  44. public function setName($name) {
  45. $this->name = $name;
  46. return $this;
  47. }
  48.  
  49. public function getName() {
  50. return $this->name;
  51. }
  52.  
  53. public function setPassword($password) {
  54. $this->password = $password;
  55. return $this;
  56. }
  57.  
  58. public function getPassword() {
  59. return $this->password;
  60. }
  61.  
  62. public function setPremdays($premdays) {
  63. $this->premdays = $premdays;
  64. return $this;
  65. }
  66.  
  67. public function getPremdays() {
  68. return $this->premdays;
  69. }
  70.  
  71. public function setLastday($lastday) {
  72. $this->lastday = $lastday;
  73. return $this;
  74. }
  75.  
  76. public function getLastday() {
  77. return $this->lastday;
  78. }
  79.  
  80. public function setEmail($email) {
  81. $this->email = $email;
  82. return $this;
  83. }
  84.  
  85. public function getEmail() {
  86. return $this->email;
  87. }
  88.  
  89. public function setKey($key) {
  90. $this->key = $key;
  91. return $this;
  92. }
  93.  
  94. public function getKey() {
  95. return $this->key;
  96. }
  97.  
  98. public function setBlocked($blocked) {
  99. $this->blocked = $blocked;
  100. return $this;
  101. }
  102.  
  103. public function getBlocked() {
  104. return $this->blocked;
  105. }
  106.  
  107. public function setWarnings($warnings) {
  108. $this->warnings = $warnings;
  109. return $this;
  110. }
  111.  
  112. public function getWarnings() {
  113. return $this->warnings;
  114. }
  115.  
  116. public function setGroupId($group_id) {
  117. $this->group_id = $group_id;
  118. return $this;
  119. }
  120.  
  121. public function getGroupId() {
  122. return $this->group_id;
  123. }
  124. }


Szukałem błędów, ale nie mam pomysłu. Problem jest z zapytaniem chyba / wartościami, ale nie jestem pewny.
phpion
Chodzi chyba o nazwę kolumny key - to słowo używane jest przy definiowaniu kluczy. Poszukaj w jaki sposób escape'ować nazwy kolumn w zapytaniu, albo zmień nazwę kolumny na inną.
Animax
Dzięki, rozwiązane:
  1. @Column(name="`key`", type="string")
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.