A PHP Error was encountered

Severity: 8192

Message: Methods with the same name as their class will not be constructors in a future version of PHP; Waterfall_Cache has a deprecated constructor

Filename: _common/waterfall_cache.php

Line Number: 47

A PHP Error was encountered

Severity: 8192

Message: Methods with the same name as their class will not be constructors in a future version of PHP; Cache_System has a deprecated constructor

Filename: _common/waterfall_cache.php

Line Number: 194

A PHP Error was encountered

Severity: 8192

Message: Methods with the same name as their class will not be constructors in a future version of PHP; Memcache_Cache_System has a deprecated constructor

Filename: _common/waterfall_cache.php

Line Number: 275

A PHP Error was encountered

Severity: 8192

Message: Methods with the same name as their class will not be constructors in a future version of PHP; Filesystem_Cache_System has a deprecated constructor

Filename: _common/waterfall_cache.php

Line Number: 440

A PHP Error was encountered

Severity: 8192

Message: Methods with the same name as their class will not be constructors in a future version of PHP; APC_Cache_System has a deprecated constructor

Filename: _common/waterfall_cache.php

Line Number: 628

Querying a Database

Querying a Database

By ServerWatch Staff (Send Email)
Posted May 7, 1999


Ian Stallings
I think this has been covered about a godzillion times but I want to show ASP newbies a clear and easy method to pull data from a database and place it in a webpage.

I think this has been covered about a godzillion times but I want to show ASP newbies a clear and easy method to pull data from a database and place it in a webpage.

There are a few objects you can use to get the data from a database, but I prefer the connection object because it takes about 3 lines of code to use a SQL statement.

(Before writing the script, make sure you have a DSN to the DB setup correctly.)

First thing we do is open an active connection to the DB using the connection object like so:

Set oConn = Server.CreateObject("ADODB.Connection")
oConn.Open "DSN=Web;UID=username;PWD=password"

We can then build the SQL statement using:

sql = "SELECT UserName FROM Accounts Where UserName='madcow'"

We then set the RS object using this line of code:

Set RS = oConn.Execute(sql)

All done! Now that we have the data, we can place it
in our HTML like this:

<%=RS("username")%>

Keep in mind that this is a very simple example and can be expanded on greatly. If you have any comments or questions feel free to drop me a line.

Page 1 of 1


Comment and Contribute

Your name/nickname

Your email

(Maximum characters: 1200). You have characters left.


 

 


Thanks for your registration, follow us on our social networks to keep up-to-date