How to connect the database to our web page? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 6

How to connect the database to our web page?

I want to give connectivity of data base to my web page. What is the way to give connection between these

23rd Apr 2017, 3:30 PM
Aniket Dhanak
Aniket Dhanak - avatar
3 Answers
+ 8
there are some steps to do that :- first > Prepare your database user account details. (I'm assuming you already know that).. 2> Connect to your database:- You will need to use a server side scripts to connect to your database. da following example code shows how to make a database connection to a MySQL system within a PHP script: <?php mysql_connect("database_host", "username", "password"); ?> You will need to alter the host address, username and password to reflect your own account. 3 > query your data:- use SQL to retrieve specific sets of data from databases. da following query for retrieving all records in a table named "Customers": SELECT * FROM Customers da following code for executing this query in PHP: $customer_result = mysql_query("SELECT * FROM Customers"); 4> Output your data:- Once you retrieve da data from your database, you can present it within your site pages,da following code demonstrates writing da query results into a page within HTML structures:- while($customer_row = mysql_fetch_array($customer_result)) { echo "<p>".$customer_row['CustName']."</p>"; } da while loop iterates through each record in da "Customer" table, writing da value from a "CustName" field into da page as part of a paragraph element. 5> Test your script:- after you have your database connection script complete, upload it to your server to test it. If you have errors, check your database account details as well as da structure of your tables. once you have established that you can connect to the database successfully in your script, you can build on da basic code to present your data to site users.
23rd Apr 2017, 4:49 PM
Don MTY
Don MTY - avatar
+ 6
You should use either PHP, Java or .NET (Among others) to establish a connection between the website and the database. You could do this with Javascript, but i would advise against it because it's deemed bad practice and has some security issues. As it is with every hard task, Google is your friend in this case. I would reccomend looking through StackOverflow, as most of the users on there are web-developers. Good luck!
23rd Apr 2017, 4:37 PM
Roolin
Roolin - avatar
+ 2
Thank you....
29th Apr 2017, 4:17 AM
Aniket Dhanak
Aniket Dhanak - avatar