Add, delete, modify, check classification information (Jquery+Ajax+PHP+MySQL)
This article will use Jquery+Ajax+PHP+MySQL to realize the management of customer classification, and use jNotify to prompt the operation results. There are demos, free download links at the bottom of the page. If you want to see more js special effects, website source code, js tutorial, please visit [Material Fire] http://www.sucaihuo.com/ js also has a demo DEMO, the most important thing is that it can be downloaded for free. 1, Table ·catalist· CREATE TABLE `catalist` ( `cid` int(11) NOT NULL auto_increment, `title` varchar(100) NOT NULL, `sort` mediumint(6) NOT NULL default '0', PRIMARY KEY (`cid`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; 2. Then load the jquery library, the operation result prompt plug-in jNotify and the deletion confirmation plug-in hiAlert index.php 3. We first traverse the data in the table ·catalist·, and add, delete and modify buttons for each item, and add an increase button at the bottom. <?php $query = mysql_query(“select * from catalog order by cid asc”); while($row=mysql_fetch_array($query)){ $list .= ” “.$row[' title'].” “; } ?> HTML 4. Then we put the traversed list into #catalist in the form of a string, the code is as follows: Customer Category Add a new item jQuery The operation mode added in global.js is as…
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…
PHP file operation class (create, write, delete, modify, copy, move, create directory)-PHP source code
PHP file operation class, this file operation class can realize file creation, writing, deletion, modification, copying, moving, creating directory, deleting directory, you can refer to it. Example 1 The code is as follows <?php /* File name: ClassFile.php Function: object-oriented, file operation class (view file, delete file, upload file) Author: source of infection Time: 2007-1-11 */ class ClassFile { private $dir_name; private $file_name; private $dh; //private $file_path; //Constructor, open the working file directory function __construct($PDirName) { $this->dir_name = $PDirName; if(is_dir($this->dir_name)) //Open directory if($this->dh = opendir($this->dir_name) or dir(‘The path is wrong, please check the path again!’)); }//function __construct(); //Close the file directory function __destruct() { //Close directory closedir($this->dh); }//function __destruct(); //Add a file to the current folder, and check whether there is a file with the same name function AddFile($temp_file) { //Read directory while($this->file_name = readdir($this->dh)) { if($this->file_name==$temp_file) //Check if it has the same name as an existing file { echo ‘The file has the same name, please change the file name…’; exit; } else { //Copy the temporary file to the current directory $up_id = copy($temp_file,”$this->dir_name/$temp_file”); if(!$up_id) { echo ‘File upload failed, please upload again…’; exit; } else { unlink($temp_file); //delete temporary file echo “”; }//if }//if }//while }//function AddFile();…
PHP add, delete, modify, check and package
Encapsulation code: host = $host; $this->username = $username; $this->password = $password; $this->db_name = $db_name; $this->cOnn= mysql_connect($host,$username,$password) or die ('Database connection failed! Error reason: '.mysql_error()); mysql_select_db($db_name) or die(‘Database selection failed! Error reason: '.mysql_error()); mysql_query(“SET CHARACTER SET utf8”); } /** * Close the data connection */ public function close() { mysql_close($this->conn); } /** * @description call method with * @param $sql * @return array */ public function QueryAll($sql) { $this->open(); $rs = mysql_query($sql,$this->conn); $objList = array(); while($obj = mysql_fetch_object($rs)) { if ($obj) { $objList[] = $obj; } } $this->close(); return $objList; } /** * description query all return Json format, for communication * @param $sql * @return string */ public function QueryAllJson($sql) { echo $sql; $this->open(); $rs = mysql_query($sql,$this->conn); $objList = array(); $i=0; while($obj = mysql_fetch_object($rs)) { $objList[$i]=$obj; $i++; } $this->close(); return json_encode(array(“result”=>”success”,'data'=>$objList)); } /** * @description Insert data into the database * @param $tableName table name * @param array $columns An array containing all column names in the table. The default empty array is all ordered field names * @param array $values contains an array of attribute values corresponding to all fields * @return int */ public function insertData($tableName, $columns=array(), $values=array()) { $sql = 'insert into '.$tableName .'( '; for($i =…
PHP add, delete, modify, check and package
Encapsulation code: host = $host; $this->username = $username; $this->password = $password; $this->db_name = $db_name; $this->cOnn= mysql_connect($host,$username,$password) or die ('Database connection failed! Error reason: '.mysql_error()); mysql_select_db($db_name) or die(‘Database selection failed! Error reason: '.mysql_error()); mysql_query(“SET CHARACTER SET utf8”); } /** * Close the data connection */ public function close() { mysql_close($this->conn); } /** * @description call method with * @param $sql * @return array */ public function QueryAll($sql) { $this->open(); $rs = mysql_query($sql,$this->conn); $objList = array(); while($obj = mysql_fetch_object($rs)) { if ($obj) { $objList[] = $obj; } } $this->close(); return $objList; } /** * description query all return Json format, for communication * @param $sql * @return string */ public function QueryAllJson($sql) { echo $sql; $this->open(); $rs = mysql_query($sql,$this->conn); $objList = array(); $i=0; while($obj = mysql_fetch_object($rs)) { $objList[$i]=$obj; $i++; } $this->close(); return json_encode(array(“result”=>”success”,'data'=>$objList)); } /** * @description Insert data into the database * @param $tableName table name * @param array $columns An array containing all column names in the table. The default empty array is all ordered field names * @param array $values contains an array of attribute values corresponding to all fields * @return int */ public function insertData($tableName, $columns=array(), $values=array()) { $sql = 'insert into '.$tableName .'( '; for($i =…
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 saving session data $_SESSION[‘name’]=”xuning”;*//Add session data. ?> Delete 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 follows:…
PHP lightweight database operation class Medoo add, delete, modify, query 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. Provides a simple, easy-to-learn, and flexible API to improve the efficiency and performance of developing web applications, and the volume is less than 8KB. Features Lightweight, only one file Easy to learn, the data structure is clear at a glance Support a variety of SQL syntax, and support complex query conditions Support multiple databases, including MySQL, MSSQL, SQLite, etc. Security against SQL injection Free, based on the MIT license Sample Code Increase 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”…
Simple php database operation code (add, delete, modify, check)
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…