PHP simple method to operate MongoDB (installation, addition, deletion, modification and query), mongodb addition and deletion_PHP tutorial

PHP simple method to operate MongoDB (installation, addition, deletion, modification and query), mongodb addition and deletion_PHP tutorial

How to simply operate MongoDB with PHP (installation, addition, deletion, modification and query), add and delete mongodb This article describes the simple method of operating MongoDB with PHP. Share it with everyone for your reference, the details are as follows: If PHP operates MongoDB, first download the MongoDB expansion package from the Internet, https://github.com/mongodb/mongo-php-driver/downloads, and select the corresponding expansion package. I downloaded this and decompressed it. VC6 is suitable for apache, VC9 is suitable for IIS, and ts (thread safe) means that PHP runs in the form of a module. Then put the php_mongo.dll in the ext folder in PHP, then add extension=php_mongo.dll to PHP.INI and restart apache. Now the PHP extension MongoDB package is installed. For information on querying some MongoDB functions, please refer to the manual http://us.php.net/manual/en/class.mongocollection.php PHPDataBase; $collection = $db->PHPCollection; /*——————————– * delete *——————————– $collection->remove(array(“name” => “xixi111”)); */ /*——————————— * insert *——————————– for($i = 0;$i “xixi”.$i,”email” => “673048143_”.$i.”@qq.com”,”age” => $i*1+20); $collection->insert($data); } */ /*———————————- * Find *——————————– $res = $collection->find(array(“age” => array(‘$gt’ => 25,’$lt’ => 40)),array(“name” => true)); foreach($res as $v) { print_r($v); } */ /*———————————- * renew *——————————– $collection->update(array(“age” =>22),array(‘$set’ => array(“name” => “demoxixi”))); */ ?> Readers who are interested in more PHP-related content can check…

Database search, addition, deletion and modification_PHP tutorial

I haven’t learned MySQL for a long time, and the operations of the database are nothing more than adding records, searching for records, deleting records, and modifying records. The following commands are summarized and shared with everyone: Connection command: mysql -h[host address] -u[user name] -p[user password] Create database: create database [ Library name] Show all databases: show databases; Open a database: use [Library name] Currently selected library status: SELECT DATABASE(); Create a data table: CREATE TABLE [Table name]([Field name] [Field type]([Field requirements]) [Field parameters], …); Display data table fields: describe table name; Current database data table structure: show tables; Change table ALTER TABLE [table name] ADD COLUMN [field name] DATATYPE Description: Add a column (without deleting a column) Syntax. ALTER TABLE [table name] ADD PRIMARY KEY ([field name]) Description: Change the definition of the table to set a field as the primary key. ALTER TABLE [table name] ] DROP PRIMARY KEY ([field name]) Description: Delete the definition of the primary key.Show current table fields: show columns from tablename; Delete database: drop database [database name]; Delete table: drop table [table name]; Data operationAdd: INSERT INTO [table name] VALUES(”,”,…Sequentially arranged data ); Query: SELECT * FROM [table name] WHERE ([condition]); Index creation:…

PHP realizes data display, addition, modification, deletion and query of text database_PHP tutorial

PHP method to realize the five basic operations of data display, addition, modification, deletion and query of text database I use a guestbook program as an example to explain how PHP implements the five basic operations of data display, addition, modification, deletion, and query on text databases. This text database has 10 fields in total: customer IP, speaking time, customer name, customer EMAIL, customer homepage address, message emoticon picture name, customer QQ, customer image picture, message content, and administrator reply content. 1. Add data program segments. $date=date(“Y-m-d H:i:s”);//Get the system time $ip = $HTTP_SERVER_VARS[REMOTE_ADDR]; //Get the IP address of the speaker $text=encode($gb_text);//Remove the spaces after the message content. $fp=fopen(“gb.dat”,”a”);//Open the gb.dat text file in write-only mode, with the file pointer pointing to the end of the file. $str =$ip.”|”.$date.”|”.$gb_name.”|”.$gb_email.”|”.$gb_home.”|”.$face.”|”.$gb_qq.”| “.$head.”|”.$text.”|”.$reply.” “;//Assign the data of all messages to the variable $str. The purpose of “|” is to use it as the data interval symbol when dividing data in the future. fwrite($fp,$str);//Write data to file fclose($fp);//Close the file showmessage(“Message successful!”,”index.php”,”3″);//The message is successful and will automatically return to the main interface after 3 seconds. Among them, $gb_name, $gb_email, $gb_home, $face, $gb_qq, $head, $gb_text, and $reply are the data passed from the speech…

Simple usage example code of DOMDocument in php (XML creation, addition, deletion, modification)_php skills

