高级材料
Insert 和 Update
假设现在你要把下面的数据插入到数据库中.
ID = 3
TheDate=mktime(0,0,0,8,31,2001) /* 31st August 2001 */
Note= sugar why don't we call it off
当你使用另外一个数据库的时候,你的插入操作可能不会成功。
第一个问题是每个数据库都有不同的默认日期格式。MySQL默认格式是YYYY-MM-DD ,
然而其它数据库有不同的默认格式。ADODB有一个DBDate()的函数,它能将日期转
换成正确的格式。
接下来的一个问题是Note字段值里的don't 应该作为引文。在MySQL中,使用
don\'t 来解决这个问题,但在一些其它的数据库中(Sybase, Access, Microsoft
SQL Server)使用don''t 。qstr()解决了这个问题。
那么我们怎么使用这个函数呢? 像下面这样:
$sql = "INSERT INTO table (id, thedate,note) values (" . $ID . ',' . $db->DBDate($TheDate) .',' . $db->qstr($Note).")";$db->Execute($sql);ADODB 也支持 $connection->Affected_Rows() (返回上次update或delete操作影响的
行数) 和 $recordset->Insert_ID() (返回insert声明生成的上一个自增编号)。但要
说明的是不是所有的数据库都支持这两个函数。
MetaTypes
你可以找到更多关于你调用recordset的方法FetchField($fieldoffset)所选择的每个
字段(我同时使用字段和列这两个词)的信息。它将返回一个有三个属性(名称,类
型和最大长度)的对象。
例如:$recordset = $conn->Execute("select adate from table");
$f0 = $recordset->FetchField(0);那么 $f0->name 的值将被设为 'adata', $f0->type 的值将被设为 'date'. 如果
max_length 未知,它被设为-1。
处理不同类型的数据库的一个问题是每个数据库常常用不同的名字来调用相同的类型。
例如timestamp 类型在某一个数据库中叫做datetime 类型,而在另一个是叫做time
类型。 因此 ADODB 有个专门的 MetaType($type, $max_length) 函数对下面的类型
进行标准化:
C: character 和 varchar 类型
X: text 或者 long character (例如.多于255 字节宽度).
B: blob 或者 binary 图像
D: date
T: timestamp
L: logical (boolean)
I: integer
N: numeric (float, double, money)
在上面的例子中,
$recordset = $conn->Execute("select adate from table");
$f0 = $recordset->FetchField(0);
$type = $recordset->MetaType($f0->type, $f0->max_length);
print $type; /* 应该显示 'D' */
Select Limit 和 Top 支持
ADODB 有一个叫$connection->SelectLimit($sql,$nrows,$offset)的函数,它允许你
获得一个记录集(recordset)的子集。它会在Microsoft产品上使用本地的SELECT TOP,
在PostgreSQL和MySQL上使用SELECT ... LIMIT,并在不支持这项功能的数据库上模拟
这个功能。
缓存支持
ADODB 允许你在你的文件系统上缓存记录集结果,只需用$connection->CacheExecute($secs2cache,$sql)
和$connection->CacheSelectLimit($secs2cache,$sql,$nrows,$offset)在指定的超时
时间段后重新向数据库服务器发出查询。
PHP4 Session 处理接口支持
ADODB 也支持PHP4 session 处理接口. 你可以使用ADODB在一个数据库中存储你的
session变量。要获得更多下信息,访问http://php.weblogs.com/adodb-sessions
鼓励作为商业用途
如果你正计划编写你要转售的商业PHP软件产品,你应该考虑ADODB。ADODB使用GPL发
布。这意味这你也可以在商业软件中合法的使用它,同时保持你的代码所有权。十分
鼓励ADODB作为商业用途!因为上述的原因我们内部也正在使用它。
结束语
作为你能耐心的看完这篇文章的答谢,下面是let's call the whole thing off 的

ACID attributes include atomicity, consistency, isolation and durability, and are the cornerstone of database design. 1. Atomicity ensures that the transaction is either completely successful or completely failed. 2. Consistency ensures that the database remains consistent before and after a transaction. 3. Isolation ensures that transactions do not interfere with each other. 4. Persistence ensures that data is permanently saved after transaction submission.

MySQL is not only a database management system (DBMS) but also closely related to programming languages. 1) As a DBMS, MySQL is used to store, organize and retrieve data, and optimizing indexes can improve query performance. 2) Combining SQL with programming languages, embedded in Python, using ORM tools such as SQLAlchemy can simplify operations. 3) Performance optimization includes indexing, querying, caching, library and table division and transaction management.

MySQL uses SQL commands to manage data. 1. Basic commands include SELECT, INSERT, UPDATE and DELETE. 2. Advanced usage involves JOIN, subquery and aggregate functions. 3. Common errors include syntax, logic and performance issues. 4. Optimization tips include using indexes, avoiding SELECT* and using LIMIT.

MySQL is an efficient relational database management system suitable for storing and managing data. Its advantages include high-performance queries, flexible transaction processing and rich data types. In practical applications, MySQL is often used in e-commerce platforms, social networks and content management systems, but attention should be paid to performance optimization, data security and scalability.

The relationship between SQL and MySQL is the relationship between standard languages and specific implementations. 1.SQL is a standard language used to manage and operate relational databases, allowing data addition, deletion, modification and query. 2.MySQL is a specific database management system that uses SQL as its operating language and provides efficient data storage and management.

InnoDB uses redologs and undologs to ensure data consistency and reliability. 1.redologs record data page modification to ensure crash recovery and transaction persistence. 2.undologs records the original data value and supports transaction rollback and MVCC.

Key metrics for EXPLAIN commands include type, key, rows, and Extra. 1) The type reflects the access type of the query. The higher the value, the higher the efficiency, such as const is better than ALL. 2) The key displays the index used, and NULL indicates no index. 3) rows estimates the number of scanned rows, affecting query performance. 4) Extra provides additional information, such as Usingfilesort prompts that it needs to be optimized.

Usingtemporary indicates that the need to create temporary tables in MySQL queries, which are commonly found in ORDERBY using DISTINCT, GROUPBY, or non-indexed columns. You can avoid the occurrence of indexes and rewrite queries and improve query performance. Specifically, when Usingtemporary appears in EXPLAIN output, it means that MySQL needs to create temporary tables to handle queries. This usually occurs when: 1) deduplication or grouping when using DISTINCT or GROUPBY; 2) sort when ORDERBY contains non-index columns; 3) use complex subquery or join operations. Optimization methods include: 1) ORDERBY and GROUPB


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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Atom editor mac version download
The most popular open source editor

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

Dreamweaver Mac version
Visual web development tools

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