小编Uly*_*rez的帖子

关闭连接MySQL Node.js

我正在使用ExpressJS和MySQL开发一个Node应用程序.我正在使用这个模块https://github.com/felixge/node-mysql/,我正在学习它的用途.我对如何正确关闭连接感到麻烦.

这就是我做的:

app.post('/example', function (req, res) {

    //BD
    var connection = mysql.createConnection({
        host: config.database.host,
        port: config.database.port,
        user: config.database.user,
        password: config.database.password,
        database: config.database.database
    });

    var sql = '';

    if (varExample != null) {

         sql = 'Random query';

         connection.query(sql, function (err, results) {

             //Get results

             connection.end();
         }); 
    }
});
Run Code Online (Sandbox Code Playgroud)

有时我必须多次调用此方法才能在数据库中插入数据.那一刻我得到一个错误'太多连接'.

在这些情况下关闭连接的方法是什么?

node.js node-mysql

3
推荐指数
2
解决办法
1万
查看次数

python中的行为unicode字符串

我已经看到这个问题,我怀疑如何在运行时将var转换为unicode?是不是正确使用unicode功能?还有其他方法可以在运行时转换字符串吗?

print(u'Cami\u00f3n') # prints with right special char

name=unicode('Cami\u00f3n')
print(name) # prints bad ===> Cami\u00f3n

name.encode('latin1')
print(name.decode('latin1')) # prints bad ===> Cami\u00f3n

encoded_id = u'abcd\xc3\x9f'
encoded_id.encode('latin1').decode('utf8')
print encoded_id.encode('latin1').decode('utf8') # prints right
Run Code Online (Sandbox Code Playgroud)

我在stackoverflow上看到了很多python unicode问题,但我无法理解这种行为.

python unicode python-3.x

2
推荐指数
1
解决办法
211
查看次数

标签 统计

node-mysql ×1

node.js ×1

python ×1

python-3.x ×1

unicode ×1