# node-mysql
[![Build Status](https://secure.travis-ci.org/felixge/node-mysql.png?branch=master)](http://travis-ci.org/felixge/node-mysql)
## Purpose
A pure node.js JavaScript Client implementing the [MySQL protocol](http://forge.mysql.com/wiki/MySQL_Internals_ClientServer_Protocol).
## Support this module
If you like this module, check out and spread the word about our service
[transloadit.com][]. We provide file uploading and encoding functionality to
other applications, and have performed billions of queries with this module so
far.
[transloadit.com]: http://transloadit.com/
## Installation
```
npm install mysql
```
**Important**: If you are upgrading from 0.9.1 or below, there have been
backwards incompatible changes in the API. Please read the [upgrading guide][].
[upgrading guide]: https://github.com/felixge/node-mysql/wiki/Upgrading-to-0.9.2+
## Usage
``` javascript
var mysql = require('mysql');
var TEST_DATABASE = 'nodejs_mysql_test';
var TEST_TABLE = 'test';
var client = mysql.createClient({
user: 'root',
password: 'root',
});
client.query('CREATE DATABASE '+TEST_DATABASE, function(err) {
if (err && err.number != mysql.ERROR_DB_CREATE_EXISTS) {
throw err;
}
});
// If no callback is provided, any errors will be emitted as `'error'`
// events by the client
client.query('USE '+TEST_DATABASE);
client.query(
'CREATE TEMPORARY TABLE '+TEST_TABLE+
'(id INT(11) AUTO_INCREMENT, '+
'title VARCHAR(255), '+
'text TEXT, '+
'created DATETIME, '+
'PRIMARY KEY (id))'
);
client.query(
'INSERT INTO '+TEST_TABLE+' '+
'SET title = ?, text = ?, created = ?',
['super cool', 'this is a nice text', '2010-08-16 10:00:23']
);
var query = client.query(
'INSERT INTO '+TEST_TABLE+' '+
'SET title = ?, text = ?, created = ?',
['another entry', 'because 2 entries make a better test', '2010-08-16 12:42:15']
);
client.query(
'SELECT * FROM '+TEST_TABLE,
function selectCb(err, results, fields) {
if (err) {
throw err;
}
console.log(results);
console.log(fields);
client.end();
}
);
```
## API
### mysql.createClient([options])
Creates a new client instance. Any client property can be set using the
`options` object.
### client.host = 'localhost'
The host to connect to.
### client.port = 3306
The port to connect to.
### client.user = null
The username to authenticate as.
### client.password = null
The password to use.
### client.database = null
The name of the database to connect to (optional).
### client.debug = false
Prints incoming and outgoing packets, useful for development / testing purposes.
### client.flags = Client.defaultFlags
Connection flags send to the server.
### client.query(sql, [params, cb])
Sends a `sql` query to the server. `'?'` characters can be used as placeholders
for an array of `params` that will be safely escaped before sending the final
query.
This method returns a `Query` object which can be used to stream incoming row
data.
**Warning:** `sql` statements with multiple queries separated by semicolons
are not supported yet.
### client.ping([cb])
Sends a ping command to the server.
### client.useDatabase(database, [cb])
Same as issuing a `'USE <database>'` query.
### client.statistics([cb])
Returns some server statistics provided by MySql.
### client.format(sql, params)
Allows to safely insert a list of `params` into a `sql` string using the
placeholder mechanism described above.
### client.escape(val)
Escapes a single `val` for use inside of a sql string.
### client.destroy()
Forces the client connection / socket to be destroyed right away.
### client.end([cb])
Schedule a COM_QUIT packet for closing the connection. All currently queued
queries will still execute before the graceful termination of the connection
is attempted.
### client event: 'error' (err)
When the client has no callback / delegate for an error, it is emitted with this
event instead.
### new mysql.Query()
Query objects are not meant to be invoked manually. To get a query object, use
the `client.query` API.
### query event: 'error' (err)
Emitted when mysql returns an error packet for the query.
### query event: 'field' (field)
Emitted upon receiving a field packet from mysql.
### query event: 'row' (row)
Emitted upon receiving a row. An option for streaming the contents of the row
itself will be made available soon.
### query event: 'end' ([result])
Emitted once the query is finished. In case there is no result set, a `result`
parameter is provided which contains the information from the mysql OK packet.
## FAQ
### How do I compile this module?
This module is written entirely in JavaScript. There is no dependency on external
C libraries such as libmysql. That means you don't have to compile this module
at all.
### How can I retrieve the id from the last inserted record?
client.query('INSERT INTO my_table SET title = ?', function(err, info) {
console.log(info.insertId);
});
### How can I find out the number of rows affected by the last query?
client.query('UPDATE my_table SET title = ?', function(err, info) {
console.log(info.affectedRows);
});
## Todo
At this point the module is ready to be tried out, but a lot of things are yet to be done:
* Implement retry
* Pause / resume
* Remaining mysql commands
* Prepared Statements
* Packet's > 16 MB
* Compression
* Decide how to handle queries with multiple statements
* Transactions
A stop-gap solution to support multiple statements and transactions is
available. Check it out here: http://github.com/bminer/node-mysql-queues
## Contributors
[Click here][contributors] for a full list of contributors.
[contributors]: https://github.com/felixge/node-mysql/contributors
## Sponsors
* [Joyent](http://www.joyent.com/) - Main sponsor, you should check out their [node.js hosting](https://no.de/).
* [pinkbike.com](http://pinkbike.com/) - The most awesome biking site there is
This is a rather large project requiring a significant amount of my limited resources.
If your company could benefit from a well-engineered non-blocking mysql driver, and
wants to support this project, I would greatly appriciate any sponsorship you may be
able to provide. All sponsors will get lifetime display in this readme, priority
support on problems, and votes on roadmap decisions. If you are interested, contact
me at [felix@debuggable.com](mailto:felix@debuggable.com) for details.
Of course I'm also happy about code contributions. If you're interested in
working on features, just get in touch so we can talk about API design and
testing.
[transloadit]: http://transloadit.com/
## Changelog
### v0.9.6
* Escape array values so they produce sql arrays (Roger Castells, Colin Smith)
* docs: mention mysql transaction stop gap solution (Blake Miner)
* docs: Mention affectedRows in FAQ (Michael Baldwin)
### v0.9.5
* Fix #142 Driver stalls upon reconnect attempt that's immediately closed
* Add travis build
* Switch to urun as a test runner
* Switch to utest for unit tests
* Remove fast-or-slow dependency for tests
* Split integration tests into individual files again
### v0.9.4
* Expose package.json as `mysql.PACKAGE` (#104)
### v0.9.3
* Set default `client.user` to root
* Fix #91: Client#format should not mutate params array
* Fix #94: TypeError in client.js
* Parse decimals as string (vadimg)
### v0.9.2
* The underlaying socket connection is now managed implicitly rather than explicitly.
* Check the [upgrading guide][] for a full list of changes.
### v0.9.1
* Fix issue #49 / `client.escape()` throwing exceptions on objects. (Nick Payne)
* Drop < v0.4.x compatibility. From now on you need node v0.4.x to use this module.
### Older releases
These releases were done before starting to maintain the above Changelog:
* [v0.9.0](https://github.com/felixge/node-mysql/compare/v0.8.0...v0.9.0)
* [v0.8.0](https://github.com/felixge/node-mysql/compare/v0.7.0...v0.8.0)
* [v0.7.0](https://github.com/felixge/no
没有合适的资源?快使用搜索试试~ 我知道了~
信誉网平台源码
共1410个文件
php:452个
js:257个
png:190个
需积分: 32 43 下载量 114 浏览量
2015-01-13
16:28:09
上传
评论 2
收藏 18.46MB RAR 举报
温馨提示
2015年最新(信誉网)平台,专业平台优秀平台,全新代码编写,完全开源源码,PHP+ajax+缓存技术+数据存储,安全性无可懈击,速度一流,安全性高,稳定性强!
资源推荐
资源详情
资源评论
收起资源包目录
信誉网平台源码 (1410个子文件)
40e20e3e97e5787a332a1b2345c2f6f1 65KB
ac0f3b72de6d4baf5b46d683d22d8c0d 7KB
all-wcprops 1KB
client.js.bak 10KB
.bash_history 483B
获取.bat 12B
.buildpath 174B
libmysql_password.c 4KB
validation.cc 4KB
validation.cc 4KB
bufferutil.cc 4KB
bufferutil.cc 4KB
DBAccess.class 11KB
Object.class 5KB
Xxtea.class 3KB
CImage.class 2KB
wscat.cmd 173B
wscat.cmd 173B
test.conf 33B
test.conf 33B
css_blue.css 83KB
_css_blue_.css 44KB
jquery-ui-1.8.21.custom.css 33KB
jquery-ui-1.8.21.custom.css 32KB
jquery-ui-1.8.21.custom.css 32KB
jquery-ui-1.8.23.custom.css 27KB
layout.css 21KB
main.css 13KB
idealForms-theme-comix.css 8KB
default.css 7KB
aero.css 7KB
idealForms-theme-forest.css 4KB
idealForms-theme-sapphire.css 3KB
idealForms.css 3KB
ie.css 583B
Thumbs.db 181KB
Thumbs.db 104KB
Thumbs.db 56KB
Thumbs.db 8KB
entries 2KB
distro2_bats-webfont.eot 3KB
ssc_admin_log.frm 69KB
ssc_bets.frm 10KB
ssc_members.frm 10KB
ssc_coin_log.frm 9KB
ssc_type.frm 9KB
ssc_played.frm 9KB
ssc_member_recharge.frm 9KB
my18_cz_temp.frm 9KB
ssc_score_goods.frm 9KB
ssc_member_session.frm 9KB
my18_pay_temp.frm 9KB
ssc_member_cash.frm 9KB
my18_pay.frm 9KB
ssc_score_swap.frm 9KB
ssc_cms_node.frm 9KB
ssc_cms_fields.frm 9KB
ssc_member_bank.frm 9KB
ssc_count.frm 9KB
ssc_data.frm 9KB
ssc_data_time.frm 9KB
ssc_content.frm 9KB
ssc_member_level.frm 9KB
ssc_bank_list.frm 9KB
ssc_played_group.frm 8KB
ssc_params_fandianset.frm 8KB
ssc_params.frm 8KB
ssc_cms_fieldc.frm 8KB
ssc_cms_app.frm 8KB
ssc_fcoin_bet.frm 1KB
ssc_fcoin_znz.frm 1KB
ssc_fcoin_cash.frm 1KB
50b857a370b35.gif 275KB
50b7c79a9127c.gif 275KB
50b7c3277896e.gif 272KB
50b7c62754999.gif 271KB
login-content-bg.gif 20KB
12.gif 17KB
kjbg.gif 17KB
bg_vedio.gif 17KB
16.gif 13KB
lot_loading-.gif 10KB
lot_loading.gif 10KB
11.gif 10KB
04.gif 9KB
login-wel.gif 9KB
01.gif 8KB
02.gif 6KB
logo.gif 6KB
03.gif 5KB
23.gif 5KB
05.gif 5KB
14.gif 5KB
06.gif 5KB
09.gif 4KB
regbtn.gif 4KB
15.gif 4KB
13.gif 4KB
10.gif 4KB
07.gif 3KB
共 1410 条
- 1
- 2
- 3
- 4
- 5
- 6
- 15
资源评论
qq_25294013
- 粉丝: 0
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功