0

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

zealous
  • 7,336
  • 4
  • 16
  • 36
Austin Hallett
  • 183
  • 1
  • 17
  • Does this answer your question? [Is it possible to access an SQLite database from JavaScript?](https://stackoverflow.com/questions/13192643/is-it-possible-to-access-an-sqlite-database-from-javascript) – zhuhang.jasper Jul 17 '20 at 21:01

1 Answers1

0

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.

zhuhang.jasper
  • 4,120
  • 4
  • 21
  • 29
  • Okay, I appreciate your input. This is all pretty new to me. I am using SQLite3 and the database connection is defined in my Django settings.py file. This script runs on the 'index.html' page. I am pretty sure that the connection does not need to be defined in the script because it is already defined in the settings...correct me if I am wrong – Austin Hallett Jul 17 '20 at 20:57
  • that is an entirely different technology stack you are using. please specify it in your question. – zhuhang.jasper Jul 17 '20 at 20:59