Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
- $link = mysqli_connect('localhost', 'db_user', 'db_password', 'db_name');
- if (!$link) {
- printf("Невозможно подключиться к базе данных. Код ошибки: %s\n", mysqli_connect_error());
- exit;
- }
- $id = rand(1, 5);
- $name = "Maxim";
- function insert($link, $id, $name)
- {
- $sql = "INSERT INTO users (id, name) VALUES ('$id', '$name')";
- if (!$result = mysqli_query($link, $sql)) {
- throw new Exception();
- }
- return true;
- }
- try {
- insert($link, $id, $name);
- } catch (Exception $e) {
- echo $e->getCode();
- echo $e->getMessage();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement