指南从MySQL转向ADODB的方法(1)_MySQL
高级材料
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 的

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

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



Setting font size has become an important personalization requirement as mobile phones become an important tool in people's daily lives. In order to meet the needs of different users, this article will introduce how to improve the mobile phone use experience and adjust the font size of the mobile phone through simple operations. Why do you need to adjust the font size of your mobile phone - Adjusting the font size can make the text clearer and easier to read - Suitable for the reading needs of users of different ages - Convenient for users with poor vision to use the font size setting function of the mobile phone system - How to enter the system settings interface - In Find and enter the "Display" option in the settings interface - find the "Font Size" option and adjust it. Adjust the font size with a third-party application - download and install an application that supports font size adjustment - open the application and enter the relevant settings interface - according to the individual

Mobile games have become an integral part of people's lives with the development of technology. It has attracted the attention of many players with its cute dragon egg image and interesting hatching process, and one of the games that has attracted much attention is the mobile version of Dragon Egg. To help players better cultivate and grow their own dragons in the game, this article will introduce to you how to hatch dragon eggs in the mobile version. 1. Choose the appropriate type of dragon egg. Players need to carefully choose the type of dragon egg that they like and suit themselves, based on the different types of dragon egg attributes and abilities provided in the game. 2. Upgrade the level of the incubation machine. Players need to improve the level of the incubation machine by completing tasks and collecting props. The level of the incubation machine determines the hatching speed and hatching success rate. 3. Collect the resources required for hatching. Players need to be in the game

Mobile phone film has become one of the indispensable accessories with the popularity of smartphones. To extend its service life, choose a suitable mobile phone film to protect the mobile phone screen. To help readers choose the most suitable mobile phone film for themselves, this article will introduce several key points and techniques for purchasing mobile phone film. Understand the materials and types of mobile phone films: PET film, TPU, etc. Mobile phone films are made of a variety of materials, including tempered glass. PET film is relatively soft, tempered glass film has good scratch resistance, and TPU has good shock-proof performance. It can be decided based on personal preference and needs when choosing. Consider the degree of screen protection. Different types of mobile phone films have different degrees of screen protection. PET film mainly plays an anti-scratch role, while tempered glass film has better drop resistance. You can choose to have better

1. The SUM function is used to sum the numbers in a column or a group of cells, for example: =SUM(A1:J10). 2. The AVERAGE function is used to calculate the average of the numbers in a column or a group of cells, for example: =AVERAGE(A1:A10). 3. COUNT function, used to count the number of numbers or text in a column or a group of cells, for example: =COUNT(A1:A10) 4. IF function, used to make logical judgments based on specified conditions and return the corresponding result.

Apple's latest releases of iOS18, iPadOS18 and macOS Sequoia systems have added an important feature to the Photos application, designed to help users easily recover photos and videos lost or damaged due to various reasons. The new feature introduces an album called "Recovered" in the Tools section of the Photos app that will automatically appear when a user has pictures or videos on their device that are not part of their photo library. The emergence of the "Recovered" album provides a solution for photos and videos lost due to database corruption, the camera application not saving to the photo library correctly, or a third-party application managing the photo library. Users only need a few simple steps

To handle database connection errors in PHP, you can use the following steps: Use mysqli_connect_errno() to obtain the error code. Use mysqli_connect_error() to get the error message. By capturing and logging these error messages, database connection issues can be easily identified and resolved, ensuring the smooth running of your application.

How to use MySQLi to establish a database connection in PHP: Include MySQLi extension (require_once) Create connection function (functionconnect_to_db) Call connection function ($conn=connect_to_db()) Execute query ($result=$conn->query()) Close connection ( $conn->close())

Through the Go standard library database/sql package, you can connect to remote databases such as MySQL, PostgreSQL or SQLite: create a connection string containing database connection information. Use the sql.Open() function to open a database connection. Perform database operations such as SQL queries and insert operations. Use defer to close the database connection to release resources.
