|
|
 |
 |
Connecting to database through asp and php |
Select
your internet browser for some handy instructions to get the most from
your internet browser.
If you want to connect to the database, please look at the point indicating your scripting language:
- PHP
$dbuser="username"; //your username
$dbpass="password"; //password for the database
$dbname="mydata"; //the name of the database
$chandle = mysql_connect("localhost", $dbuser, $dbpass)
or die("Connection Failure to Database");
echo "Connected to database server "; //if you connect to the database, it shows a message, that you were successful in connecting
mysql_select_db($dbname, $chandle) or die ($dbname . " Database not found." . $dbuser);
echo "Database " . $database . " is selected"; //this text is not necessary
mysql_close($chandle); //this line you should write at the end, when you you do not need any connection to database anymore.
Text after the sign // may be deleted, because it does not have any effect on the code.
- ASP
Dim ServerName ‘put here you server name (address where the database is placed)
Dim DatabaseName ‘put here the database name
Dim Username ‘valid username for the database
Dim Password ‘valid password for the database
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open "Provider=sqloledb;Data Source=ServerName;Initial Catalog=DatebaseName;User Id=Username;Password=Password;"
strSql = "SELECT FieldName FROM TableName"
Set rs = Conn.Execute(strSql)
If rs.eof Then
Response.write("No records returned")
End If
do until rs.eof
Response.write(rs("FieldName") & " ")
rs.movenext
loop
Conn.Close ‘write that whenever you want to close the connection
Set Conn = Nothing
More information about sql you can get by clicking on the provided link: http://dev.mysql.com/doc/.
|