duanping1632 2015-12-08 14:21
浏览 46
已采纳

MySqli为值返回NULL,无法插入或选择

My problem is that my db have no errors and still ignore my inserts, selects etc. So i tried var_dump() and it gives NULL for all variables. That is my connection query:

 $this->conexao = new mysqli('localhost:3307','root','', 'construsite');

And this is wrong, i think:

 public 'conexao' => 
 object(mysqli)[2]
  public 'affected_rows' => null
  public 'client_info' => null
  public 'client_version' => null
  public 'connect_errno' => null
  public 'connect_error' => null
  public 'errno' => null
  public 'error' => null
  public 'error_list' => null
  public 'field_count' => null
  public 'host_info' => null
  public 'info' => null
  public 'insert_id' => null
  public 'server_info' => null
  public 'server_version' => null
  public 'stat' => null
  public 'sqlstate' => null
  public 'protocol_version' => null
  public 'thread_id' => null
  public 'warning_count' => null

and my function to insert that is ignored:

public function registro(){
    //comando sql para inserir novo cliente
    $comando = "INSERT INTO clientes(id, nome_cliente, email_cliente, telefone_cliente, senha_cliente, data_nasc_cliente) "
    . "VALUES (NULL, '$this->nome_cliente', '$this->email_cliente', '$this->telefone_cliente', '$this->senha_cliente', STR_TO_DATE( '$this->data_nasc_cliente', '%Y/%d/%m')";
    //executa o comando
    $registro_resultado = $this->conexao->query($comando); //executa o comando
    return $registro_resultado;
}

I tried to find in google and here but i could not. (Sorry my bad english!!)

  • 写回答

1条回答 默认 最新

  • dthswrp84966 2015-12-08 14:28
    关注

    Id is primary key, and primary key doesn't accept null. if your primary key auto increment so remove id from insert query.

    $comando = "INSERT INTO clientes(nome_cliente, email_cliente, telefone_cliente, senha_cliente, data_nasc_cliente) "
        . "VALUES ('$this->nome_cliente', '$this->email_cliente', '$this->telefone_cliente', '$this->senha_cliente', STR_TO_DATE( '$this->data_nasc_cliente', '%Y/%d/%m'))";
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?