Adott egy utazok nevű tábla:
desc utazok; +-----------+-------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-----------+-------------+------+-----+---------+----------------+ | az | int(11) | NO | PRI | NULL | auto_increment | | nev | varchar(50) | YES | | NULL | | | telepules | varchar(50) | YES | | NULL | | +-----------+-------------+------+-----+---------+----------------+
Feladatunk: elérni az adatbázist, lekérdezni és beszúrni adatokat.
const mariadb = require('mariadb/callback'); const conn = mariadb.createConnection({ host: 'localhost', database: 'test02', user: 'test02', password: 'titok' }); conn.query("select * from utazok", (err, rows) => { console.log(rows); conn.end(); });
const mariadb = require('mariadb/callback'); const conn = mariadb.createConnection({ host: 'localhost', database: 'test02', user: 'test02', password: 'titok' }); conn.query("insert into utazok (nev, telepules) values (?, ?)", ["Pataki Sándor", "Szolnok"], (err, res) => { console.log(res); conn.end(); });