版权声明:原创作品,允许转载,转载时请务必以超链接形式标明文章原始出版、作者信息和本声明。否则将追究法律责任。http://blog.csdn.net/mayongzhan - 马永占,myz,mayongzhan
其中需要在本地文件夹里建立一个temp文件夹
adodbtest.php
<?
php
require_once
(
'
newadodb.php
'
);
?>
<
html
>
<
head
>
<
metahttp
-
equiv
=
"
Content-Type
"
content
=
"
text/html;charset=gbk
"
/>
<
title
></
title
>
</
head
>
<
body
>
<?
php
/*
*@author马永占
*/
$ADODB_FETCH_MODE
=
ADODB_FETCH_ASSOC;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
$query
=
"
SELECT*FROMlibrary
"
;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
//
$result=$db->Execute($query)ordie($db->ErrorMsg());
$result
=
$db
->
SelectLimit(
$query
,
10
,
1
)or
die
(
$db
->
ErrorMsg());
//
从第一个开始显示10个
while
(
!
$result
->
EOF)
{
echo
$result
->
fields[
'
title
'
]
.
"
-
"
.
$result
->
fields[
'
author
'
]
.
"
<br/>
"
;
$result
->
MoveNext();
}
echo
"
<br/>[
"
.
$result
->
RecordCount()
.
"
rows]<br/></b>
"
;
//
行数
echo
"
<br/>[
"
.
$result
->
FieldCount()
.
"
fields]<br/></b>
"
;
//
字段数
$db
->
Close();
?>
</
body
>
</
html
>
adodbtest2.php
<?
php
require_once
(
'
newadodb.php
'
);
?>
<
html
>
<
head
>
<
metahttp
-
equiv
=
"
Content-Type
"
content
=
"
text/html;charset=gbk
"
/>
<
title
></
title
>
</
head
>
<
body
>
<?
php
/*
*@author马永占
*/
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
$title
=
$db
->
qstr(
"
myz
"
);
$author
=
"
123
"
;
$query
=
"
INSERTINTOlibrary(title,author)VALUES($title,$author)
"
;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
$result
=
$db
->
Execute(
$query
)or
die
(
$db
->
ErrorMsg());
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
if
(
$result
)
{
echo
"
LastinsertedIDis
"
.
$db
->
Insert_ID();
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
$db
->
Close();
?>
</
body
>
</
html
>
adodbtest3.php
<?
php
require_once
(
'
newadodb.php
'
);
?>
<
html
>
<
head
>
<
metahttp
-
equiv
=
"
Content-Type
"
content
=
"
text/html;charset=gbk
"
/>
<
title
></
title
>
</
head
>
<
body
>
<?
php
/*
*@author马永占
*/
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
$title
=
$db
->
qstr(
"
myz
"
);
$author
=
"
123
"
;
$query
=
"
DELETEFROMlibraryWHEREid=4
"
;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
$result
=
$db
->
Execute(
$query
)or
die
(
$db
->
ErrorMsg());
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
if
(
$result
)
{
echo
$db
->
Affected_Rows()
.
"
rowsdeleted
"
;
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
$db
->
Close();
?>
</
body
>
</
html
>
adodbtest4.php
<?
php
/*
*@author马永占
*/
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
require_once
(
"
newadodb.php
"
);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
$query
=
$db
->
Prepare(
"
INSERTINTOlibrary(title,author)VALUES(?,?)
"
);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
$data
=
file
(
"
list.txt
"
);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
foreach
(
$data
as
$l
)
{
$arr
=
explode
(
"
,
"
,
$l
);
$result
=
$db
->
Execute(
$query
,
array
(
$arr
[
0
]
,
$arr
[
1
]))or
die
(
"
Errorinquery:$query.
"
.
$db
->
ErrorMsg());
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
$db
->
Close();
?>
adodbtest5.php
<?
php
/*
*@author马永占
*/
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
require_once
(
"
newadodb.php
"
);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
$db
->
BeginTrans();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
//
firstquery
$query
=
"
INSERTINTOlibrary(title,author)VALUES('TitleA','AuthorB')
"
;
$result
=
$db
->
Execute(
$query
)or
die
(
"
Errorinquery:$query.
"
.
$db
->
ErrorMsg());
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
//
useIDfromfirstqueryinsecondquery
if
(
$result
)
{
$id
=
$db
->
Insert_ID();
$query
=
"
INSERTINTOlibrary(title,author)VALUES($id,'USD39.99')
"
;
$result
=
$db
->
Execute(
$query
)or
die
(
"
Errorinquery:$query.
"
.
$db
->
ErrorMsg());
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
if
(
$result
)
{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
$db
->
CommitTrans();
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
else
{
$db
->
RollbackTrans();
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
$db
->
Close();
?>
adodbtest6.php
<?
php
/*
*@author马永占
*/
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
require_once
(
"
newadodb.php
"
);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
$query
=
"
SELECT*FROMlibrary
"
;
$result
=
$db
->
CacheExecute(
300
,
$query
)or
die
(
$db
->
ErrorMsg());
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
while
(
!
$result
->
EOF)
{
echo
$result
->
fields[
1
]
.
"
-
"
.
$result
->
fields[
2
]
.
"
"
;
$result
->
MoveNext();
}
$db
->
Close();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
?>
adodbtest7.php
<?
php
/*
*@author马永占
*/
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
require_once
(
"
newadodb.php
"
);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
$query
=
"
SELECTtitle,idFROMlibrary
"
;
$result
=
$db
->
Execute(
$query
)or
die
(
"
Errorinquery:$query.
"
.
$db
->
ErrorMsg());
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
print
$result
->
GetMenu(
"
library
"
,
''
,
false
);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
$db
->
Close();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
?>
adodbtest8.php
<?
php
/*
*@author马永占
*/
require_once
(
"
adodb/toexport.inc.php
"
);
require_once
(
"
adodb/tohtml.inc.php
"
);
require_once
(
"
newadodb.php
"
);
$query
=
"
SELECTtitle,idFROMlibrary
"
;
$result
=
$db
->
Execute(
$query
)or
die
(
"
Errorinquery:$query.
"
.
$db
->
ErrorMsg());
//
echors2csv($result,false);
//echors2tab($result,false);
echo
rs2html(
$result
,
false
);
$db
->
Close();
?>
newadodb.php
<?
php
/*
*@author马永占
*/
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
require_once
'
adodb/adodb.inc.php
'
;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
$ADODB_CACHE_DIR
=
'
temp/
'
;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
$mydbtype
=
'
mysql
'
;
$mydbhost
=
'
localhost
'
;
$mydbname
=
'
root
'
;
$mydbpass
=
'
myz
'
;
$mydb
=
'
adodbtest
'
;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
$db
=
NewADOConnection(
$mydbtype
);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
$db
->
Connect(
$mydbhost
,
$mydbname
,
$mydbpass
,
$mydb
)or
die
(
$db
->
ErrorMsg());
?>
list.txt
abc,bcd
sdf,dsfgg
grwetg,dfsdf