MongoDB với PHP | 297 bài hướng dẫn PHP hay nhất

3 138 1
MongoDB với PHP | 297 bài hướng dẫn PHP hay nhất

Đang tải... (xem toàn văn)

Thông tin tài liệu

http://vietjack.com/mongodb/index.jsp                                                                                                              Copyright  ©  vietjack.com     MongoDB với PHP Để sử dụng MongoDB với PHP, bạn cần sử dụng MongoDB PHP Driver Tải Driver từ Tải PHP Driver Bạn nên tải phiên Sau unzip đặt php_mongo.dll vào thư mục PHP Extension bạn (ext theo mặc định) thêm dòng sau vào php.ini file: extension=php_mongo.dll Tạo kết nối Chọn Database Để tạo kết nối, bạn cần xác định tên Database, khơng tồn MongoDB tự động tạo Bạn theo dõi code sau: Khi code biên dịch thực thi, kết là: Connection to database successfully Database mydb selected Tạo Collection Bạn theo dõi code sau để tạo Collection: Khi code biên dịch thực thi, kết là: Connection to database successfully Database mydb selected Collection created succsessfully Chèn Document Để chèn Document vào MongoDB, bạn sử dụng phương thức insert() Bạn theo dõi code sau: http://vietjack.com/                                                                                                                              Trang  chia  sẻ  các  bài  học  online  miễn  phí     http://vietjack.com/mongodb/index.jsp                                                                                                              Copyright  ©  vietjack.com     Khi code biên dịch thực thi, kết là: Connection to database successfully Database mydb selected Collection selected succsessfully Document inserted successfully Tìm tất Document Để chọn tất Document từ Collection, bạn sử dụng phương thức find() Bạn theo dõi code sau: Khi code biên dịch thực thi, kết là: Connection to database successfully Database mydb selected Collection selected succsessfully { "title": "MongoDB" } Cập nhật Document Để cập nhật Document, bạn cần sử dụng phương thức update() Trong ví dụ dưới, cập nhật title Document chèn Chương trình sau minh họa điều http://vietjack.com/                                                                                                                              Trang  chia  sẻ  các  bài  học  online  miễn  phí     http://vietjack.com/mongodb/index.jsp                                                                                                              Copyright  ©  vietjack.com     Khi code biên dịch thực thi, kết là: Connection to database successfully Database mydb selected Collection selected succsessfully Document updated successfully Updated document { "title": "MongoDB Tutorial" } Xóa Document Để xóa Document, bạn cần sử dụng phương thức remove() Trong ví dụ dưới, xóa Document mà có title MongoDB Tutorial Chương trình sau minh họa điều Khi code biên dịch thực thi, kết là: Connection to database successfully Database mydb selected Collection selected succsessfully Documents deleted successfully Trong ví dụ trên, tham số thứ hai kiểu Boolean sử dụng cho trường justOne phương thức remove() Các phương thức findOne(), save(), limit(), skip(), sort(), MongoDB làm việc tương tự trình bày   http://vietjack.com/                                                                                                                              Trang  chia  sẻ  các  bài  học  online  miễn  phí     ...http://vietjack.com /mongodb/ index.jsp                                                                                                              Copyright  ©  vietjack.com     < ?php // connect to mongodb. .. "title": "MongoDB" } Cập nhật Document Để cập nhật Document, bạn cần sử dụng phương thức update() Trong ví dụ dưới, cập nhật title Document chèn Chương trình sau minh họa điều < ?php // connect to mongodb. .. "title": "MongoDB Tutorial" } Xóa Document Để xóa Document, bạn cần sử dụng phương thức remove() Trong ví dụ dưới, xóa Document mà có title MongoDB Tutorial Chương trình sau minh họa điều < ?php //

Ngày đăng: 02/12/2017, 11:42

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan