ThinkPHP-ActiveReocrd form (add, delete, modify, check)

ThinkPHP–ActiveReocrd mode (add, delete, modify and check) ActiveReocrd mode This mode is the largest What’s special is that it simplifies the operation of CURD and adopts an object-based operation method, which is easy to use and understand. //Add a piece of data $user = M(‘User’);$user->user = ‘Naruto’;$user->email = [email protected]’;$user->date = date(‘Y-m-d H:i:s’); $user->add( ); //Combined with create $user = M(‘User’);$user->create();$user->date = date(‘Y-m-d H:i:s’);$user->add(); //Find the one with primary key 4值 $user = M(‘User’);var_dump($user->find(4)); //Find user=Crayon Shin-chan Records $user = M(‘User’);var_dump($user->getByUser(‘Crayon Shin-chan’)); //Output user echo $user->user; //Query multiple by primary key $user = M(‘User’);var_dump($user->select(‘1,2,3’)); //Modify a piece of data $user = M(‘User’);$user->find(1);$user->user = ‘Crayon Old New’;$ user->save(); //Delete the currently found data $user = M(‘User’);$user- >find(11);$user->delete(); //Delete the data with the primary key 10 $user = M( ‘User’);$user->delete(10); //Delete the data with the primary key 10,11 $user = M(‘User’);$user->delete(‘10,11’);

PHP lightweight database operation class Medoo add, delete, modify, query examples_php examples

