General error: 1366 Incorrect integer value with Doctrine 2.1 and Zend Form update
我正在处理提交的Zend表单,该表单使用以下代码更新了Doctrine记录,其中$ query是使用教义查询构建器构建的查询:
1 2 3 4 5 6 7 8 9 10 11 12 13 | $record_array = $query->getResult(); $this->_record = $record_array[0]; if($this->getRequest()->isPost()) { if ($this->_form->isValid($this->_request->getPost())) { $newEntity = $this->_form->update($this->_record); $this->_em->flush(); $this->view->success = 'Record Saved.'; } else { $this->view->errors = $this->_form->getErrors(); } } |
如果记录中没有整数(即仅字符串),则上述方法可以正常工作。 但是,如果我在表单中包含在学说实体中映射为整数的字段,则会出现上述错误。
任何帮助,将不胜感激。
更新:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 | /** * @var integer $solicitorid * * @Column(name="SolicitorID", type="integer", nullable=false) * @Id * @GeneratedValue(strategy="IDENTITY") */ private $solicitorid; /** * @var string $solicitor * * @Column(name="Solicitor", type="string", length=160, nullable=true) */ private $solicitor; /** * @var string $address * * @Column(name="Address", type="string", length=160, nullable=true) */ private $address; /** * @var string $town * * @Column(name="Town", type="string", length=100, nullable=true) */ private $town; /** * @var string $county * * @Column(name="County", type="string", length=100, nullable=true) */ private $county; /** * @var string $postcode * * @Column(name="Postcode", type="string", length=100, nullable=true) */ private $postcode; /** * @var string $dxaddress * * @Column(name="DXAddress", type="string", length=150, nullable=true) */ private $dxaddress; /** * @var string $phone * * @Column(name="phone", type="string", length=30, nullable=true) */ private $phone; /** * @var string $fax * * @Column(name="fax", type="string", length=30, nullable=true) */ private $fax; /** * @var string $email * * @Column(name="email", type="string", length=255, nullable=true) */ private $email; /** * @var string $password * * @Column(name="password", type="string", length=30, nullable=false) */ private $password; /** * @var integer $leadStatus * * @Column(name="lead_status", type="integer", nullable=true) */ private $leadStatus; /** * @var string $termsref * * @Column(name="termsRef", type="string", length=10, nullable=true) */ private $termsref; /** * @var integer $termsconditions * * @Column(name="termsconditions", type="integer", nullable=true) */ private $termsconditions; /** * @var date $termssent * * @Column(name="termsSent", type="date", nullable=true) */ private $termssent; /** * @var date $termssigneddate * * @Column(name="termssigneddate", type="date", nullable=true) */ private $termssigneddate; /** * @var integer $paymentterms * * @Column(name="paymentterms", type="integer", nullable=true) */ private $paymentterms; /** * @var integer $discountterms * * @Column(name="discountterms", type="integer", nullable=true) */ private $discountterms; /** * @var float $discountrate * * @Column(name="discountrate", type="float", nullable=true) */ private $discountrate; /** * @var integer $accountscontact * * @Column(name="AccountsContact", type="integer", nullable=true) */ private $accountscontact; /** * @var date $warned * * @Column(name="warned", type="date", nullable=true) */ private $warned; /** * @var float $feerate * * @Column(name="FeeRate", type="float", nullable=true) */ private $feerate; /** * @var string $labourrate * * @Column(name="LabourRate", type="string", length=100, nullable=true) */ private $labourrate; /** * @var text $specialinst * * @Column(name="SpecialInst", type="text", nullable=true) */ private $specialinst; /** * @var text $reportinst * * @Column(name="ReportInst", type="text", nullable=true) */ private $reportinst; /** * @var boolean $autostatement * * @Column(name="AutoStatement", type="boolean", nullable=true) */ private $autostatement; /** * @var datetime $lastmodifed * * @Column(name="lastModifed", type="datetime", nullable=false) */ private $lastmodifed; |
以上是实体。
当我尝试更新整数字段时,问题就来了。
您正在使用MySQL吗? 发生这种情况是因为MySQL在严格模式下运行。
从phpMyAdmin或您正在使用的任何数据库管理员运行这些查询,以检查数据库是否处于严格模式下:
1 2 | SELECT @@GLOBAL.sql_mode; SELECT @@SESSION.sql_mode; |
如果返回包含
1 | SET @@global.sql_mode= 'NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'; |