PHP Extension _ PHP Tutorial

Source: Internet
Author: User
PHP extension. Download the corresponding php extension file php_mongo.dll, merge it into the php Extension folder phpext, and modify php. ini file, add the following lines: extensionphp_mongo.dllPHP to connect to the database $ co to download the corresponding php extension file php_mongo.dll, export it to the php Extension folder/php/ext, and modify php. the INI file adds the following lines:

Extension = php_cmd.dll

PHP operations

Connect to database

$ Conn = new Mongo ("mongodb: // localhost: 27017 // admin: admin ");

Select database and set

// Select the database blog. If no, create

$ Db = $ conn-> yyd;

// You can also enter $ db = $ conn-> selectDB ('yyd ');

// Set the result set (set: yyd_test)

$ Collection = $ db-> yyd_test;

// You can also write it as $ collection = $ db-> selectCollection ('yyd _ test ');

// Var_dump ($ collection );

Add data

$ Post = array ('name' => '22', 'sex' => '32 ');

$ Flag = ($ collection-> insert ($ post ));

Var_dump ($ flag );

Image

Image

Search for data

$ Arr = array ();

$ Cursor = $ collection-> find ($ arr );

Foreach ($ cursor as $ key => $ value ){

Echo"

";

echo $value['_id'];

echo '
name:';

echo $value['name'];

echo "
sex:";

echo $value['sex'];

echo "

";

}

Image

Conditional search

$ Arr = array ("name" => "22 ");

$ Cursor = $ collection-> find ($ arr );

Modify data

Image

$ Newdata = array ('$ set' => array ("email" => "test@test.com "));

$ Collection-> update (array ("name" => "22"), $ newdata );

Var_dump ($ collection );

$ Arr = array ("name" => "22 ");

$ Cursor = $ collection-> find ($ arr );

Foreach ($ cursor as $ key => $ value ){

Echo"

";

echo $value['_id'];

echo '
name:';

echo $value['name'];

echo "
sex:";

echo $value['sex'];

echo "
email:";

echo $value['email'];

echo "

";

}

Delete data

Image

$ Arr = array ("name" => "22 ");

$ Collection-> remove ($ arr );

Var_dump ($ collection );

Image

Other common operations

// Close the connection

$ Conn-> close ();

// Delete a database

$ Conn-> dropDB ("yyd ");

// List all available databases

$ Dbs = $ conn-> listDBs ();

Export extension = php_mongo.dll PHP operation connection database $ co...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.