I have a database with the following table:
Product_table
The product table has 3 columns; product_name, product_info, and product_cost
I need to query the database in order to pull all product names out, and put them in an array.
I know the SQL is 'SELECT product_name FROM product_table' but I don't know how to implement that in javascript.
Any guidance would be greatly appreciated
-
Does this answer your question? Is it possible to access an SQLite database from JavaScript?zhuhang.jasper– zhuhang.jasper2020年07月17日 21:01:39 +00:00Commented Jul 17, 2020 at 21:01
1 Answer 1
Edit: See here if it helps: Is it possible to access an SQLite database from JavaScript?
Your question is very badly asked.
I suggest you to use node.js: https://nodejs.org/en/download/ It allows you to run javascript without browser.
And I assume the database is MySQL. Then u will need the mysql package: https://github.com/mysqljs/mysql Refer the github documentation on how to install and use it.
Basically, you will use the mysql pacakge to make connection to your database (you need to provide the host/user/password), create database connection, then executes your SELECT query. The mysql package's conn.query(sql, params) already returns list of results in an array for you.