A.Quiroga
A.Quiroga

Reputation: 5722

MySQLi is not working , no errors , no inserted info

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 = '[email protected]'; //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\n", $this->db->error);
        }
        echo 'Any Errors: '.$this->db->error.PHP_EOL;

Upvotes: 2

Views: 420

Answers (1)

eggyal
eggyal

Reputation: 125855

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

$this->db->commit();

Upvotes: 6

Related Questions