代码拷贝框

/********************************************

* *

* Name : MySQL Manager *

* Author : Windy_sk *

* Email : flyhorses@sina.com *

* HomePage: None (Maybe Soon) *

* Notice : U Can Use & Modify it freely, *

* BUT PLEASE HOLD THIS ITEM. *

* *

********************************************/

/*--------------------------------------------------------------------------------------------------------------------

How To Use:

$MySQL = new MySQL($host, $user, $pass)// Set the Database Class

$MySQL->ChangUser($user, $pass, $db="")// Change the Database User (Unusable in some versoin of MySQL)

$MySQL->OptimizeTab()// Optimize the Tablses of Selected Database

$MySQL->ReadSqlFile($file)// Read SQL File And Send Content of the File to HandleSQL($strSQL)

$MySQL->HandleSQL($strSQL)// Split the SQL Query String into a array from a whole String (Maybe Read from a File)

$MySQL->BatchExec($ArrSQL)// Execute Multi Query from an Array (Use HandleSQL First)

$MySQL->Connect($pconnect = false)// Build a Connection to MySQL to $MySQL->DB_conn

$MySQL->SelectDB($the_db)// Select a Database of MySQL to $MySQL->DB_select (Must Build Connect First)

$MySQL->Query($sql)// Execute a Query of MySQL, Result into $MySQL->DB_resut

$MySQL->SeekData($line)// Seek Data Row in the $MySQL->DB_resut ($MySQL->DB_Qtype Must Be Setted into True Before Query)

$MySQL->GetResult($line, $field="")// The Same Use as mysql_result ($MySQL->DB_Qtype Must Be Setted into True Before Query)

$MySQL->GetRS()// Return The Current Result as an Array and Set the Point of Result to the Next Result

$MySQL->GetStat()// Get the Current Status of MySQL

$MySQL->GetDBs()// Get the Databases List of Current MySQL Server as an Array

$MySQL->GetTabs($the_db)// Get the Tables List of Current Selected Database as an Array

$MySQL->GetIdx($the_tab) // Get the Indexes List of a Table as an Array

$MySQL->GetTabSetting($the_tab)// Get the Whole Struction of Current Selected Database as an Array

$MySQL->GetTabData($the_tab)// Get All of The Data of a Table

$MySQL->GetTabFields($the_db, $the_tab)// Get the Columns List of a Table as an Array

$MySQL->GetQueryFields()// Get the Columns List of Current Query

$MySQL->Free()// Free the $MySQL->DB_result in order to Release the System Resource

$MySQL->Close()// Close Current MySQL Link

$MySQL->Error($str)// Handle the Errors

--------------------------------------------------------------------------------------------------------------------*/

