Designed by Maunakea !
5 en ligne  


 Search


Acheter - Vendre
neuf et occasion

pda, jeux vidéo, graveur, cd vierges, dvd vierges, matériel informatique, pc, ordinateur portable, logiciel, antivirus, annonces gratuites





   

Connection to a database

Connect a database to an ASP|PHP page





artvoila
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

  1. 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!)

  2. You can also use Access database if you do not have MS Access software with ASP (even PHP) by going to this presentation!

  3. 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.

  4. 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!


First create a database "ma_base" with PhpMyAdmin (http://localhost/mysql/) and after:

ma_page.php
<? include("_connexion.php");

// Disconnect
mysql_close(); ?>



and to connect to MySQL:

_connexion.php
<?
// 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...


Or, if everything works well,

go to the next step!


Other links related to this subject

ADO Connexion String Samples
Connection PHP/Access - PHP/SQL Server - ASP/Oracle - ASP/Sybase - ASP/MySQL
PHP/Lotus Notes Forum - Functions
Connection ASP without DSN (Access, Sql Server, Oracle, Sybase ASE)
ASP connected to an Excel spreadsheet - The example of Microsoft - Another example
Convert Access <--> MySQL read also MySQL and ODBC and MSAccess to MySQL

artvoila on 2/18/2004 (8 850 hits)
Didier Téléchargez gratuitement !!!
7 logiciels illimités dont Visual Studio Pro et SQL Server 2005 !
SQL Server 2008 ß !
[gratuit] 11-12-13 février
les MS TechDays 2008 !!!
Au fil des news  
Dreamweaver CS3 + XML + Ajax - Création d'une région détail
Dans cet article, je vais vous montrer comment utiliser la technique région détail, avec Spry
PHP - joli arborescence dynamique
Magazines - Le N°104 de Programmez est disponible
PHP - PhPBB 3.0.0 !!!
[MAJ] Université de Sherbrooke - située dans un beau coin du Québec, l'Estrie...
- Ajout du programme d'imagerie et de médias numérique - Le département de mathématiques et ...
Magazines - Le N°103 de Programmez est disponible
PHP - Calcul jours ouvrables entre dates, gestion fériés
PHP - WampServer 2.0, la nouvelle version de WAMP5 !
SharePoint 2007 et Workflows Designer - Part 2 - Modifions un workflow dans SharePoint 2007
Dans la première partie, nous avons vu comment créer un WorkFlow dans MOSS avec SharePoint ...
Modifier le ruban de Word 2007 avec Open XML -
Open XML est un format de document bureautique flexible : structure basée sur l'Open Packaging ...
La corbeille de SharePoint 2007 - Fonctionnement de la corbeille de SharePoint 2007
Une des nouveautés de SharePoint 2007 est la mise en place de la corbeille pour chaque site. Il est ...
SharePoint 2007 et Workflows Designer - Part 1 - Créer un workflow simple dans SharePoint 2007
L'automatisation de Workflows, ou Flux de travail, résulte d'une volonté d'amélioration de ...
CSS - Dégradé de couleur
Magazines - Le N°102 de Programmez est disponible
Dreamweaver CS3 + Mysql - Formulaire de redirection
Suite au coup de pouce de DB77, je vous propose ce petit script pour améliorer vos pages Internet. ...
[MAJ] Tutoriel AJAX simple - En avant vers le WEB2.0
Mis à jour le 26/10/2007
Magazines - Le Hors-Série .Net de Programmez est disponible
LINQ et vous - Part 2 - Le .NET Framework 3.5 décortiqué !
Ce nouvel article fait suite à mon premier article de cette nouvelle collection « LINQ et vous ». ...
Présentation des KPI dans SharePoint - Présentation des KPI dans SharePoint 2007
Nous verrons au travers de cet article une présentation détaillée de ce qu'est un KPI et dans quel ...
LINQ et vous - Part 1 - Evolutions du .NET Framework - Visual Studio 2008
Voilà plus d'un an que je n'ai plus posté d'articles sur ma communauté préférée. Il était temps ...
Agenda - 21-22 novembre : Le Forum PHP 2007 !
Microsoft - Essayez gratuitement MS Expression Studio !!!
Les Utilisateurs dans SharePoint - La gestion des utilisateurs dans SharePoint
SharePoint dont le coeur est l'outil collaboratif, Windows SharePoint Services. Chaque utilisateur ...
Magazines - Le N°101 de Programmez est disponible
Hebergement - hébergement de forum gratuit - créer un forum.
Revue de presse - Nouvelle mise à jour chez Adobe
PHP - import csv vers bdd avec verification
PHP5 - Csv2array
PHP - Framework PHP5 - PoppyFramework
Le Moteur de Recherche de MOSS 2007 - Installer le moteur de recherche de MOSS 2007
Nous avons vu dans un précédent article comment mettre en place le moteur de recherche dans un site ...
PHP5 - incrementation alphanumerique
Magazines - Le N°100 de Programmez est disponible
Agenda - Adobe vous donne rendez-vous du 4 au 9 septembre..
ABAP leçon 1 : Les variables - Auteur : Jerome Fortias
je me devais de continuer mon travail de vulgarisation à SAP. En parallèle à mon site destiné aux ...
Agenda - Nov 2007 : Les TechEd Developers à Barcelone !
Microsoft - Vista SP1 et XP SP3 pour bientôt !
Le Moteur de Recherche de WSS V3 - Installer le moteur de recherche de WSS V3
Parmi les évolutions de Windows SharePoint Services V3, on trouve le moteur de recherche. Nous ...
PHP - array2xml convertie un array en xml
Revue de presse - Flash Player 9 Update beta
PHP5 - class Timer - ajouter/enlever du temp au time unix
Tutorial : HTML | Scripting | ASP-PHP | ASP.net | SQL Server | XML
Sharepoint | XAML | Pocket | Dreamweaver | VML | Divers
  Scripts : Scripting | ASP-PHP | ASP.net | Divers
  Boutique | Annuaire | Bannières | Météo | Tribune | Partenariats
v3 © Didier 2003   
 
 ASP-magazine Groupes Utilisateurs Microsoft MVP El Roubio DotNet Project CodePPC Wygwam TechNet Codes Sources The Inquirer FR