Tag:sts class return ring Auto iconv des param func
<?php/** * __construct ($Mysql _config) Constructors $Mysql _config[' server ') servers-$ mysql_config[' user ' username-$Mysql _config[' pwd '] password-$Mysql _config[' name '] Database name-$Mysql _config[' character '] Character set * Mysql_ Alter_drop ($table, $name) Delete a field $table indicate $name field name * Mysql_alter_add ($table, $name, $type) Add a field $table indicates that the $name field name is $ Type field types * Mysql_instert ($data = "", $name = "") Add a data $data array format the data is exactly the same as the database field $name indicates that * MYSQL_INSERT_ID () has been generated by the previous insert operation ID * Mysql_delete ($name = "", $where = "") delete data $name indicate $where condition * mysql_update ($name = "", $data = "", $where = "") Modify a statement $name indicate $ Data array format is simply consistent with database fields $where condition * mysql_query ($sql = "") executes an SQL statement $sql statement * Mysql_array ($array = "") returns a two-dimensional array $array The return of the previous query Value * Mysql_json_encode ($ array, $fromCode = "gb2312", $toCode = "utf-8") array conversion JSON * MYSQL_ROWS () returns the corresponding number of bars * Mysql_rows_result () Frees resource * function __destruct () destructor to automatically close library */
_ooooo_//o8888888o//88 ". "88//(| -_- |) o\ =/o//____/'---' \____//. ' \\| |//'.///\\| | | : ||| // // / _||||| -:- ||||| - // | | \\\ - /// | |// | \_| ' \---/' | |//\-\__ '-' ___/-. /// ___`. . '/--.--\ '. . __// ."" ' < '. ___\_<|>_/___. ' > ' ".//| | : `- \`.; `\ _ /`;. `/ - ` : | |// \ \ `-. \_ __\/__ _/.-'////\ ====== '-.____ '-.___\_____/___.-' ____.-' ======//' =---= '//// ... ....//Buddha Bless the Eternal bug//Buddha Yue://-------------* * * * * * * * * * * * * Office Building, writing Room programmer;//program staff write procedures, and take the program for drinks. Sober only sit on the internet, drunkAlso to the net sleep,//drunk Awake day after day, online network next year. I hope the old computer, do not want to bow to the boss before;//Mercedes-Benz BMW is interesting, bus self-programmers. Others laugh at me crazy, I laugh at my life is too cheap,//Don't see the street pretty sister, which is the programmer?
Class tl_mysql{private $conn;p rivate $result;/* constructor */public function __construct ($Mysql _config) {if (Is_array ($Mysql _ Config) {$this->conn = mysql_connect (!empty ($Mysql _config[' server ')? $Mysql _config[' server ']: ' localhost ',! Empty ($Mysql _config[' user ')? $Mysql _config[' user ']: ' Root ', $Mysql _config[' pwd ']; mysql_select_db ($Mysql _config[ ' name ']); mysql_query (!empty ($Mysql _config[' character ")? $Mysql _config[' character ']: ' utf8_general_ci ');} }/** * Delete a field * @param [type] $table [description] indicates * @param [type] $name [description] Field name */P ublic function Mysql_alter_drop ($table, $name) {$sql = "ALTER TABLE". $table. "Drop column". $name. ""; $this->mysql_query ($sql); return $sql; }/** * Adds a field * @param [type] $table [description] indicates * @param [type] $name [description] Field name * @para m [Type] $type [description] Type/number of digits */Public Function Mysql_alter_add ($table, $name, $type) {$sql = "ALTER TABLE ". $table." Add ". $name." ". $type." "; $this->mysql_query ($sql); return $sql; }/** * Add a data * @param [type] $data [description] Data * @param [type] $name [description] Database name * @return [Type] [description] */Public Function mysql_instert ($data = "", $name = "") {if (Is_array ($data) & ;&!empty ($name)) {$key = ""; $value = ""; foreach ($data as $keys + = $values) {$key = $key. " `" . $keys. "',"; $value = $value. "‘" . $values. "‘,";} $key = substr ($key, 0,-1), $value = substr ($value, 0,-1); $sql = "INSERT into". $name. " (". $key.") VALUES (". $value.") "; $this->mysql_query ($sql); return $sql; }else{$sql = "Mysql_instert (not an array, table name)"; return $sql; }/* Gets the id*/public function mysql_insert_id () {return mysql_insert_id () generated by the previous INSERT operation; }/** * Delete data * @param [type] $name [description] Table name * @param [Type] $where [description] condition */Pub Lic function mysql_delete ($name = "", $where = "") {if (!empty ($name) &&!empty ($where) {$sql = ' delete from '. $name. "where". $where; $this->mysql_query ($sql); return $sql; }else{$sql = "mysql_delete (table name, database condition)"; return $sql; }}/** * Modify a statement * @param [type] $name [description] Table name * @param [Type] $data [description] Data * @param [Type] $where [description] Condition */Public Function mysql_update ($name = "", $data = "", $where = "") {if (Is_ar Ray ($data)) {$datas = ""; foreach ($data as $keys = = $values) {$datas = $datas. $keys. "= '". $values. "',";} $sql = "Update". $name. "Set". substr ($datas, 0,-1). "Where". $where; $this->mysql_query ($sql); return $sql; }else{$sql = "mysql_update (table name, data, condition)"; return $sql; }}/** * executes an SQL statement * @param [type] $sql [description] SQL statement * @return [type] [description] */ Public Function mysql_query ($sql = "") {if (!empty ($sql)) {$result =mysql_query ($sql); return $this->result = $result; }else{$result = "mysql_query (mySQL statement) "; return $result; }}/** * Returns a two-dimensional array * @param [type] $array [description] Executed SQL statement */Public function Mysql_array ($arr Ay= "") {if (!empty ($array)) {$result =array (); while ($row = Mysql_fetch_array ($array, Mysql_assoc)) {$result [] = $row;} return $result; }else{$_array = Array (' Mysql_array (executed SQL statement) '); return $_array; }}/** * [Encodeconvert description] Convert JSON * @param [type] $str [description] Array * @param [type ] $fromCode [description] gb2312 * @param [Type] $toCode [description] Utf-8 * @return [type] [DESCRI Ption] */function Mysql_json_encode ($str, $fromCode, $toCode) {if (Strtoupper ($toCode) = = Strtoupper ($fromCode )) return $str; if (is_string ($STR)) {if (function_exists (' mb_convert_encoding ')) {return mb_convert_encoding ($s TR, $toCode, $fromCode); } else{return Iconv ($fromCode, $toCode, $STR); }} elseif (Is_array ($str)) {foreach ($str as $k = = $v) { $STR [$k] = $this->mysql_json_encode ($v, $fromCode, $toCode); } return $STR; } return $STR; }/** * Returns the corresponding number of bars */Public Function mysql_rows () {return mysql_affected_rows (); }//Release resource public Function Mysql_rows_result () {return mysql_free_result ($this->result); }//destructor, automatically shuts down the database, garbage collection mechanism public Function __destruct () {if (!empty ($this->result)) {$this->m Ysql_rows_result (); } return Mysql_close ($this->conn); }} $Mysql _config = array (' server ' = = ' localhost ',//Specify the servers to be connected. ' User ' = ' root ',//username. The default value is the user name of the server process owner. ' pwd ' = ' 9803164 ',//password. The default value is a blank password. ' Name ' = ' Test ',//database name ' character ' = ' utf8_general_ci ',//character set); $Mysql = new Mysql ($Mysql _config);
< Xiao Tian eat dumplings > Php:mysql Basic class