Introduction to Medoo Medoo is an ultra-lightweight PHP SQL database framework developed by Li Yanzhuo, the founder of the social networking site Catfan and the open source project Qatrix. It provides a simple, easy-to-learn, and flexible API to improve the efficiency and performance of developing web applications, and the size is less than 8KB. Features Lightweight, only one file Easy to learn, the data structure is clear at a glance Supports multiple SQL syntaxes and complex query conditions Supports a variety of databases, including MySQL, MSSQL, SQLite, etc. Safe, prevents SQL injection Free, based on MIT license Sample code Add The code is as follows: $database = new medoo ( “my_database” ); $last_user_id = $database->insert ( “account”, [ “user_name” => “foo”, “email” => “[email protected]”, “age” => 25, “lang” => [ “en”, “fr”, “jp”, “cn” ] ] ); Delete The code is as follows: $database = new medoo ( “my_database” ); $database->delete(“account”, [ “AND” => [ “type” => “business” “age[ 18 ] ]); Edit The code is as follows: $database = new medoo ( “my_database” ); $database->update ( “account”, [ “type” => “user”, // All age plus one “age[+]” => 1, // All level subtract 5 “level[-]” => 5, “lang” =>…

yii add, delete, modify, check example_PHP

1. Data Access Object (DAO) Yii DAO is built on PHP Data Objects (PDO). It is an extension that provides unified data access for many popular DBMS, including MySQL, PostgreSQL, etc. Therefore, use Yii DAO, PDO extension and specific PDO database driver (such as PDO_MYSQL) Must be installed. Yii DAO mainly includes the following four categories: CDbConnection: Represents a database connection. CDbCommand: Represents a SQL statement executed through the database. CDbDataReader: Represents a forward-only stream of rows from a query result set. CDbTransaction: Represents a database transaction. 1. Establish database connection To establish a database connection, create a CDbConnection Instance and activate it. Connecting to a database requires a data source name (DSN) to specify connection information. Username and password may also be used. When an error occurs while connecting to the database (e.g. wrong DSN or invalid username/password), an exception will be thrown. $cOnnection=new CDbConnection($dsn,$username,$password); // establish connection. You can use try…catch to catch exceptions that may be thrown $connection->active=true; … $connection->active=false; // Close connection The format of the DSN depends on the PDO database driver used. In general, the DSN contains the name of the PDO driver, followed by a colon, followed by driver-specific connection syntax. Check out…

Simple PHP database operation code (add, delete, modify, check)_PHP

The basic process of database manipulation is:  1. Connect to the database server 2. Select database  3. Execute SQL statements 4. Processing result sets 5. Print operation information The related functions used are •resource mysql_connect ([string server [, string username [, string password [, bool new_link [, int client_flags]]]]] ) Connect to the database server•resource mysql_pconnect ( [string server [, string username [, string password [, int client_flags]]]]) Connect to the database server, long connection•int mysql_affected_rows ([resource link_identifier]) Get the latest INSERT, UPDATE or associated with link_identifier The number of rows affected by the DELETE query. bool mysql_close ([resource link_identifier]) Returns TRUE if successful, FALSE if failed. •int mysql_errno ([resource link_identifier]) returns the error number of the previous MySQL function, or 0 (zero) if there is no error. •string mysql_error ([resource link_identifier]) returns the error text of the previous MySQL function, or ” (empty string) if there is no error. If no connection resource number is specified, the last successfully opened connection is used to extract error information from the MySQL server. array mysql_fetch_array ( resource result [, int result_type] ) Returns an array based on the rows fetched from the result set, or FALSE if there are no more rows.…

Simple php database operation code (add, delete, modify, check)_php example

The basic process of database manipulation is: 1. Connect to the database server 2. Select the database 3. Execute SQL statement 4. Processing the result set 5. Print operation information The related functions used are •resource mysql_connect ( [string server [, string username [, string password [, bool new_link [, int client_flags]]]]] ) Connect to the database server•resource mysql_pconnect ( [string server [, string username [, string password [, int client_flags]]]] ) Connect to the database server, long connection •int mysql_affected_rows ( [resource link_identifier] ) Get the latest INSERT, UPDATE or The number of rows affected by the DELETE query. •bool mysql_close ( [resource link_identifier] ) returns TRUE if successful, FALSE if failed. •int mysql_errno ( [resource link_identifier] ) returns the error number of the last MySQL function, or 0 (zero) if no error occurred. •string mysql_error ( [resource link_identifier] ) returns the error text of the previous MySQL function, or ” (empty string) if no error occurred. If no connection resource number is specified, the last successfully opened connection is used to fetch error information from the MySQL server. •array mysql_fetch_array ( resource result [, int result_type] ) Returns an array based on the rows fetched from the result…

CRUD (add, delete, modify, check) operations of php development message board_php example-php tutorial

CRUD (add, delete, modify, check) operations of php development message board_php example-php tutorial

Project Structure: Add page: Note: Here we only pay attention to the operation, no effort has been made on the art of the interface, I hope everyone understands… Listing page: Modify page: The sql required in the project: The code is as follows: create database form; use form; CREATE TABLE `message` ( `id` tinyint(1) NOT NULL auto_increment, `user` varchar(25) NOT NULL, `title` varchar(50) NOT NULL, `content` tinytext NOT NULL, `lastdate` date NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=gbk AUTO_INCREMENT= 1 ; conn.php The code is as follows: <?php $cOnn= @ mysql_connect(“localhost”, “root”, “”) or die(“Database connection error”); mysql_select_db(“form”, $conn); mysql_query(“set names ‘gbk’”); ?> add.php The code is as follows: <?php include ‘ conn.php’; if($_POST[‘submit’]){ $sql=”INSERT INTO message(id,user,title,content,lastdate) VALUES (NULL, ‘$_POST[user] ‘, ‘$_POST[title]’, ‘$_POST[content]’, now())”; mysql_query($sql); //Page jump, implemented by Javascript $url = “list.php”; echo “”; } ?> User: Title: Content: list.php The code is as follows: <?php include ‘conn.php’; ?> <?php echo “ Continue adding “; ?> <?php $sql=”select * from message order by id”; $query= mysql_query($sql); while ($row=mysql_fetch_array($query)){ ?> Title: User: “>Edit| “>Delete Content: Date published: delete.php The code is as follows: <?php include ‘conn.php’; $id = $_GET[‘id’]; $query=”delete from message where id=”.$id; mysql_query($query) ; ?> <?php…

Simple php database operation code (add, delete, modify, check)

I am going to re-study these days, sort out the knowledge system, and do some things according to the functional modules. so. The operation of mysql becomes the first point. I wrote a simple mysql operation class to implement simple addition, deletion, modification and query functions of data. The basic process of database manipulation is: 1. Connect to the database server 2. Select the database 3. Execute SQL statement 4. Processing the result set 5. Print operation information The related functions used are •resource mysql_connect ( [string server [, string username [, string password [, bool new_link [, int client_flags]]]]] ) Connect to the database server•resource mysql_pconnect ( [string server [, string username [, string password [, int client_flags]]]] ) Connect to the database server, long connection •int mysql_affected_rows ( [resource link_identifier] ) Get the latest INSERT, UPDATE or The number of rows affected by the DELETE query. •bool mysql_close ( [resource link_identifier] ) returns TRUE if successful, FALSE if failed. •int mysql_errno ( [resource link_identifier] ) returns the error number of the last MySQL function, or 0 (zero) if no error occurred. •string mysql_error ( [resource link_identifier] ) returns the error text of the previous MySQL function, or ”…

Explain in detail how PHP uses the DOMDocument class to traverse, add, modify, and delete XML node operations

Dom (Document object model) document-object-model, the core idea is to treat an Xml file as an object model, and then operate the Xml file through the object. Let’s first summarize the attribute methods of DOM objects, and then use cases to illustrate their applications! DOMDocument Attributes: Attributes stores the list of attributes for the node ( Dom(Document object model)document–object– model, the core idea is to put a Xml file as an object model, and then manipulate the Xml file in the form of an object. Let’s summarize the attribute methods of the DOM object first, and illustrate its application with cases! DOMDocument Attributes: AttributesA list of attributes for storage nodes(read-only) childNodesStorage node’s child node list(read-only) dataTypeReturns the data type of this node DefinitionDefinition of a node given in DTD or XMLschema(read-only) Doctype Specifies the document type node(read-only) documentElementreturns the root element of the document(readable and writable) firstChildreturns the first child of the current node(read-only) ImplementationreturnsXMLDOMImplementationobject lastChildreturns the last child node of the current node(read-only) nextSiblingreturns the next sibling of the current node(read-only) nodeNamereturns the name of the node(read-only) nodeTypereturns the type of the node(read-only) nodeTypedValuestorage node value(readable and writable) nodeValuereturns the text of the node(readable and writable) ownerDocumentreturns the root…

Add, delete, modify, view operations of PHPSESSION

The difference between SESSION and COOKIE is firstly that the file of COOKIE is saved on the client, while the session is saved on the server. In comparison, in order to improve certain security, session has more advantages. Because the session is generally managed by the server manager on the server side, but the COOKIE is saved on the client side, and anyone can read it. If not specified, the password is also saved in plain text, and the security is obvious. And the session is relatively more powerful, it can save arrays, even objects, etc., to a certain extent, it can reduce the development cost. The following is the session usage code: Increase of session data: The code is as follows: <?php header(“Content-type: text/html; charset=utf-8;”);//Display in utf-8, has nothing to do with session session_start();//Start session data saving $_SESSION[‘name’]=”xuning”;*//Add session data. ?> Deletion of session data. The code is as follows: <?php header(“Content-type: text/html; charset=utf-8;”);//Display in utf-8, has nothing to do with session session_start();//Start session data unset($_SESSION[‘name’]=”xuning”);*//Delete session data. session_destory();//Delete all sessions ?> The modification of the session is the increase of the session data. View the session data, that is, take out the session data. The code is as…

CRUD (add, delete, modify, check) operation of php development message board

In php learning, it is good to open a guestbook as an introductory material for php. The sql required in the project: The code is as follows: create database form; use form; CREATE TABLE `message` ( `id` tinyint(1) NOT NULL auto_increment, `user` varchar(25) NOT NULL, `title` varchar(50) NOT NULL, `content` tinytext NOT NULL, `lastdate` date NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=gbk AUTO_INCREMENT=1 ; conn.php The code is as follows: <?php $cOnn= @ mysql_connect(“localhost”, “root”, “”) or die(“Database connection error”); mysql_select_db(“form”, $conn); mysql_query (“set names ‘gbk’”); ?> add.php The code is as follows: <?php include ‘conn.php’; if($_POST[‘submit ‘]){ $sql=”INSERT INTO message(id,user,title,content,lastdate) VALUES (NULL, ‘$_POST[user]’, ‘$_POST[title]’, ‘$_POST[content ]’, now())”; mysql_query($sql); //Page jump, realized by Javascript $url = “list.php”; echo “”; } ?> User: Title: Content: list.php The code is as follows: <?php include ‘conn.php’; ?> <?php echo “ Continue adding “; ?> <?php $sql=”select * from message order by id”; $query=mysql_query($sql); while ($row= mysql_fetch_array($query)){ ?> Title: User: “>Edit| “>Delete Content: Date published: delete.php The code is as follows: <?php include ‘conn.php’; $id = $_GET[‘id’]; $query=”delete from message where id=”.$id; mysql_query($query); ?> <?php//Page jump, implemented by Javascript $url = “list.php”; echo “”; ?> preEdit.php The code is as follows: <?…

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
首页
微信
电话
搜索