There are four files in total, which have four functions: create, add, delete, and modify. The variables are all hard-coded. You can use $_POST instead to receive them//index.php creation function The code is as follows: <?php $xmlpatch = ‘index.xml’; $_id = ‘1’; $_title = ‘title1’; $_cOntent= ‘content1’; $_author = ‘author1’ ; $_sendtime = ‘time1’; $_htmlpatch = ‘1.html’; jb51.net$doc = new DOMDocument(‘1.0’, ‘utf-8’); $ doc -> formatOutput = true; jb51.net$root = $doc -> createElement(‘root’);//New nodejb51.net$index = $doc -> createElement(‘index’) ;//New nodejb51.net$url = $doc -> createAttribute(‘url’);//New attribute$patch = $doc -> createTextNode($_htmlpatch);//New TEXT value $url -> appendChild($patch);//Set the $patch text to the value of the $url attributejb51.net$id = $doc -> createAttribute(‘id’); $ newsid = $doc -> createTextNode($_id); $id -> appendChild($newsid); jb51.net$title = $doc -> createAttribute(‘title’); $newstitle = $doc -> createTextNode($_title); $title -> appendChild($newstitle); jb51.net$cOntent= $doc -> createTextNode($_content);//Node value jb51.net$author = $doc -> createAttribute(‘author’); $newsauthor = $doc -> createTextNode($_author); $author -> appendChild($newsauthor); jb51 .net$sendtime = $doc -> createAttribute(‘time’); $newssendtime = $doc -> createTextNode($_sendtime); $sendtime -> appendChild($newssendtime); jb51. net$index -> appendChild($id);//Set $id as an attribute of the index node, the following is similar to $index -> appendChild($title); $index -> appendChild($content ); $index -> appendChild($url); $index -> appendChild($author); $index -> appendChild($sendtime); jb51.net$root – > appendChild($index);//Set index…

Basic tutorial on operating MongoDB in PHP (connection, addition, modification, deletion, query)_PHP

MongoDB The code is as follows://Connect localhost:27017$cOnn= new Mongo(); //Default port for connecting to the remote host$cOnn= new Mongo(‘test.com’); //Connect to the remote host port 22011$cOnn= new Mongo(‘test.com:22011’); //MongoDB has a username and password$cOnn= new Mongo(“mongodb://${username}:${password}@localhost”) //MongoDB has a username and password and specifies the database blog$cOnn= new Mongo(“mongodb://${username}:${password}@localhost/blog”); //Multiple servers$cOnn= new Mongo(“mongodb://localhost:27017,localhost:27018”);//Select database blog$db = $conn-> blog;//Specify the result set (table name: users)$collection = $db->users;//Newly added$user = array(‘name’ => ‘caleng ‘, ’email’ => ‘admin#admin.com’);$collection->insert($user);//Modify$newdata = array(‘$set’ => array (“email” => “[email protected]”));$collection->update(array(“name” => “caleng”), $newdata);//Delete $collection->remove(array(‘name’=>’caleng’), array(“justOne” => true));//Find$cursor = $collection->find();var_dump($cursor);//Find one$user = $collection->findOne(array(‘name’ => ‘caleng’), array(’email’)); var_dump($user);//Close the database$conn->close();

Addition, deletion, modification and query operations in the CI (CodeIgniter) framework_php example

CodeIgniter’s data function class is in \system\database\DB_active_rec.php The code is as follows: class ModelName extends CI_Model { function __construct() { parent::__construct(); } } Connect to the database: $this->load->database(); The code is as follows: classModel_name extends CI_Model { function __construct() { parent::__construct(); $this->load->database (); } } Written in the constructor of the model, it is very convenient to connect to the database while loading the model. Insert data The code is as follows: $this->db->insert($tableName,$data);$tableName = is the name of the table you want to operate. $data=The data you want to insert is inserted in the form of an array (key name=field name, key value=field value, auto-increment primary key does not need to be written). Update data The code is as follows: $this->db->where(‘field name’,’field value’); $this->db->update(‘table name’, modify value array); Query data The code is as follows: $this->db->where(‘field name’,’field value’); $this->db->select(‘field’); $query= $this->db->get(‘table name’); return $query->result(); Delete data The code is as follows: $this->db->where(‘field name’,’field value’); $this->db->delete(‘table name’); The next step is to call our model in the controller The code is as follows: $this->load->model(‘model name’)//The model name refers to your Model built under the project directory /models/ (same as the file name) $this->model name->method name In order not to call it…

PHP operation MongoDB basic tutorial (connection, addition, modification, deletion, query)

This article mainly introduces a concise tutorial on PHP operation MongoDB, including connection, addition, modification, deletion, query, etc. Friends in need can refer to it The code is as follows: //Connect to localhost:27017$cOnn= new Mongo(); //Connect to the default port of the remote host$cOnn= new Mongo(‘test.com’); //Connect to remote host port 22011$cOnn= new Mongo(‘test.com:22011’); //MongoDB has username and password$cOnn= new Mongo(“mongodb://${username}:${password}@localhost”) //MongoDB has a username and password and specifies the database blog$cOnn= new Mongo(“mongodb://${username}:${password}@localhost/blog”); //Multiple servers$cOnn= new Mongo(“mongodb://localhost:27017,localhost:27018”);//Select database blog$db = $conn-> blog;//Formulate the result set (table name: users)$collection = $db->users;//Newly added$user = array(‘name’ => ‘caleng ‘, ’email’ => ‘admin#admin.com’);$collection->insert($user);//Modify$newdata = array(‘$set’ => array (“email” => “[email protected]”));$collection->update(array(“name” => “caleng”), $newdata);//delete $collection->remove(array(‘name’=>’caleng’), array(“justOne” => true));//Find$cursor = $collection->find();var_dump($cursor);//Find a $user = $collection->findOne(array(‘name’ => ‘caleng’), array(’email’)); var_dump($user);//Close the database$conn->close(); ,

