저는 Zend Framework 1.11.4와 Zend_Db를 사용하고 있습니다. 문제는, 나는 값이 0 또는 1 (BIT (1)) 인 성을위한 열을 가지고 있는데, 삽입을 잘하면 false를 넣었지만 사실로 만들면 다음과 같은 오류가 나타납니다. 'Data too long for column' sex 'on row 1'Zend_Db로 mysql 비트 열에 PHP 부울을 삽입하십시오.
나는 벌써 디버깅을했고 그것이 부울임을 확인했습니다! 거짓 (0) 오류없이,하지만 사실과 오류가 (클래스 Application_Model_UserNodeMapper) 발생 :
public function save(Application_Model_UserNode $user){
$sex = $user->getSex();
if($sex == 'm'){
$user->setSex(false); //NO ERROR!!
}
else{
$user->setSex(true); //ERROR!!
}
$data = $user->getProperties();
if(null === ($id = $user->getId())) {
unset($data['id']);
$id = $this->getDbTable()->insert($data);
return $id;
}
else{
$this->getDbTable()->update($data, array('id = ?' => $id));
return null;
}
}
코드 Application_model_UserNode (일부 속성은 내가 일을 명확히하기 위해 섹스에 SEXO을 변경, 포르투갈어에있는)에 대한 :
<?php
class Application_Model_UserNode
{
protected $id;
protected $nome_completo;
protected $nome_exibicao;
protected $senha;
protected $status;
protected $email;
protected $sex;
protected $data_nasc;
protected $cidade_id;
protected $pais_id;
function __construct(array $options = null)
{
if (is_array($options)) {
$this->setOptions($options);
}
}
public function __set($name, $value)
{
$method = 'set' . $name;
if (('mapper' == $name) || !method_exists($this, $method)) {
throw new Exception('Invalid userNode property');
}
$this->$method($value);
}
public function __get($name)
{
$method = 'get' . $name;
if (('mapper' == $name) || !method_exists($this, $method)) {
throw new Exception('Invalid guestbook property');
}
return $this->$method();
}
public function setOptions(array $options)
{
$methods = get_class_methods($this);
foreach ($options as $key => $value) {
$method = 'set' . ucfirst($key);
if (in_array($method, $methods)) {
$this->$method($value);
}
}
return $this;
}
public function getId() {
return $this->id;
}
public function setId($id) {
$this->id = $id;
}
public function getNome_completo() {
return $this->nome_completo;
}
public function setNome_completo($nome_completo) {
$this->nome_completo = $nome_completo;
}
public function getNome_exibicao() {
return $this->nome_exibicao;
}
public function setNome_exibicao($nome_exibicao) {
$this->nome_exibicao = $nome_exibicao;
}
public function getSenha() {
return $this->senha;
}
public function setSenha($senha) {
$this->senha = $senha;
}
public function getStatus() {
return $this->status;
}
public function setStatus($status) {
$this->status = $status;
}
public function getEmail() {
return $this->email;
}
public function setEmail($email) {
$this->email = $email;
}
public function getSex() {
return $this->sex;
}
public function setSex($sex) {
$this->sex = $sex;
}
public function getData_nasc() {
return $this->data_nasc;
}
public function setData_nasc($data_nasc) {
$this->data_nasc = $data_nasc;
}
public function getProperties(){
$properties = get_object_vars($this);
return $properties;
}
}
도움을 주셔서 감사합니다.
'sex'및 max size 열의 데이터 형식은 무엇입니까? Application_Model_UserNode 클래스의 코드는 무엇입니까? true가 문자열 'true'로 유지되는 동안 false는 '0'으로 변환 될 수 있습니다! – satrun77
섹스는 BIT (1)로 정의되므로 true와 false를 모두 받아 들여야합니다. 데이터베이스에서 직접 편집하지만 응용 프로그램에서는 편집하지 않으면 값 1을 허용합니다. 나는 Application_Model_UserNode 코드를 게시 할 것이다. – Jirico
http://stackoverflow.com/questions/839596/mysql-how-to-query-a-column-whose-type-is-bit – Thor