{"id":939,"date":"2021-03-11T00:12:06","date_gmt":"2021-03-10T16:12:06","guid":{"rendered":"http:\/\/www.tra56.com\/?p=939"},"modified":"2021-03-11T00:12:06","modified_gmt":"2021-03-10T16:12:06","slug":"939","status":"publish","type":"post","link":"https:\/\/www.tra56.com\/939.html","title":{"rendered":"discuz7 phpMysql\u64cd\u4f5c\u7c7b"},"content":{"rendered":"

MySql\u6570\u636e\u5e93\u8fde\u63a5\u7c7b\uff0c\u5927\u5bb6\u53ef\u4ee5\u770b\u4e0b\u7f51\u4e0a\u8001\u624b\u4eec\u7528\u7684\u4ec0\u4e48\u65b9\u6cd5\uff0c\u5927\u5bb6\u53ef\u4ee5\u76f4\u63a5\u62ff\u6765\u7528\uff0c\u4f46\u524d\u63d0\u662f\u5927\u5bb6\u80fd\u719f\u7ec3\u7684\u638c\u63e1\u7684\u57fa\u7840\u4e0a\uff0c\u8fd9\u6837\u624d\u80fd\u6709\u6240\u8fdb\u6b65\u3002<\/p>\n

<?php\r\n\/*\r\n* MySql\u6570\u636e\u5e93\u8fde\u63a5\u7c7b\r\n* mysql.class.php 2009.04.15 by Hackbaby\r\n*\/\r\nclass dbstuff {\r\nvar $version = '';\r\nvar $querynum = 0;\r\nvar $link = null;\r\n\/\/\u8fde\u63a5\u6570\u636e\u5e93\r\nfunction connect($dbhost, $dbuser, $dbpw, $dbname, $pconnect = 0, $halt = TRUE, $dbcharset2 = '') {\r\n$conn = empty($pconnect) ? 'mysql_connect' : 'mysql_pconnect';\r\nif (!$this->link = @$conn($dbhost, $dbuser, $dbpw, 1)) {\r\n$halt && $this->halt('Can not connect to MySQL server');\r\n} else {\r\nif($this->version() > '4.1') {\r\nglobal $charset, $dbcharset;\r\n$dbcharset = $dbcharset2 ? $dbcharset2 : $dbcharset;\r\n$dbcharset = !$dbcharset && in_array(strtolower($charset), array('utf-8', 'big5', 'utf-8')) ? str_replace('-', '', $charset) : $dbcharset;\r\n$serverset = $dbcharset ? 'character_set_connection='.$dbcharset.', character_set_results='.$dbcharset.', character_set_client=binary' : '';\r\n$serverset .= $this->version() > '5.0.1' ? ((empty($serverset) ? '' : ',').'sql_mode=\\'\\'') : '';\r\n$serverset && mysql_query("SET $serverset", $this->link);\r\n}\r\n$dbname && @mysql_select_db($dbname, $this->link);\r\n}\r\n\r\n}\r\n\/\/\u9009\u62e9\u6570\u636e\u5e93\r\nfunction select_db($dbname) {\r\nreturn mysql_select_db($dbname, $this->link);\r\n}\r\n\/\/\u6570\u636e\u5e93\u6267\u884c\u540e\u7684\u8fd4\u56de\u65b9\u6cd5\r\nfunction fetch_array($query, $result_type = MYSQL_ASSOC) {\r\nreturn mysql_fetch_array($query, $result_type);\r\n}\r\n\/\/\u8fd4\u56defetch_array\u65b9\u6cd5\u6267\u884c\u540e\u7684\u8fd4\u56de\u503c\r\nfunction fetch_first($sql) {\r\nreturn $this->fetch_array($this->query($sql));\r\n}\r\n\/\/\u8fd4\u56deresult\u65b9\u6cd5\u6267\u884c\u540e\u7684\u8fd4\u56de\u503c\r\nfunction result_first($sql) {\r\nreturn $this->result($this->query($sql), 0);\r\n}\r\n\/\/\u6267\u884c\u5bf9\u6570\u636e\u5e93\u7684\u64cd\u4f5c\r\nfunction query($sql, $type = '') {\r\nglobal $debug, $discuz_starttime, $sqldebug, $sqlspenttimes;\r\n\/\/\u5224\u65addebug\u8c03\u8bd5\r\nif(defined('SYS_DEBUG') && SYS_DEBUG) {\r\n@include_once WEB_ROOT.'.\/include\/debug.func.php';\r\nsqldebug($sql);\r\n}\r\n\/\/\r\n$func = $type == 'UNBUFFERED' && @function_exists('mysql_unbuffered_query') ?\r\n'mysql_unbuffered_query' : 'mysql_query';\r\nif(!($query = $func($sql, $this->link))) {\r\nif(in_array($this->errno(), array(2006, 2013)) && substr($type, 0, 5) != 'RETRY') {\r\n$this->close();\r\nrequire '.\/config.inc.php';\r\n$this->connect($dbhost, $dbuser, $dbpw, $dbname, $pconnect, true, $dbcharset);\r\n$this->query($sql, 'RETRY'.$type);\r\n} elseif($type != 'SILENT' && substr($type, 5) != 'SILENT') {\r\n$this->halt('MySQL Query Error', $sql);\r\n}\r\n}\r\n\/\/\u67e5\u8be2\u6761\u6570\u52a01\r\n$this->querynum++;\r\nreturn $query;\r\n}\r\n\/\/\u53d6\u5f97\u524d\u4e00\u6b21 MySQL \u64cd\u4f5c\u6240\u5f71\u54cd\u7684\u8bb0\u5f55\u884c\u6570\r\nfunction affected_rows() {\r\nreturn mysql_affected_rows($this->link);\r\n}\r\n\/\/\u6570\u636e\u5e93\u7684\u6587\u672c\u9519\u8bef\u63d0\u793a\r\nfunction error() {\r\nreturn (($this->link) ? mysql_error($this->link) : mysql_error());\r\n}\r\n\/\/\u8fd4\u56de\u4e0a\u4e00\u4e2a MySQL \u64cd\u4f5c\u4e2d\u7684\u9519\u8bef\u4fe1\u606f\u7684\u6570\u5b57\u7f16\u7801\r\nfunction errno() {\r\nreturn intval(($this->link) ? mysql_errno($this->link) : mysql_errno());\r\n}\r\n\/\/\u8fd4\u56de\u6570\u636e\u5e93\u64cd\u4f5c\u7ed3\u679c\r\nfunction result($query, $row = 0) {\r\n$query = @mysql_result($query, $row);\r\nreturn $query;\r\n}\r\n\/\/\u8fd4\u56de\u6570\u636e\u5e93\u67e5\u8be2\u7b49\u64cd\u4f5c\u7684\u6570\u76ee\r\nfunction num_rows($query) {\r\n$query = mysql_num_rows($query);\r\nreturn $query;\r\n}\r\n\/\/\u53d6\u5f97\u7ed3\u679c\u96c6\u4e2d\u5b57\u6bb5\u7684\u6570\u76ee\r\nfunction num_fields($query) {\r\nreturn mysql_num_fields($query);\r\n}\r\n\/\/\u91ca\u653e\u7ed3\u679c\u5185\u5b58\r\nfunction free_result($query) {\r\nreturn mysql_free_result($query);\r\n}\r\n\/\/\u53d6\u5f97\u4e0a\u4e00\u6b65 INSERT \u64cd\u4f5c\u4ea7\u751f\u7684 ID\r\nfunction insert_id() {\r\nreturn ($id = mysql_insert_id($this->link)) >= 0 ? $id : $this->result($this->query("SELECT last_insert_id()"), 0);\r\n}\r\n\/\/\u4ee5\u6570\u7ec4\u7684\u5f62\u5f0f\u8fd4\u56de\u67e5\u8be2\u7ed3\u679c\r\nfunction fetch_row($query) {\r\n$query = mysql_fetch_row($query);\r\nreturn $query;\r\n}\r\n\/\/\u4ece\u7ed3\u679c\u96c6\u4e2d\u53d6\u5f97\u5217\u4fe1\u606f\u5e76\u4f5c\u4e3a\u5bf9\u8c61\u8fd4\u56de\r\nfunction fetch_fields($query) {\r\nreturn mysql_fetch_field($query);\r\n}\r\n\/\/\u83b7\u53d6Mysql\u7684\u7248\u672c\r\nfunction version() {\r\nif(empty($this->version)) {\r\n$this->version = mysql_get_server_info($this->link);\r\n}\r\nreturn $this->version;\r\n}\r\n\/\/\u5173\u95ed\u8fde\u63a5\r\nfunction close() {\r\nreturn mysql_close($this->link);\r\n}\r\n\/\/\u9519\u8bef\u63d0\u793a\r\nfunction halt($message = '', $sql = '') {\r\ndefine('CACHE_FORBIDDEN', TRUE);\r\nrequire_once WEB_ROOT . '.\/include\/db_mysql_error.inc.php';\r\n}\r\n}\r\n?><\/pre>\n

<\/p>\n","protected":false},"excerpt":{"rendered":"

MySql\u6570\u636e\u5e93\u8fde\u63a5\u7c7b\uff0c\u5927\u5bb6\u53ef\u4ee5\u770b\u4e0b\u7f51\u4e0a\u8001\u624b\u4eec\u7528\u7684\u4ec0\u4e48\u65b9\u6cd5\uff0c\u5927\u5bb6\u53ef\u4ee5\u76f4\u63a5\u62ff\u6765\u7528\uff0c\u4f46\u524d\u63d0\u662f\u5927\u5bb6\u80fd\u719f\u7ec3\u7684\u638c\u63e1\u7684\u57fa\u7840 […]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10],"tags":[26,72,70],"class_list":["post-939","post","type-post","status-publish","format-standard","hentry","category-php","tag-php"],"_links":{"self":[{"href":"https:\/\/www.tra56.com\/wp-json\/wp\/v2\/posts\/939"}],"collection":[{"href":"https:\/\/www.tra56.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tra56.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tra56.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tra56.com\/wp-json\/wp\/v2\/comments?post=939"}],"version-history":[{"count":1,"href":"https:\/\/www.tra56.com\/wp-json\/wp\/v2\/posts\/939\/revisions"}],"predecessor-version":[{"id":940,"href":"https:\/\/www.tra56.com\/wp-json\/wp\/v2\/posts\/939\/revisions\/940"}],"wp:attachment":[{"href":"https:\/\/www.tra56.com\/wp-json\/wp\/v2\/media?parent=939"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tra56.com\/wp-json\/wp\/v2\/categories?post=939"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tra56.com\/wp-json\/wp\/v2\/tags?post=939"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}