1dbf0001e40d729cb4bd

The 22nd day of my php learning – MySQL add, delete, modify, check basic operations

1. MySQL client, steps to operate MySQL Step 1: Connect to the MySQL database server mysql –uroot -root The second step: select the database to be operated (current database) use db_name The third step: set the character set set names gbk Step 4: Execute SQL statements: add, delete, modify, check Add: INSERT INTO table_name(title,author,addate) VALUES(‘title’,’admin’,now()) Delete: DELETE FROM table_name WHERE conditional expression Modify: UPDATE table_name SET title=”New title” WHERE conditional expression Query: SELECT * FROM table_name WHERE condition ORDER BY LIMIT 2. Steps for PHP to operate MySQL (MySQL function) Step 1: Connect MySQL Database Server mysql_connect() Meaning: connect to My sql database server Format: resource mysql_connect (host address, user name, user password) Return value: If the connection is successful, return the resource identifier, if the connection fails, return false Example: $link = mysql_connect(“ localhost “,”root”,”root”); exit() Meaning: After outputting information, the interrupt script continues to run downward Format: void exit([$string]) Note: The $string parameter is optional, if there is no parameter, it will be interrupted directly; if there is a parameter, it will be output first and then interrupted Example: exit(“ Connection to MySQL failed”); header() Meaning: Send some information to the browser client through the header() function, such…

php5.4 and above mysqli instance operation mysql add, delete, modify, check

1 <?php 2 //php5.4 or above mysqli instance operation mysql 3 header(“Content-type:text/html;charset=utf8”); 4 $cOnn= new mysqli(‘localhost’, ‘root’, ‘root’); 5 mysqli_select_db($conn, ‘cc’); 6 $conn->query(‘set names utf8’); 7 $sql_search = “select * from bb where id=9”; 8 /*$sql_add = “insert into bb(name) values ​​(‘Xiaoming’)”; 9 $sql_update = “update bb set name = ‘small h’ where id=9”; 10 $sql_del = “delete from bb where id=9”;*/ 11 $result = $conn->query($sql_search); 12 while ($row = $result->fetch_array()) { 13 echo $row[‘name’] . ‘ ‘; 14 } 15 $conn->close();

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

In the past few days, I am going to re-learn, sort out the knowledge system, and do some things according to the division of 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 operation is: 1. Connect to the database server 2. Select the database 3. Execute the SQL statement 4. Process the result set 5. Print the operation information > The relevant functions used are•resource mysql_connect ( [string server [, string username [, string password [, bool new_link [, int client_flags]]]]] ) to 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 DELETE associated with link_identifier The number of rows affected by the query. •bool mysql_close ( [resource link_identifier] ) returns TRUE on success, FALSE on failure. •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] )…

PHP modify news classification code, complete news unlimited classification code, can add, delete, move, modify

//Connect to the database tutorial $link = mysql tutorial_connect('localhost','root','password& #39;) or die(mysql_error()); mysql_select_db('sortclass',$link); mysql_query(“set names ' gbk'”); //Unlimited classification class library class sortclass{ var $data = array(); var $data = array(); p> var $child = array(-1=>array()); var $layer = array(-1=>-1) ; var $parent = array(); var $link; var $table; function sortclass ($link, $table){ $this->setnode(0, -1, 'top node'); $this-> link = $link; $this->table = $table; $node = array(); $results = mysql_query('select * from '.$this->table.'',$this->link); while($node = mysql_fetch_assoc($results)){ $this->setnode($node['cid'], $node['pid' 39;],$node['cname']); } } function setnode ($id, $parent, $value){ $parent = $parent?$parent:0; $this->data[$id] = $value; $this->data[$id] = $value; p> $this->child[$id] = array(); $this->child[$parent][] = $id; $this->parent[$id] = $parent; $this->layer[$id] = !isset($this->layer[$ parent])? 0 : $this->layer[$parent] + 1; } function getlist (&$tree, $root= 0) { foreach ($this->child[$root] as $key=>$id){ $tree[] = $id; $tree[] = $id; p> if ($this->child[$id]) $this->getlist($tree, $id); } } function getvalue ($id){return $this->data[$id];} function getlayer ($id, $space = false){ return $space?str_repeat($space, $this->layer[$id]):$this->layer[$id]; } function getparent ($ id){return $this->parent[$id];} function getparents ($id){ while ($this->parent[$id] !&# 61; -1){ $id = $parent[$this->layer[$id]] = $this->parent[$id]; } ksort($parent); reset($parent); return $parent; } function getchild ($id){return $this->child[$id];} function getchilds ($id = 0){ $child = array($id); $this->getlist($child, $id); return $child; } function addnode($name,$pid){ mysql_query(“insert into $this->table (`pid`,` cname`)…

Technology sharing pictures

ThinkPHP (add, modify, delete)

Realize the addition of products 1, change the name of the form element in the add.html page GoodsThe add() method of the Goods controller Loop inadd.html 2, set the submission location 3, add commodity code seeGoodsController.class.php Method 1: $this->redirect();is also a redirect Method Two(usecreateto create an array): create()The role of: 1, match the value of the form element with the field in the database one by one. 2, remove the fields that are not in the database from the array. The syntax added in PHP is as follows: success() and error()methods are the successful execution and Failed method, you can use this method to achieve jump. Method Three: I() function I() is used to getget, post, session\COOKIEetc. data. Syntax:I(‘Type of variable.Name of variable‘,[default],[filter method]) variable type Description Get Get parameters submitted by get Post Get parameters submitted by POST param Automatically determine whether it is get or post request Get the data submitted by request Session Get session data COOKIE Get COOKIEData server Similar to $_SERVER[]; globals Get $GLOBALSparameters path Get the pathinfopatternurlparameter Usage: Description Example Get getsubmittednamevariable I(‘get.name’) Get getsubmittednamevariables and assign default values I(‘get.name’,’李白‘) Get the value and call the function to process the data I(‘get.name’,’ ‘, mysql_real_escape_string,…

1dbf0001e40d729cb4bd

The 22nd day of my php learning – MySQL add, delete, modify, check basic operations

1. MySQL client, steps to operate MySQL Step 1: Connect to the MySQL database server mysql –uroot -root The second step: select the database to be operated (current database) use db_name The third step: set the character set set names gbk Step 4: Execute SQL statements: add, delete, modify, check Add: INSERT INTO table_name(title,author,addate) VALUES(‘title’,’admin’,now()) Delete: DELETE FROM table_name WHERE conditional expression Modify: UPDATE table_name SET title=”New title” WHERE conditional expression Query: SELECT * FROM table_name WHERE condition ORDER BY LIMIT 2. Steps for PHP to operate MySQL (MySQL function) Step 1: Connect MySQL Database Server mysql_connect() Meaning: connect to My sql database server Format: resource mysql_connect (host address, user name, user password) Return value: If the connection is successful, return the resource identifier, if the connection fails, return false Example: $link = mysql_connect(“ localhost “,”root”,”root”); exit() Meaning: After outputting information, the interrupt script continues to run downward Format: void exit([$string]) Note: The $string parameter is optional, if there is no parameter, it will be interrupted directly; if there is a parameter, it will be output first and then interrupted Example: exit(“ Connection to MySQL failed”); header() Meaning: Send some information to the browser client through the header() function, such…

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