php database backup and restore
1. mydb.php <span style="color: #008000;">//</span><span style="color: #008000;">DB类</span> 2. backup.php <span style="color: #008000;">//</span><span style="color: #008000;">备份脚本</span> 3. restore.php <span style="color: #008000;">//</span><span style="color: #008000;">还原脚本</span> <span style="color: #000000;"> mydb</span>.<span style="color: #000000;">php </span> <span style="color: #0000ff;">class</span><span style="color: #000000;"> db{ </span><span style="color: #0000ff;">var</span> <span style="color: #800080;">$linkid</span><span style="color: #000000;">; </span><span style="color: #0000ff;">var</span> <span style="color: #800080;">$sqlid</span><span style="color: #000000;">; </span><span style="color: #0000ff;">var</span> <span style="color: #800080;">$record</span><span style="color: #000000;">; </span><span style="color: #0000ff;">function</span> db(<span style="color: #800080;">$host</span>="",<span style="color: #800080;">$username</span>="",<span style="color: #800080;">$password</span>="",<span style="color: #800080;">$database</span>=""<span style="color: #000000;">) { </span><span style="color: #0000ff;">if</span>(!<span style="color: #800080;">$this</span>->linkid) @<span style="color: #800080;">$this</span>->linkid = <span style="color: #008080;">mysql_connect</span>(<span style="color: #800080;">$host</span>, <span style="color: #800080;">$username</span>, <span style="color: #800080;">$password</span>) or <span style="color: #0000ff;">die</span>("连接服务器失败."<span style="color: #000000;">); @</span><span style="color: #008080;">mysql_select_db</span>(<span style="color: #800080;">$database</span>,<span style="color: #800080;">$this</span>->linkid) or <span style="color: #0000ff;">die</span>("无法打开数据库"<span style="color: #000000;">); </span><span style="color: #0000ff;">return</span> <span style="color: #800080;">$this</span>-><span style="color: #000000;">linkid;} </span><span style="color: #0000ff;">function</span> query(<span style="color: #800080;">$sql</span><span style="color: #000000;">) {</span><span style="color: #0000ff;">if</span>(<span style="color: #800080;">$this</span>->sqlid=<span style="color: #008080;">mysql_query</span>(<span style="color: #800080;">$sql</span>,<span style="color: #800080;">$this</span>->linkid)) <span style="color: #0000ff;">return</span> <span style="color: #800080;">$this</span>-><span style="color: #000000;">sqlid; </span><span style="color: #0000ff;">else</span><span style="color: #000000;"> { </span><span style="color: #800080;">$this</span>->err_report(<span style="color: #800080;">$sql</span>,<span style="color: #008080;">mysql_error</span><span style="color: #000000;">); </span><span style="color: #0000ff;">return</span> <span style="color: #0000ff;">false</span><span style="color: #000000;">;} } </span><span style="color: #0000ff;">function</span> nr(<span style="color: #800080;">$sql_id</span>=""<span style="color: #000000;">) {</span><span style="color: #0000ff;">if</span>(!<span style="color: #800080;">$sql_id</span>) <span style="color: #800080;">$sql_id</span>=<span style="color: #800080;">$this</span>-><span style="color: #000000;">sqlid; </span><span style="color: #0000ff;">return</span> <span style="color: #008080;">mysql_num_rows</span>(<span style="color: #800080;">$sql_id</span><span style="color: #000000;">);} </span><span style="color: #0000ff;">function</span> nf(<span style="color: #800080;">$sql_id</span>=""<span style="color: #000000;">) {</span><span style="color: #0000ff;">if</span>(!<span style="color: #800080;">$sql_id</span>) <span style="color: #800080;">$sql_id</span>=<span style="color: #800080;">$this</span>-><span style="color: #000000;">sqlid; </span><span style="color: #0000ff;">return</span> <span style="color: #008080;">mysql_num_fields</span>(<span style="color: #800080;">$sql_id</span><span style="color: #000000;">);} </span><span style="color: #0000ff;">function</span> nextrecord(<span style="color: #800080;">$sql_id</span>=""<span style="color: #000000;">) {</span><span style="color: #0000ff;">if</span>(!<span style="color: #800080;">$sql_id</span>) <span style="color: #800080;">$sql_id</span>=<span style="color: #800080;">$this</span>-><span style="color: #000000;">sqlid; </span><span style="color: #0000ff;">if</span>(<span style="color: #800080;">$this</span>->record=<span style="color: #008080;">mysql_fetch_array</span>(<span style="color: #800080;">$sql_id</span>)) <span style="color: #0000ff;">return</span> <span style="color: #800080;">$this</span>-><span style="color: #000000;">record; </span><span style="color: #0000ff;">else</span> <span style="color: #0000ff;">return</span> <span style="color: #0000ff;">false</span><span style="color: #000000;">; } </span><span style="color: #0000ff;">function</span> f(<span style="color: #800080;">$name</span><span style="color: #000000;">) { </span><span style="color: #0000ff;">if</span>(<span style="color: #800080;">$this</span>->record[<span style="color: #800080;">$name</span>]) <span style="color: #0000ff;">return</span> <span style="color: #800080;">$this</span>->record[<span style="color: #800080;">$name</span><span style="color: #000000;">]; </span><span style="color: #0000ff;">else</span> <span style="color: #0000ff;">return</span> <span style="color: #0000ff;">false</span><span style="color: #000000;">; } </span><span style="color: #0000ff;">function</span> close() {<span style="color: #008080;">mysql_close</span>(<span style="color: #800080;">$this</span>-><span style="color: #000000;">linkid);} </span><span style="color: #0000ff;">function</span> lock(<span style="color: #800080;">$tblname</span>,<span style="color: #800080;">$op</span>="WRITE"<span style="color: #000000;">) {</span><span style="color: #0000ff;">if</span>(<span style="color: #008080;">mysql_query</span>("lock tables ".<span style="color: #800080;">$tblname</span>." ".<span style="color: #800080;">$op</span>)) <span style="color: #0000ff;">return</span> <span style="color: #0000ff;">true</span>; <span style="color: #0000ff;">else</span> <span style="color: #0000ff;">return</span> <span style="color: #0000ff;">false</span><span style="color: #000000;">;} </span><span style="color: #0000ff;">function</span><span style="color: #000000;"> unlock() {</span><span style="color: #0000ff;">if</span>(<span style="color: #008080;">mysql_query</span>("unlock tables")) <span style="color: #0000ff;">return</span> <span style="color: #0000ff;">true</span>; <span style="color: #0000ff;">else</span> <span style="color: #0000ff;">return</span> <span style="color: #0000ff;">false</span><span style="color: #000000;">;} </span><span style="color: #0000ff;">function</span><span style="color: #000000;"> ar() { </span><span style="color: #0000ff;">return</span> @<span style="color: #008080;">mysql_affected_rows</span>(<span style="color: #800080;">$this</span>-><span style="color: #000000;">linkid); } </span><span style="color: #0000ff;">function</span><span style="color: #000000;"> i_id() { </span><span style="color: #0000ff;">return</span> <span style="color: #008080;">mysql_insert_id</span><span style="color: #000000;">(); } </span><span style="color: #0000ff;">function</span> err_report(<span style="color: #800080;">$sql</span>,<span style="color: #800080;">$err</span><span style="color: #000000;">) { </span><span style="color: #0000ff;">echo</span> "Mysql查询错误<br>"<span style="color: #000000;">; </span><span style="color: #0000ff;">echo</span> "查询语句:".<span style="color: #800080;">$sql</span>."<br>"<span style="color: #000000;">; </span><span style="color: #0000ff;">echo</span> "错误信息:".<span style="color: #800080;">$err</span><span style="color: #000000;">; } </span><span style="color: #008000;">/*</span><span style="color: #008000;">***************************************类结束**************************</span><span style="color: #008000;">*/</span><span style="color: #000000;"> }</span>?><span style="color: #000000;"> backup</span>.<span style="color: #000000;">php </span>
<span style="color: #0000ff;">error_reporting(E_ALL & ~ E_NOTICE);</span>
<span style="color: #0000ff;">global</span> <span style="color: #800080;">$mysqlhost</span>, <span style="color: #800080;">$mysqluser</span>, <span style="color: #800080;">$mysqlpwd</span>, <span style="color: #800080;">$mysqldb</span><span style="color: #000000;">; </span><span style="color: #800080;">$mysqlhost</span>="localhost"; <span style="color: #008000;">//</span><span style="color: #008000;">host name</span> <span style="color: #800080;">$mysqluser</span>="root"; <span style="color: #008000;">//</span><span style="color: #008000;">login name</span> <span style="color: #800080;">$mysqlpwd</span>=""; <span style="color: #008000;">//</span><span style="color: #008000;">password</span> <span style="color: #800080;">$mysqldb</span>=""; <span style="color: #008000;">//</span><span style="color: #008000;">name of database</span> <span style="color: #0000ff;">include</span>("mydb.php"<span style="color: #000000;">); </span><span style="color: #800080;">$d</span>=<span style="color: #0000ff;">new</span> db(<span style="color: #800080;">$mysqlhost</span>,<span style="color: #800080;">$mysqluser</span>,<span style="color: #800080;">$mysqlpwd</span>,<span style="color: #800080;">$mysqldb</span><span style="color: #000000;">); </span><span style="color: #008000;">/*</span><span style="color: #008000;">--------------界面--------------</span><span style="color: #008000;">*/</span><span style="color: #0000ff;">if</span>(!<span style="color: #800080;">$_POST</span>['act']){<span style="color: #008000;">/*</span><span style="color: #008000;">----------------------</span><span style="color: #008000;">*/</span> <span style="color: #800080;">$msgs</span>[]="服务器备份目录为backup"<span style="color: #000000;">; </span><span style="color: #800080;">$msgs</span>[]="对于较大的数据表,强烈建议使用分卷备份"<span style="color: #000000;">; </span><span style="color: #800080;">$msgs</span>[]="只有选择备份到服务器,才能使用分卷备份功能"<span style="color: #000000;">; show_msg(</span><span style="color: #800080;">$msgs</span><span style="color: #000000;">); </span>?>
".$title." |
|
error_reporting(E_ALL & ~ E_NOTICE);
<span style="color: #008080;">session_start</span><span style="color: #000000;">(); </span><span style="color: #0000ff;">global</span> <span style="color: #800080;">$mysqlhost</span>, <span style="color: #800080;">$mysqluser</span>, <span style="color: #800080;">$mysqlpwd</span>, <span style="color: #800080;">$mysqldb</span><span style="color: #000000;">; </span><span style="color: #800080;">$mysqlhost</span>="localhost"; <span style="color: #008000;">//</span><span style="color: #008000;">host name</span> <span style="color: #800080;">$mysqluser</span>="root"; <span style="color: #008000;">//</span><span style="color: #008000;">login name</span> <span style="color: #800080;">$mysqlpwd</span>=""; <span style="color: #008000;">//</span><span style="color: #008000;">password</span> <span style="color: #800080;">$mysqldb</span>=""; <span style="color: #008000;">//</span><span style="color: #008000;">name of database</span> <span style="color: #0000ff;">include</span>("mydb.php"<span style="color: #000000;">); </span><span style="color: #800080;">$d</span>=<span style="color: #0000ff;">new</span> db(<span style="color: #800080;">$mysqlhost</span>,<span style="color: #800080;">$mysqluser</span>,<span style="color: #800080;">$mysqlpwd</span>,<span style="color: #800080;">$mysqldb</span><span style="color: #000000;">); </span><span style="color: #008000;">/*</span><span style="color: #008000;">*****界面</span><span style="color: #008000;">*/</span><span style="color: #0000ff;">if</span>(!<span style="color: #800080;">$_POST</span>['act']&&!<span style="color: #800080;">$_SESSION</span>['data_file']){<span style="color: #008000;">/*</span><span style="color: #008000;">********************</span><span style="color: #008000;">*/</span> <span style="color: #800080;">$msgs</span>[]="本功能在恢复备份数据的同时,将全部覆盖原有数据,请确定是否需要恢复,以免造成数据损失"<span style="color: #000000;">; </span><span style="color: #800080;">$msgs</span>[]="数据恢复功能只能恢复由dShop导出的数据文件,其他软件导出格式可能无法识别"<span style="color: #000000;">; </span><span style="color: #800080;">$msgs</span>[]="从本地恢复数据需要服务器支持文件上传并保证数据尺寸小于允许上传的上限,否则只能使用从服务器恢复"<span style="color: #000000;">; </span><span style="color: #800080;">$msgs</span>[]="如果您使用了分卷备份,只需手工导入文件卷1,其他数据文件会由系统自动导入"<span style="color: #000000;">; show_msg(</span><span style="color: #800080;">$msgs</span><span style="color: #000000;">); </span>?>
".$title." |
|

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

What are the magic methods of PHP? PHP's magic methods include: 1.\_\_construct, used to initialize objects; 2.\_\_destruct, used to clean up resources; 3.\_\_call, handle non-existent method calls; 4.\_\_get, implement dynamic attribute access; 5.\_\_set, implement dynamic attribute settings. These methods are automatically called in certain situations, improving code flexibility and efficiency.

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

JavaScript is the cornerstone of modern web development, and its main functions include event-driven programming, dynamic content generation and asynchronous programming. 1) Event-driven programming allows web pages to change dynamically according to user operations. 2) Dynamic content generation allows page content to be adjusted according to conditions. 3) Asynchronous programming ensures that the user interface is not blocked. JavaScript is widely used in web interaction, single-page application and server-side development, greatly improving the flexibility of user experience and cross-platform development.

In PHP, you can effectively prevent CSRF attacks by using unpredictable tokens. Specific methods include: 1. Generate and embed CSRF tokens in the form; 2. Verify the validity of the token when processing the request.
