dongqu4443 2013-05-23 19:50
浏览 46
已采纳

Codeigniter上的简单查询和错误

I have a problem with CodeIgniter and Mysql. I am getting an error with a very simple query:

$o = "INSERT INTO usuarios (user, password) VALUES ('deesggsd', 'dsggd')";
$query = $this->db->query($o);
$this->db->query($query);

produces:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '1' at line 1

1

Filename: C:\wamp\www
ewWeb\system\database\DB_driver.php

Line Number: 330

But the query is actually executed; the row appears on the database. What i'm doind wrong?

If I execute the same query on phpmyadmin, all is ok.

Thanks!!!

  • 写回答

2条回答 默认 最新

  • duanbairan4235 2013-05-23 19:55
    关注

    What you are doing with $query = $this->db->query($o); is executing the query and storing the result to the $query variable. So you've already run the INSERT once which is why it stores properly to the database.

    Now when you try to run $this->db->query($query); you're basically trying to run a mysql procedure using the result (TRUE) as your query string. This is where it throws the error. Make sense?

    Try doing this instead:

    $this->db->insert('usuarios', array(
        'user'     => 'deesggsd',
        'password' => 'dsggd'
    );
    

    I suggest looking into Active Record and how interaction between PHP & mysql work in general. No offense but this is a beginner level mistake.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?