私はZend Framework 1.11.4とZend_Dbを使用しています。問題は、私は値が0または1(BIT(1))、私は挿入がうまくいけば、私は本当に次のエラーが表示されます:性別 '行1'PHPのブール値をZend_Dbのmysqlビット列に挿入
私はすでにデバッグし、それがブール値であることを確認しました!偽(0)エラーなしでは、真のでエラーが(クラスApplication_Model_UserNodeMapper)が起こる:Application_model_UserNodeため
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;
}
}
コード(一部のプロパティは、ポルトガル語で、私は物事を明確にするために、セックスに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の列のデータ型は何ですか? Application_Model_UserNodeクラスのコードは何ですか? Trueが文字列 'true'として保持されている間に、falseが '0'に変換された可能性があります。 – satrun77
セックスはBIT(1)と定義されているため、真と偽の両方を受け入れる必要があります。データベースから直接編集する場合は値1を受け取りますが、アプリケーションからは編集しません。私はApplication_Model_UserNodeコードを掲示します。 – Jirico
http://stackoverflow.com/questions/839596/mysql-how-to-query-a-column-whose-type-is-bit – Thor