
February 23rd, 2004, 12:57 PM
|
 |
Contributing User
|
|
Join Date: Feb 2004
Location: NewHampshire, USA
Posts: 416
  
Time spent in forums: 4 Days 19 h 30 m 44 sec
Reputation Power: 9
|
|
|
DB connection methods.. Which is better?
Hi,
I have seen two methods for connecting to databases and was just wondering which is better and for what situations?
I've been using method 1 so far, but I haven't seen many other people using it. It seems more people use method 2, but I can't find a good resources on how to use it correctly.
Any help would be appreciated.
Method 1:
PHP Code:
<%
Dim getBooks
Dim BookImg, BookName, BookDesc
Set getBooks = Server.CreateObject("ADODB.Recordset")
getBooks.ActiveConnection = MM_database_STRING ' MM_database_STRING from include file.
getBooks.Source = "SELECT * FROM Books"
getBooks.CursorType = 0
getBooks.CursorLocation = 2
getBooks.LockType = 1
getBooks.Open()
While (NOT getBooks.EOF AND NOT getBooks.BOF)
BookImg = getBooks.fields.item("Book_IMG").value
BookName = getBooks.fields.item("Book_NAME").value
BookDesc = getBooks.fields.item("Book_DESC").value
%>
<tr>
<td> </td>
<td align="center"><img src="<%=BookImg%>" alt="<%=BookName%>"></td>
<td> </td>
<td><b><%=BookName%></b> - <%=BookDesc%></td>
</tr>
<%
getBooks.movenext()
Wend
getBooks.Close()
Set getBooks = Nothing
%>
Method 2:
PHP Code:
<%
Dim adOpenForwardOnly, adLockReadOnly, adCmdTable
adOpenForwardOnly = 0
adLockReadOnly = 1
adCmdTable = 2
Dim objConn, objRS
Set objConn = Server.CreateObject("ADODB.Connection")
Set objRS = Server.CreateObject("ADODB.Recordset")
'Now we use this selection to open the connection in the appropriate way
objConn.Open "Provider=SQLOLEDB;Persist Security Info=False;" & _
"User ID=sa;Initial Catalog=Movie;" & _
"Initial File Name=C:\MSSQL7\Data\Movie2000.mdf"
objRS.Open "Movies", objConn, adOpenForwardOnly, adLockReadOnly, adCmdTable
While Not objRS.EOF
Response.Write objRS("Title") & "<BR>"
objRS.MoveNext
Wend
objRS.Close
objConn.Close
Set objRS = Nothing
Set objConn = Nothing
%>
Thanks.
__________________
Mark Pearce
|