Advanced Materials
Insert and Update
Let's say you want to insert the following data into the database.
ID = 3
TheDate=mktime(0,0,0,8,31,2001) /* 31st August 2001 */
Note= sugar why don't we call it off
When you use another database, your insert operation may not be successful.
The first problem is that each database has a different default date format. The MySQL default format is YYYY-MM-DD, whereas other databases have different default formats. ADODB has a dbdate () function that converts dates to the correct format.
The next problem is that don ' t should be quoted as a citation in the value of the Note field. In MySQL, use don\ ' t to solve this problem, but in some other databases (Sybase, Access, Microsoft SQL Server) use don ' t. Qstr () solves the problem.
So how do we use this function? Like the following:
$sql = "INSERT into table (ID, Thedate,note) VALUES (". $ID. ',' . $db->dbdate ($TheDate). $db->qstr ($Note) ")"; $db->execute ($sql); ADODB also supports $connection->affected_rows () (returns the number of rows affected by the last update or delete operation) and $recordset->insert_id () () ( Returns the last self-increasing number generated by the Insert Declaration. But the explanation is that not all databases support both functions.
Metatypes
You can find more information about each field (I use both fields and columns) that you select for the method Fetchfield ($fieldoffset) that you call the recordset. It returns an object with three attributes (name, type, and maximum length).
For example: $recordset = $conn->execute ("Select adate from table");
$f 0 = $recordset->fetchfield (0), then $f 0->name value will be set to ' Adata ', $f 0->type value will be set to ' date '. If Max_length is unknown, it is set to-1.
One problem with different types of databases is that each database often invokes the same type with a different name. For example, the timestamp type is called a datetime type in one database and the other is called the time type. So ADODB has a special metatype ($type, $max _length) function that standardizes the following types:
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)
In the example above,
$recordset = $conn->Execute("select adate from table");
$f0 = $recordset->FetchField(0);
$type = $recordset->MetaType($f0->type, $f0->max_length);
print $type; /* 应该显示 'D' */
Select Limit and top support
ADODB has a function called $connection->selectlimit ($sql, $nrows, $offset) that allows you to obtain a subset of a Recordset (recordset). It uses a local select top on a Microsoft product, and a select on PostgreSQL and MySQL ... LIMIT, and simulates this feature on a database that does not support this feature.
Caching support
ADODB allows you to cache recordset results on your file system with only $connection->cacheexecute ($secs 2cache, $sql) and $connection->cacheselectlimit ($ Secs2cache, $sql, $nrows, $offset) re-issue the query to the database server after the specified timeout period.
The PHP4 session processing interface supports ADODB also supports PHP4 session processing interfaces. You can use ADODB to store your session variables in a database. For more information, visit http://php.weblogs.com/adodb-sessions to encourage business use
If you are planning to write a commercial PHP software product you want to resell, you should consider ADODB. ADODB is released using the GPL. This means that you can also use it legally in commercial software, while maintaining ownership of your code. Very encouraging ADODB as a commercial use! For the reasons above, we are using it internally as well.