简体   繁体   English

node.js中的数据库查询(php样式)

[英]database queries in node.js (php style)

I finally understood the concept of websockets. 我终于了解了websockets的概念。 I found great Q/As here, helped a lot, thanks. 我在这里找到了很好的问答,对我帮助很大,谢谢。 I am about to install node.js alongside apache and geoserver for a web-mapping project, I'll use node.js just to handle websockets. 我将为Web映射项目将apache和geoserver以及node.js一起安装,我将仅使用node.js来处理websocket。 In practice, coding-wise, I'm more experienced with php and its hard for me to shift my logic from traditional xml-http-requests, but I'll give it a shot. 在实践中,在编码方面,我对php更有经验,并且很难将我的逻辑从传统的xml-http-requests转移到其他地方,但是我会做个尝试。

Some questions, before I dig in. I use postgreSQL/postGIS, how can I perform database queries from node.js to postgreSQL/postGIS? 在深入研究之前,我会遇到一些问题。我使用postgreSQL / postGIS,如何执行从node.js到postgreSQL / postGIS的数据库查询? I'm used to the traditional PHP queries like the following 我已经习惯了如下所示的传统PHP查询

 $stmt = $dbh->prepare("SELECT pins.p_name FROM     pins
 WHERE type.t_id=pins.p_type AND
    AND p_id = :nm");
$stmt->bindParam(':nm', $nm, PDO::PARAM_STR);
$nm=$jas;
$data=array('nm'=>$nm);
$stmt->execute($data);
//blah blah
//(I always use PDO and prepared statements)

Most tutorials out there talk about chat apps, but what about queries and communicating with postgreSQL/postGIS? 那里的大多数教程都谈论聊天应用程序,但是查询和与postgreSQL / postGIS通信又如何呢? Is that possible in node.js/socket.io? 在node.js / socket.io中可以吗? Any tips/tutorials? 有任何提示/教程吗? I want to execute the query, gather the outcome, put some html tags and then push it back to the client, in a specific div. 我想执行查询,收集结果,放置一些html标记,然后将其推回到特定div中的客户端。

Also, is node.js now working on windows 7, without a problem? 另外,node.js现在可以在Windows 7上正常工作了吗? In the past it did not, but I guess now it does, since they have an msi installer. 过去没有,但是我想现在可以了,因为他们有一个msi安装程序。 Right? 对?

Thank you very much... 非常感谢你...

Use Node Postgres https://github.com/brianc/node-postgres/ The documentation is excellent and easy to use. 使用Node Postgres https://github.com/brianc/node-postgres/该文档非常好并且易​​于使用。

It also allows for prepared statements with the format 它还允许使用格式准备的语句

query( {name:"emp_name", text:"select name from emp where emp_id=$1", values:[123]} )

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM