dongwang788787 2012-07-03 11:08
浏览 58
已采纳

MySQLi不工作,没有错误,没有插入信息

I've been doing all people told me to make it works , but there is no errors and no inserted rows:

Any idea?

private $db;

// Constructor - open DB connection
function __construct() 
{
    $this->db = new mysqli('localhost', 'root', '', 'sampleinyoudb');
    $this->db->autocommit(FALSE);

    if (mysqli_connect_errno()) 
    {
        sendResponse(500, "Could not connect to the database!");
        exit();
    }
}

// Destructor - close DB connection
function __destruct() 
{
    $this->db->close();
}

...

        if($stmt = $this->db->prepare("INSERT INTO Users (id,email) VALUES (?, ?)"))
        {
            $test1 = 1; //Empty
            $test2 = 'asdasd@gmail.com'; //Empty
            $stmt->bind_param("is", $test1, $test2);
            $stmt->execute();   
            if ( false===$stmt ) 
            {
              die('execute() failed: ' . htmlspecialchars($mysqli->error));
            }               
            $stmt -> close();
        }
        else
        {
            printf("Prepared Statement Error: %s
", $this->db->error);
        }
        echo 'Any Errors: '.$this->db->error.PHP_EOL;
  • 写回答

1条回答 默认 最新

  • droe9376 2012-07-03 11:12
    关注

    You have specified autocommit(FALSE), but are not manually committing your transaction. At some point after $stmt->execute() you must put:

    $this->db->commit();
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 从Freecad中宏下载的DesignSPHysics,出现如下问题是什么原因导致的(语言-python)
  • ¥30 notepad++ 自定义代码补全提示
  • ¥15 MATLAB有限差分法解一维边值问题
  • ¥200 内网渗透测试 横向渗透 Windows漏洞 Windows权限维持
  • ¥15 数据结构图的相关代码实现
  • ¥15 python中aiohttp.client_exceptions.ContentTypeError
  • ¥30 DeepLung肺结节检测生成最大froc值对应的epoch报错
  • ¥15 信号发生器如何将频率调大,步尽值改成10
  • ¥15 keil 5 编程智能家具,风扇台灯开关,人体感应等
  • ¥100 找一名渗透方面的专家