class MySQL {

var $DB_host= "";

var $DB_user= "";

var $DB_pass= "";

var $DB_db= "";

var $DB_conn= NULL;

var $DB_select= NULL;

var $DB_error= false;

var $DB_qstr= "";

var $DB_result= NULL;

var $DB_RStype= 1;

var $DB_Qtype= false;

function MySQL($host, $user, $pass) {

$this->DB_serv = $host;

$this->DB_user = $user;

$this->DB_pass = $pass;

return;

}

function ChangUser($user, $pass, $db="") { // Maybe doesn't work !

eval("\$result = mysql_change_user('$user', '$pass'".($db==""?"":", '$db'").");");

return $result;

}

function OptimizeTab() {

if($this->DB_select == NULL || $this->DB_conn == NULL) return false;

$tabs = $this->GetTabs($this->DB_db);

for($i=0; $i

$this->Query("OPTIMIZE TABLE ".$tabs[$i]);

}

$this->Free();

return true;

}

function ReadSqlFile($file) {

return is_file($file)?$this->HandleSQL(join("",file($file))):"";

}

function HandleSQL($strSQL) {

$strSQL= trim($strSQL);

$strSQL= preg_replace("/^#[^\n]*\n?$/m", "", $strSQL);

$strSQL= preg_replace("/\r\n/", "\n", $strSQL);

$strSQL= preg_replace("/[\n]+/", "\n", $strSQL);

$strSQL= preg_replace("/[\t ]+/", " ", $strSQL);

$strSQL= preg_replace("/\/\*[^(\*\/)]*\*\//", "", $strSQL);

$temp= split(";",$strSQL);

$result= array();

for($i=0; $i

if(str_replace("\n","",$temp[$i]) != "") {

$result[] = preg_replace("/^\n*(.*)\n*$/m","\\1",$temp[$i]);

}

}

return($result);

}

function BatchExec($ArrSQL){

if($this->DB_select == NULL || $this->DB_conn == NULL) return false;

for($i=0; $i

@mysql_unbuffered_query($ArrSQL[$i], $this->DB_conn);

$this->DB_qstr = $ArrSQL[$i];

if(mysql_error() != "")$this->Error("Error Occur in Batch Query");

}

return true;

}

function Connect($pconnect = false) {

if($pconnect) {

$this->DB_conn = @mysql_pconnect($this->DB_host, $this->DB_user, $this->DB_pass);

} else {

$this->DB_conn = @mysql_connect($this->DB_host, $this->DB_user, $this->DB_pass);

}

$this->DB_qstr = "none (Connect to MySQL Server)";

if(mysql_error() != "")$this->Error("Could not connect to MySQL Server");

return;

}

function SelectDB($the_db) {

if($this->DB_conn == NULL) return false;

$this->DB_db = $the_db;

$this->DB_select = @mysql_select_db($the_db, $this->DB_conn);

$this->DB_qstr = "none (Select Database)";

if(mysql_error() != "")$this->Error("Could not connect to the Database");

return true;

}

function Query($sql) {

if($this->DB_conn == NULL) return false;

$this->Free();

$ifsel = strstr("|selec|show |descr|expla|", strtolower(substr(trim($sql), 0, 5)));

if($this->DB_Qtype) {

$this->DB_result = @mysql_query($sql, $this->DB_conn);

} else {

$this->DB_result = @mysql_unbuffered_query($sql, $this->DB_conn);

}

$this->DB_qstr= $sql;

if($ifsel) {

$num_rows = @mysql_num_rows($this->DB_result);

} else {

$num_rows = @mysql_affected_rows($this->DB_conn);

$this->Free();

}

if(mysql_error() != "")$this->Error("Error Occur in Query !");

return $num_rows;

}

function SeekData($line) {

if(!$this->DB_Qtype || $this->DB_result == NULL) return false;

$flag = @mysql_data_seek($this->DB_result, $line);

if(mysql_error() != "")$this->Error("Error Occur in Query !");

return $flag;

}

function GetResult($line, $field=""){

if(!$this->DB_Qtype || $this->DB_result == NULL) return false;

eval("\$result = @mysql_result(\$this->DB_result, $line".(empty($field)?"":", '$field'").");");

if(mysql_error() != "")$this->Error("Error Occur in Query !");

return $result;

}

function GetRS(){

if($this->DB_result == NULL) return false;

switch($this->DB_RStype){

case 1:

$flag = ($row = @mysql_fetch_assoc($this->DB_result));

break;

case 2:

$flag = ($row = @mysql_fetch_row($this->DB_result));

break;

case 3:

$flag = ($row = @mysql_fetch_array($this->DB_result));

break;

default:

$flag = ($row = @mysql_fetch_assoc($this->DB_result));

}

$this->DB_qstr= "none(Get Recordset)";

if(mysql_error() != "")$this->Error("Error Occur in Get Recordset !");

return ($flag?$row:false);

}

function GetStat() {

if($this->DB_conn == NULL) return "";

$result = "";

$result .= "MySQL server version: ".mysql_get_server_info()."
\n";

$result .= "MySQL protocol version: ".mysql_get_proto_info()."
\n";

$result .= "MySQL host info: ".mysql_get_host_info()."
\n";

$result .= "MySQL client info: ".mysql_get_client_info()."
\n";

$result .= str_replace(" ","
\n",mysql_stat($this->DB_conn));

return $result;

}

function GetDBs() {

$this->Free();

$dbs = array();

$this->DB_result = @mysql_list_dbs($this->DB_conn);

$this->DB_qstr = "none (List Databases)";

if (mysql_error() != "") $this->Error("Could not List Databases");

$dbs = array();

$num_dbs = mysql_num_rows($this->DB_result);

for ($i = 0; $i < $num_dbs; $i++) {

$dbs[] = mysql_dbname($this->DB_result, $i);

}

$this->Free();

return $dbs;

}

function GetTabs($the_db) {

$this->Free();

$this->DB_result = @mysql_list_tables($the_db);

$this->DB_qstr = "none (List Tables of $the_db)";

if (mysql_error() != "") $this->Error("Could not List Tables");

$tabs = array();

$num_tabs = mysql_num_rows($this->DB_result);

for ($i = 0; $i < $num_tabs; $i++) {

$tabs[] = mysql_tablename($this->DB_result, $i);

}

$this->Free();

return $tabs;

}

function GetIdx($the_tab) {

$this->Free();

$this->DB_qstr = "SHOW INDEX FROM $the_tab";

$this->DB_result = mysql_query($this->DB_qstr);

if (mysql_error() != "") $this->Error("Could not List Table's Setting");

$idxes = array();

while($row = mysql_fetch_array($this->DB_result)){

if($row["Key_name"] != "PRIMARY") {

$tmp = $row["Column_name"];

if($row["Sub_part"] != "") $tmp .= "(".$row["Sub_part"].")";

if($row["Seq_in_index"] == 1) {

if(count($idxes) != 0)

$idxes[count($idxes)-1] .= ")";

$idxes[] = "INDEX ".$row["Key_name"]." (".$tmp;

} else {

$idxes[count($idxes)-1] .= ", $tmp";

}

}

}

if(count($idxes) != 0)

$idxes[count($idxes)-1] .= ")";

$this->Free();

return $idxes;

}

function GetPri($the_tab) {

$this->Free();

$this->DB_qstr = "SHOW FIELDS FROM $the_tab";

$this->DB_result = mysql_query($this->DB_qstr);

if (mysql_error() != "") $this->Error("Could not List Table's Setting");

$keys= "";

while($row = mysql_fetch_assoc($this->DB_result)) {

if($row["Key"] == "PRI" || $row["Key"] == "MUL")

$keys[]= $row["Field"];

}

$this->Free();

return $keys;

}

function GetTabSetting($the_tab) {

$this->Free();

$this->DB_qstr = "SHOW FIELDS FROM $the_tab";

$this->DB_result = mysql_query($this->DB_qstr);

if (mysql_error() != "") $this->Error("Could not List Table's Setting");

$result = "CREATE TABLE $the_tab (\n";

$P_key= "";

while($row = mysql_fetch_assoc($this->DB_result)) {

$string= "".$row["Field"]." ".$row["Type"]." ";

if($row["Null"] == "")$string .= "NOT NULL ";

if($row["Default"] != "")$string .= "Default \"".$row["Default"]."\" ";

if($row["Key"] == "PRI")$P_key.= "PRIMARY KEY (".$row["Field"].") ,\n";

elseif($row["Key"] == "MUL")$P_key.= "KEY ".$row["Field"]." (".$row["Field"].") ,\n";

$string .= $row["Extra"].",\n";

$result .= $string;

}

$result .= $P_key;

$idxes = $this->GetIdx($the_tab);

for($i=0; $i

$result .= "".$idxes[$i]." ,\n";

}

$result .= ");\n";

$this->Free();

return $result;

}

function GetTabData($the_tab) {

$this->Free();

$this->DB_qstr = "SELECT * FROM $the_tab";

$this->DB_result = mysql_query($this->DB_qstr);

if (mysql_error() != "") $this->Error("Could not List Table's Setting");

$result = "";

while($row = mysql_fetch_row($this->DB_result)) {

$result .= "INSERT INTO $the_tab VALUES (";

for($i=0; $i

$result .= "\"".addslashes($row[$i])."\",";

$result .= ");\n";

}

$result = str_replace("\",);","\");",$result);

return $result;

}

function GetTabFields($the_db, $the_tab) {

$this->Free();

$this->DB_result = @mysql_list_fields($the_db, $the_tab, $this->DB_conn);

$this->DB_qstr = "none (List Fields of $the_tab)";

if (mysql_error() != "") $this->Error("Could not List Fields");

$fields = array();

$columns = mysql_num_fields($this->DB_result);

for ($i = 0; $i

$fields[] = mysql_field_name($this->DB_result, $i);

}

$this->Free();

return $fields;

}

function GetQueryFields() {

if($this->DB_result == NULL) return false;

$fields = array();

$columns = mysql_num_fields($this->DB_result);

for ($i = 0; $i

$fields[] = mysql_field_name($this->DB_result, $i);

}

return $fields;

}

function Free() {

@mysql_free_result($this->DB_result);

$this->DB_result = NULL;

return;

}

function Close() {

if($this->DB_result != NULL)

$this->Free();

if($this->DB_conn != NULL)

@mysql_close($this->DB_conn);

if($this->DB_select != NULL)

$this->DB_select = NULL;

return;

}

function Error($str) {

$err_msg = "";

$err_msg .= "Time: ".gmdate("Y-n-j G:i", time() + 8 * 3600)."\n";

$err_msg .= "File: ".$_SERVER["PHP_SELF"]."\n";

$err_msg .= "Error Message: $str \n";

$err_msg .= "Query String: ".$this->DB_qstr."\n";

$err_msg .= "MySQL Message: ".mysql_errno()." - ".mysql_error();

echo "
".str_replace("\n", "\n
\n", $err_msg);

$this->Close();

die();

}

}

?>

[Ctrl+A 全部选择 然后拷贝]

php 色色源码,PHP源代码集锦相关推荐

  1. mfc使用cef源代码实现_如何获得微信小游戏跳一跳源码以及源代码组合包括哪些...

    很多小游戏都是由源代码编写而成的,那大家知道源代码组合包括哪些吗?手机游戏源代码怎么使用的呢?还有,如何获得微信小游戏跳一跳源码?下面就由奇瑰网小编带大家来了解一下相关的内容吧. 源代码组合包括哪些 ...

  2. 如何拷贝工程_如何获得微信小游戏跳一跳源码以及源代码组合包括哪些

    很多小游戏都是由源代码编写而成的,那大家知道源代码组合包括哪些吗?手机游戏源代码怎么使用的呢?还有,如何获得微信小游戏跳一跳源码?下面就由奇瑰网小编带大家来了解一下相关的内容吧. 源代码组合包括哪些 ...

  3. c语言小游戏跳一跳代码及注释,如何获得微信小游戏跳一跳源码以及源代码组合包括哪些...

    原标题:如何获得微信小游戏跳一跳源码以及源代码组合包括哪些 很多小游戏都是由源代码编写而成的,那大家知道源代码组合包括哪些吗?手机游戏源代码怎么使用的呢?还有,如何获得微信小游戏跳一跳源码?下面就由奇 ...

  4. C、C++、VC、MFC网页自动注册、登陆、发帖、留言 QQ注册、QQ申请器源码、源代码

    查看文章   [转]C.C++.VC.MFC网页自动注册.登陆.发帖.留言 QQ注册.QQ申请器源码.源代码 2012-01-11 10:58 转载自 qq316293804 最终编辑 qq31629 ...

  5. C#工业触摸屏上位机源码 纯源代码 替代传统plc搭载的触摸屏

    C#工业触摸屏上位机源码 0, 纯源代码. 1, 替代传统plc搭载的触摸屏. 2, 工控屏幕一体机直接和plc通信. 3, 功能强大,多级页签. 4, 可以自由设定串口或以太网通信. 5, 主页. ...

  6. 新闻管理系统源码java_小虫新闻管理系统 .rar - WEB源码|JSP源码/Java|源代码 - 源码中国...

    压缩包 : 小虫新闻管理系统 .rar 列表 downcode.com downcode.com\xwgl downcode.com\xwgl\classes downcode.com\xwgl\cl ...

  7. Android 源码编译问题集锦

    error:Must specify LOCAL_SDK_VERSION or LOCAL_PRIVATE_PLATFORM_APIS 参考 : About LOCAL_PRIVATE_PLATFOR ...

  8. 拍卖系统源码 java,基于B2C的网上拍卖系统_秒杀与竞价 - WEB源码|JSP源码/Java|源代码 - 源码中国...

    文件名大小更新时间 a014基于B2C的网上拍卖系统_秒杀与竞价02019-08-15 a014基于B2C的网上拍卖系统_秒杀与竞价\截图02020-05-29 a014基于B2C的网上拍卖系统_秒杀 ...

  9. 教务管理系统java源代码,教务管理系统 - WEB源码|JSP源码/Java|源代码 - 源码中国...

    教务管理系统\E-R图.doc 教务管理系统\UML图.doc 教务管理系统\代码注释\login\11.jpg 教务管理系统\代码注释\login\LoginFrame.java 教务管理系统\代码 ...

最新文章

  1. 我了解到的新知识之——电热水器用电安全
  2. jquery字体颜色_基于jquery实现的web版excel
  3. linux 系统相关服务解释
  4. 2017 Android 面试题 [ 基础与细节 ]
  5. Openlayers中使用animate实现车辆定位导航效果(以当前车辆为中心移动)
  6. rabbitmq在web管理界面登录失败login fail
  7. 从零开始写javaweb框架 pdf_大学写的一个 Java Web 框架
  8. 台式电脑主板插线步骤图_风味台式烤肠#夏天夜宵High起来!#
  9. 机器学习-算法背后的理论与优化(part1)--从线性回归到逻辑回归
  10. bootstrap模态框
  11. 如何开发高度可定制的产品
  12. 想和人脑一样智能? IBM 的芯片级模仿才是关键
  13. BZOJ1027 [JSOI2007]合金 【计算几何 + floyd】
  14. 大数据工作由哪几部分组成
  15. mysqli.php,PHP: MySQLi - Manual
  16. 有效缓解眼睛疲劳的小方法网站设置404页面有什么作用
  17. 解决vscode的任务栏白色图标的问题
  18. LF-YOLO: A Lighter and Faster YOLO for Weld Defect Detection of X-ray Image
  19. 如何设计一个C++的类?
  20. 碉堡了!最大 18 禁网站用 AI 和 ML 来做视频分类加标签

热门文章

  1. 论文发表时的第一作者和通讯作者哪个含金量比较高
  2. python pandas 讲解ppt_Python中pandas的分析——包括代码实践,相关,解析,含,实战
  3. Android检测App的内存占用和泄漏
  4. 最优化理论极简入门(第二部分):拉格朗日对偶问题
  5. conda配置清华源 国内源
  6. 1131. Subway Map (30)-PAT甲级真题 (DFS or 堆优化dij or SPFA)
  7. 【关于游戏中多人交互业务无回调写法的2种方案】1.xdb 2.world服+只读redis+队列
  8. 刘芳计算机学院,刘芳(计算机科学学院)老师 - 四川师范大学 - 院校大全
  9. 上海人才引进居住证转户口的经验(收藏)
  10. Echarts legend属性使用