The main objective of a database is to collect data entries from visitors and enable to easily sort, retrieve and search data saved in this database. But, you must know how to "manually" create and handle a database before managing it with and ASP or PHP page.
Caution
We will only talk about ASP/Access and PHP/MySQL. So, if you are not familiar with these associations please just do it clicking with MS Access (a class?) or PhpMyAdmin (http://localhost/mysql/ if your Apache server is active!)
You can also use Access database if you do not have MS Access software with ASP (even PHP) by going to this presentation!
Except this installation, the 1st connection to a database is quite often difficult (especially with ASP)... but once we know how to do it, the procedure becomes natural and the connection so practical that it seems difficult, after that, not to use it... As a database is associated to a server (parameters), the procedure must be renewed anytime you change "LocalHost" server... So, we are going to build a new file name "_connexion" to be included in your pages and adapted to each system if required.
Then, take your time in your learning curve, and if you encounter difficulties please write your question if necessary... For other database/language associations, you can browse some links related to the subject!
How does it work?
As for any script, syntax is very important... So, please respect it with diligence to avoid any syntax errors that will be very cumbersome to correct in the future!
First create ma_base.mdb with MSAccess and after:
ma_page.asp
<!-- #include file="_connexion.asp"-->
<% ' Disconnect Conn.close : Set Conn=nothing %>
and for the connection, 2 possibilities:
Method 1: DSN-less
_connexion.asp
<% ' Long path of the database dbPath = Server.MapPath("/rep_depro/ma_base.mdb") ' Creation of the object enabling the connection Set Conn = Server.CreateObject("ADODB.Connection") ' Connection Conn.Open "DRIVER={Microsoft Access Driver (*.mdb)};" _ & " DBQ=" & dbPath %>
Method 2: with DSN
Control panel > ODBC data source > DSN system (sources of data system) > Add > Driver Microsoft Access Driver (*.mdb)
Select database
Name of the source: ma_base
_connexion.asp
<% ' Creation of the object enabling the connection Set Conn = Server.CreateObject("ADODB.Connection") ' Connection Conn.Open "ma_base" %>
The directory where the database is located must be open for editing!
<? // Personal parameters $host = "localhost"; // see ISP $user = "login"; // empty or "root" for local $pass = "password"; // empty in local $bdd = "ma_base"; // name of the DB // connection @mysql_connect($host,$user,$pass) or die("Impossible to connect"); @mysql_select_db("$bdd") or die("Impossible to connect"); ?>
Also: If PHP is configured on port 81 PHPMyAdmin could not work properly... So, modify the variable $cfgPmaAbsoluteUri of the file ../EasyPHP/phpmyadmin/config.inc.php as follow:
/** * Your phpMyAdmin url */ $cfgPmaAbsoluteUri = 'http://127.0.0.1:81/mysql/';
This page does not post anything. Of course, but it enables you to check that the connection happened... If an error message is posted, check any character of your script, and if necessary, write your question...