Tuesday, July 28, 2009

How do i connect a webpage to a database during web development?

web development code for dynamic databases

How do i connect a webpage to a database during web development?
In order to connect to a database, you have to use a server side technology like ASP .NET, ColdFusion, PHP, JSP, etc. Strictly HTML and Javascript won't be able to achieve that. So, this is the first step.





The second step is to set up an ODBC connection on the server.





The third step is the syntax. Each server side technology has its own syntax. I am a certified ColdFusion developer. In ColdFusion, the syntax is as follows,


%26lt;cfquery name="search_something" datasource="my_ODBC"%26gt;


SELECT *


FROM My_Table


%26lt;/cfquery%26gt;


In order to do this, you will need to write your own SQL statement. SQL is a database language for you to create queries.





I am a web developer by trade. If you have any questions, please feel free to contact me.
Reply:it's going to depend on what you are using for the database - but in general you will need to create a connection string. This will define what database engine is being used, and the location of the database and the type of connection.





The website below gives some good examples.
Reply:You haven't given us enough information to properly answer. What database are you using (Oracle, Access, Informix, Sybase, MySQL, MS SQL, etc...)? What web server (Apache, IIS, or an application server http server) and application container (JBoss, WebLogic, JRun, IIS, WebSphere, Tomcat, etc...) are you using? Are you looking to script (VBScript, JScript, JavaScript, etc...) this or use a compiled/interpreted language (C#, Java, VB, C, C++)?
Reply:Using PHP and MySQL, you would do something like:





$conn = mysql_connect($dbHost, $dbUser, $dbPass) or die ('Error connecting to mysql');


mysql_select_db($dbName) or die ('Could not select database "'.$dbName.'"');





//Do something with the database here...





mysql_close($conn);








___________________


Hope that helps, Adam


My website: http://www.cygnetgames.co.uk


No comments:

Post a Comment