Linking to the database is the first step in our program development. Let's take a look at the tips for using database paths in Dreamweaver.
1. It is not recommended to use Server.Mappath (database file with relative document path address).
Although it has platform portability, the correctness of the database path cannot be completely guaranteed for files that reference the database at different levels and at different depths.
For example:
1. The database file cnbruce.mdb is located in the folder database (accessible via http)
2. The connection database file conn.asp automatically generated by DW is located in the folder Connections
3. If the connection path is successfully tested in DW, then The address must be entered as Server.Mappath("../database/cnbruce.mdb")
but the file that subsequently references the database connection must be saved in a folder that is the same as the database, that is
:
- database
- cnbruce.
Only the structure ofmdb
- Connections
- conn.asp
- a certain folder
- x1.asp
can be used normally. But this requires that all files in the site that reference the connection database file must be stored in the first-level directory of the site. Obviously this is unreasonable, such as such a structure.
- x2.asp
- database
- cnbruce.mdb
- Connections
- conn.asp
- a certain folder
- a certain subfolder
- x3.asp,
then both x2.asp and x3.asp cannot be displayed normally.
Principle analysis: No matter where conn.asp is placed, no matter what the content of conn.asp is, it ultimately depends on the file location of the file that references conn.asp and the location relationship of the database.
Solution: Determine the current path in conn.asp, and give different link paths according to different level values... This is troublesome for beginners.
2. It is not recommended to use Server.Mappath (database file with relative root directory path).
To use this method, you first need to adjust the IIS default site to the folder where the current DW site is located (XP system), or create a site pointing to the folder ( 2K and other systems).
Anyway, in one sentence, when you enter http://localhost/ , the displayed content is no longer the default IIS homepage, but the default homepage document in the DW site folder you set.
Then after setting up the IIS site
1. The database file cnbruce.mdb is located in the folder database (accessible via http)
2. The connection database file conn.asp automatically generated by DW is located in the folder Connections
3. If the connection is tested in DW If the path is successful, the input address is Server.Mappath("/database/cnbruce.mdb")
/database/cnbruce.mdb This method is relative to the root directory and obtains the database path from a high-level perspective, no matter which level or directory it is under. All site documents can be displayed normally.
But it’s still not recommended! The reason is as follows:
You can modify the IIS site locally, but when it is uploaded to a server or virtual host, trouble begins.
1. If your virtual host service provider's technology is not good enough, when parsing the root directory of your website, it will not point to your site folder, but to the wwwroot folder under the server system disk. So the path must be wrong.
2. If what you need to upload is not the root directory of your site, obviously, there will definitely be a parsing error in the path.
Therefore, it is not recommended! So, what should we do?
3. It is recommended to use Server.Mappath (local absolute physical path database file).
It is very simple. You will always know the location of this database locally. The absolute physical path address is used directly when creating it in DW.
OK, let’s upload. Of course it can't be such a coincidence: the physical path address of the database uploaded to the server is the same as the physical path address of the local database
. So, now you only need to get the physical address of the database file uploaded to the server space on the server.
How to get it?
1. Create a path.asp file with very simple content.
2. This file and the database file cnbruce.mdb are in the same folder and uploaded together in a bundle.
3. View path.asp in the URL address bar, obtain the physical address of cnbruce.mdb on the server, and copy the path.
4. Replace the physical path in the local conn.asp and then upload it. Everything is OK!
Features:
1. Although the platform migration is not very strong, it fully supports file connections in all sites, and that is the migration between local and server.
2. Prevent %5c from indirectly obtaining the database address by exploiting the database.
3. Nowadays, more and more spaces recommend placing database files in non-Web access directories (of course, obtaining the specific path is another method), which requires users to use physical paths.
Therefore, my point of view is:
How to use Dreamweaver MX dynamic website building database path: use the physical address locally, and still use the physical address when uploading to the server.