Addition, deletion, modification and query operations in the CI (CodeIgniter) framework_php example

CodeIgniter’s data function class is in \system\database\DB_active_rec.php The code is as follows: class ModelName extends CI_Model { function __construct() { parent::__construct(); } } Connect to the database: $this->load->database(); The code is as follows: classModel_name extends CI_Model { function __construct() { parent::__construct(); $this->load->database (); } } Written in the constructor of the model, it is very convenient to connect to the database while loading the model. Insert data The code is as follows: $this->db->insert($tableName,$data);$tableName = is the name of the table you want to operate. $data=The data you want to insert is inserted in the form of an array (key name=field name, key value=field value, auto-increment primary key does not need to be written). Update data The code is as follows: $this->db->where(‘field name’,’field value’); $this->db->update(‘table name’, modify value array); Query data The code is as follows: $this->db->where(‘field name’,’field value’); $this->db->select(‘field’); $query= $this->db->get(‘table name’); return $query->result(); Delete data The code is as follows: $this->db->where(‘field name’,’field value’); $this->db->delete(‘table name’); The next step is to call our model in the controller The code is as follows: $this->load->model(‘model name’)//The model name refers to your Model built under the project directory /models/ (same as the file name) $this->model name->method name In order not to call it…

PHP operation MongoDB basic tutorial (connection, addition, modification, deletion, query)_php instance

The code is as follows: //connect localhost:27017$cOnn= new Mongo(); //Connect to the default port of the remote host$cOnn= new Mongo(‘test.com’); //Connect to remote host port 22011$cOnn= new Mongo(‘test.com:22011’); //MongoDB has username and password$cOnn= new Mongo(“mongodb://${username}:${password}@localhost”) //MongoDB has a username and password and specifies the database blog$cOnn= new Mongo(“mongodb://${username}:${password}@localhost/blog”); //Multiple servers$cOnn= new Mongo(“mongodb://localhost:27017,localhost:27018”);//Select database blog$db = $conn-> blog;//Formulate the result set (table name: users)$collection = $db->users;//Newly added$user = array(‘name’ => ‘caleng ‘, ’email’ => ‘admin#admin.com’);$collection->insert($user);//Modify$newdata = array(‘$set’ => array (“email” => “[email protected]”));$collection->update(array(“name” => “caleng”), $newdata);//Delete $collection->remove(array(‘name’=>’caleng’), array(“justOne” => true));//Find$cursor = $collection->find();var_dump($cursor);//Find a $user = $collection->findOne(array(‘name’ => ‘caleng’), array(’email’)); var_dump($user);//Close the database$conn->close();

Sample code for simple usage of DOMDocument in php (XML creation, addition, deletion, modification)

It is divided into four files, which are the four functions of creating, adding, deleting and modifying. The variables are hard-coded, and you can use it to receive it by $_POST.//index.php create function The code is as follows: <?php $xmlpatch = ‘index.xml’; $_id = ‘1’; $ _title = ‘title1’; $_cOntent= ‘content1’; $_author = ‘author1’; $_sendtime = ‘time1’; $_htmlpatch = ‘1.html’; >jb51.net$doc = new DOMDocument(‘1.0’, ‘utf-8’); $doc -> formatOutput = true; jb51.net$root = $doc -> createElement(‘root’ );//New nodejb51.net$index = $doc -> createElement(‘index’);//New nodejb51.net$url = $doc -> createAttribute(‘url’); //Create a new attribute$patch = $doc -> createTextNode($_htmlpatch);//Create a new TEXT value$url -> appendChild($patch);//Set the $patch text to the $url attribute Valuejb51.net $id = $doc -> createAttribute(‘id’); $newsid = $doc -> createTextNode($_id); $id -> appendChild($newsid); jb51.net$title = $doc -> createAttribute(‘title’); $newstitle = $doc -> createTextNode($_title); $title -> appendChild($newstitle); jb51.net$cOntent= $doc -> createTextNode($_content);//node valuejb51.net$author = $doc -> createAttribute(‘author’); $newsauthor = $doc -> createTextNode($_author); $author -> appendChild($newsauthor); jb51.net $sendtime = $doc -> createAttribute(‘time’); $newssendtime = $doc – > createTextNode($_sendtime); $sendtime -> appendChild($newssendtime); jb51.net$index -> appendChild($id);//Set $id as the attribute of the index node, the following class Same as $index -> appendChild($title); $index -> appendChild($content); $index -> appendChild($url); $index -> appendChild($ author); $index -> appendChild($sendtime); jb51.net$root ->…

Contact Us

Contact us

181-3619-1160

Online consultation: QQ交谈

E-mail: [email protected]

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top
首页
微信
电话
搜索