|
Reviewing the code :
' Our Connection Object
Set con = CreateObject("ADODB.Connection")
con.Open strDB
Set results = con.Execute("select title, description, keywords _
from all_pages where url = '" & strURL & "'")
After populating the three variables title, description and keywords,
we now move forward to add them to the database. We begin by creating Connection object. Then we
open the database. Note as we discussed earlier, 'editme.asp' contains the location of the
database in the variable strDB. So after including 'editme.asp' page in our 'addtodb.asp' page we
can easily use the value of strDB in our script.
We then check the database to see if this given URL has been added to the database before. We do it by selecting title,
description and keywords fields from the 'all_pages' table where URL is the given URL. If the returning recordset is empty
then it shows that the URL has not been added to the database. But if the returning recordset is not empty then it means
that URL has been added to the database before.
' If the returning recordset is empty then add the URL with accompanying
' info to the database
If results.EOF Then
con.Execute("insert into all_pages (title, description, keywords, url, _
mydate) values ('" & title & "', '" & description & "', '" & _
keywords & "', '" & strURL & "', '" & date & "')")
Set rs = con.Execute("select count(url) as total_count from all_pages")
cnt = rs("total_count")
Set rs = Nothing
Response.Write "<b>New account successfully created for " & strURL & " _
.</b>" & vbcrlf
Response.Write "<br>"
Response.Write "Total Pages Indexed : " & cnt & vbcrlf
If the URL has not been added to the database before, we then add it along with the retrieved title,
description and keywords values and current date.
Else
' But if the returning recordset is not empty i.e. we have already added _
' title, desc, keywords etc into it then update that information with the _
' new one.
con.Execute("update all_pages set title = '" & title & "', description = _
'" & description & "', keywords = '" & keywords & "', mydate = #" _
& date & "# where url = '" & strURL & "'")
Response.Write "<b>Account updated successfully.</b>"
End If
But if the URL has been added to the database earlier then instead of entering another row for this URL, update
the earlier values in their respective fields. Note this is useful if you update a page and then also want to update
it's info in the search engine database.
' Done. Now release Objects
Set results = Nothing
con.Close
Set con = Nothing
%>
</body></html>
Now we are done, so lets remove the objects from the server memory.
Summarizing, we retrieved the contents of given page in the variable strFileContents. Then
we searched for the title, description and keywords meta tags and
populated our title, description and keywords ASP variables with their
values. In the end we added or updated their values in the database.
On the next page we explore 'addtodb_fso.asp' page which indexes the pages using FileSystemObject in a manner similar
to 'addtodb.asp' page, but with a slight difference.
Next ->
|