query(„CREATE TABLE IF NOT EXISTS language ( Code text NOT NULL, Speakers int(11) NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;“); /* Start transaction */ $mysqli->begin_transaction(); try { /* Insert some values */ $mysqli->query(„INSERT INTO language(Code, Speakers) VALUES (‘DE’, 42000123)“); /* Try to insert invalid values */ $language_code = ‘FR’; $native_speakers = ‘Unknown’; $stmt = $mysqli->prepare(‘INSERT INTO language(Code, Speakers) VALUES (?,?)’); $stmt->bind_param(‘ss’, $language_code, $native_speakers); $stmt->execute(); /* If code reaches this point without errors then commit the data in the database */ $mysqli->commit(); } catch (mysqli_sql_exception $exception) { $mysqli->rollback(); throw $exception; }

By admin