Solution to Activity 8.2
The solution to this activity is as follows:
- Using your text editor, create a script called
Activity_6_02_Solution_Populate_Tables.js
. - Start by connecting to the database and running a query to use
CustomerDatabase
:var mysqlconnection = require("./mysqlconnection.js"); mysqlconnection.query("USE CustomerDatabase", function (err, result) { if (err) throw err.code; console.log(result); });
- Next, create the customer records and insert them through a parameterized query:
var record = [['Big Company'],['Little Company'],['Old Company'],['New Company']]; var sql = "INSERT INTO customers(CustomerName) VALUES ?;" mysqlconnection.query(sql, [record], function (err, result) { if (err) throw "Problem creating database" + err.code; console.log(result); });
- Finally, create the...