import React from 'react';
import ReactDOM from 'react-dom';
// get the client
const mysql = require('mysql');
// First you need to create a connection to the db
const con = mysql.createConnection({
user: 'masterUsername',
password: 'masterPassword',
database : 'db_wmcw'
});
//try to connect to the mySql database. If an error occurs, display an error message on the console
con.connect((err) => {
if(err){
const product_title = "No connection to the server";
const product_description = err;
} else {
//a connection has been established to the database. Now, run a query against the table 'homepage'
//to retrieve each row and all columns of the table
con.query('SELECT * FROM homepage', (err,rows) => {
//if an error occurs when reading the data from the table, display the error on the console
if(err) {
const product_title = "Error reading data from the database";
const product_description = err;
} else {
// a record has been read from the database
const { product_title, product_description } = results[0];
}
});
}
});
con.end((err) => {
// The connection is terminated gracefully
// Ensures all previously enqueued queries are still
// before sending a COM_QUIT packet to the MySQL server.
});
const appTitle = React.createElement('div', null, product_title);
const appDescription = React.createElement('div', null, product_description);
ReactDOM.render(appTitle, document.getElementById('appTitle'));
ReactDOM.render(appDescription, document.getElementById('appDescription'));