Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/241.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Zend_Db将php布尔值插入mysql位列_Php_Mysql_Zend Framework_Boolean_Zend Db - Fatal编程技术网

使用Zend_Db将php布尔值插入mysql位列

使用Zend_Db将php布尔值插入mysql位列,php,mysql,zend-framework,boolean,zend-db,Php,Mysql,Zend Framework,Boolean,Zend Db,我正在使用Zend Framework 1.11.4和Zend_Db。问题是,我有一个sex列,它的值为0或1(位(1)),当我输入false时,插入就可以了,但当输入true时,会出现以下错误:“第1行“sex”列的数据太长” 我已经调试并验证了它是布尔值!如果为false(0),则无错误,如果为true,则会发生错误(类应用程序\u模型\u用户节点映射): 应用程序\模型\用户节点的代码(一些属性是葡萄牙语的,我已将sexo更改为sex以澄清问题): 位数据类型的MySQL实现不一定是单个位

我正在使用Zend Framework 1.11.4和Zend_Db。问题是,我有一个sex列,它的值为0或1(位(1)),当我输入false时,插入就可以了,但当输入true时,会出现以下错误:“第1行“sex”列的数据太长”

我已经调试并验证了它是布尔值!如果为false(0),则无错误,如果为true,则会发生错误(类应用程序\u模型\u用户节点映射):

应用程序\模型\用户节点的代码(一些属性是葡萄牙语的,我已将sexo更改为sex以澄清问题):


位数据类型的MySQL实现不一定是单个位,但在创建表时可以在1到64位之间变化。大多数db连接器在数据类型转换方面都有困难,因为MySQL位实际上并不像您通俗地想象的那样。正确的解决方案是使用不是bit而是tinyint(1)的列类型,如您的注释所示。

列“性别”和最大大小的数据类型是什么?类应用程序\模型\用户节点的代码是什么?可能false已转换为“0”,而true保留为字符串“true”!性被定义为比特(1),所以它应该接受真与假。如果我直接从数据库编辑而不是从应用程序编辑,则它接受值1。我将发布应用程序\模型\用户节点代码。您的脚本在使用PHP5.3、Zend Framework 1.11.11和MYSQL 5.1.51时运行良好。你可能在什么地方有拼写错误。或者尝试使用最新版本的zend framework。否则,使用不同的数据类型是更安全的选择(tinyint)。
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;
}

}  
<?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;
}


}