mysql

I want to take out the result from mysql's connection.query and save it in global scope chain in nodejs

非 Y 不嫁゛ 提交于 2021-02-11 13:02:14
问题 I tried bringing out result by storing in variable current product. But I cant use it outside the function, so my array returns empty var connection = mysql.createConnection({ host: config.config.mysql.opencart_local.host, user: config.config.mysql.opencart_local.user, password: config.config.mysql.opencart_local.password, database: config.config.mysql.opencart_local.database }) var query_current_products = 'select * from table;'; var current_products = []; connection.connect(function(err) {

JS Can't query MySQL database. ERROR: connection.query is not a function

血红的双手。 提交于 2021-02-11 12:56:58
问题 Trying to query my mySQL database but I can't because i get a TypeError: connection.query is not a function error. Does anyone have any idea why? I don't have any clue as to why this is happening. database.js const fs = require('fs'); // node.js file system module require('dotenv').config(); // stores tokens, keys, passwords and other info const Discord = require('discord.js'); // links discord.js api to file const database = require('./database.js'); const client = new Discord.Client(); //

Indicate a valid procedure call

我的未来我决定 提交于 2021-02-11 12:50:32
问题 I come with a question and hope to get an answer Well, my question is: Indicate the correct procedure call I wonder about the answers: b or d but I do not know if this is a good "way of thinking" create procedure car2(out average float) begin select avg(cena) into average from car; end // a) call car2 (average); b) call car2 (@total); c) call car2 (); d) Neither answer is correct Thank you in advance for your answer and maybe explaining why this answer and not another one 回答1: The answer a)

Possible to use IF in a query?

拈花ヽ惹草 提交于 2021-02-11 12:47:14
问题 I'm using Grafana to plot data from a MySQL datasource. Is it possible to, in a panel's query editor, use an IF ... THEN ... type statement. I would like to create a variable that I could put in the IF. I want the variable to be a condition, not necessarily to be used directly in the query. For example: //IN THE DATA SOURCE: CREATE TABLE Example (Id INT, ANIMALS VARCHAR(15)); INSERT INTO Example VALUES (1,'Dog'), (2,'Fish'), (3,'Cat'), (4,'Lizard') For a variable Test with values "Mammal',

Query varchar date with between

穿精又带淫゛_ 提交于 2021-02-11 12:46:59
问题 How can i select a date stored as varchar (format: "2012.04") with the BETWEEN operator? I need to select a one year interval on this field. Now i'm trying with this, but this gives my MySQL syntax error: SELECT DISTINCT monthcol FROM bo_alerts WHERE STR_TO_DATE(monthcol , '%Y.%m') BETWEEN (STR_TO_DATE('2012.04', '%Y.%m') AND STR_TO_DATE('2011.03', '%Y.%m')) ORDER BY monthcol DESC The dates are now static (for testing), but i need to calculate the second value in the BETWEEN so that it will

Query varchar date with between

半腔热情 提交于 2021-02-11 12:46:11
问题 How can i select a date stored as varchar (format: "2012.04") with the BETWEEN operator? I need to select a one year interval on this field. Now i'm trying with this, but this gives my MySQL syntax error: SELECT DISTINCT monthcol FROM bo_alerts WHERE STR_TO_DATE(monthcol , '%Y.%m') BETWEEN (STR_TO_DATE('2012.04', '%Y.%m') AND STR_TO_DATE('2011.03', '%Y.%m')) ORDER BY monthcol DESC The dates are now static (for testing), but i need to calculate the second value in the BETWEEN so that it will

same database structure and index, but different query speed and explain results

好久不见. 提交于 2021-02-11 12:40:37
问题 I have 2 MySQL databases on 2 separate cloud servers. One is setup by my colleague and I duplicated that one with same structures. Days ago I found a query on my database is slow but fast in his database. Then he told me he added 2 indexes for a table and he added the same 2 indexes for my database but it just didn't work and he didn't know why. The explain result is different after adding the same indexes. And my query is still slow. ( 0.36s vs > 3mins ) Could you tell me what's wrong and

Use PHP MySQLi prepared statements without references?

限于喜欢 提交于 2021-02-11 12:35:12
问题 Is there a way to use MySQLi prepared statements without passing references? [Background: I'm extremely new to PHP and to MySQL but I inherited a private WordPress plugin to maintain and so I'm learning both as I go.] I understand that prepared statements are useful for preventing SQL injections and potentially also for speeding up queries (if the statements are kept around) but the need for referenced variables seems odd. Is the idea that one calls bind_param up front and then when making

WCF service with entity framework(relationship between table)

时光总嘲笑我的痴心妄想 提交于 2021-02-11 12:32:18
问题 I am creating a server on a WCF server. I have a database in which there are several tables. For each of the tables, you need to create a WCF service. The WCF service has two files, an interface where I implement my REST architecture and a microwave file where I implement the methods that I call on this interface. When working with the database, EF, database first was used. This means that the data was imported from MySQL by the framework itself and automatically established connections. 1st

Fetch hourly data from MySQL

人盡茶涼 提交于 2021-02-11 12:31:44
问题 The query below retrieves Date Hourly and groups the data into hourly format SELECT Hour(created) AS hour, created,image FROM user_screenshot WHERE created BETWEEN ( Curdate() + INTERVAL (SELECT Hour(Now())) hour - INTERVAL 23 hour ) AND Now() AND date(created) = '2021-01-27' GROUP BY hour ORDER BY ( Curdate() + INTERVAL (SELECT Hour(Now())) hour - INTERVAL 23 hour ) It prints the data this way which is okay. But Is it possible to retrieve all the records as well which belongs to that hour.