Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to connect html pages to mysql database? [closed]

Tags:

html

mysql

I want to know how to connect html pages to mysql database? What are the codes?

I also want to know how to add new data to MySQL database when I'm using HTML page and also how to publish the data?

like image 234
lilian Avatar asked Feb 16 '11 03:02

lilian


People also ask

What are the ways the connection with MySQL can be closed?

mysql_close() closes the non-persistent connection to the MySQL server that's associated with the specified link identifier. If link_identifier isn't specified, the last opened link is used.

Can we connect HTML page with database?

It happens on server, which is where the website is hosted. So, in order to connect to the database and perform various data related actions, you have to use server-side scripts, like php, jsp, asp.net etc. In order to insert new data into the database, you can use phpMyAdmin or write a INSERT query and execute them.

What happens if MySQL connection is not closed?

Performance will negatively be affected. Opening a new socket (especially to an external database server) is more expensive and time consuming than just keeping a pointer to the current connection in memory. The access to the data will be performed by a new PHP request. Hence, you will have a new database connection.


1 Answers

HTML are markup languages, basically they are set of tags like <html>, <body>, which is used to present a website using css, and javascript as a whole. All these, happen in the clients system or the user you will be browsing the website.

Now, Connecting to a database, happens on whole another level. It happens on server, which is where the website is hosted.

So, in order to connect to the database and perform various data related actions, you have to use server-side scripts, like php, jsp, asp.net etc.

Now, lets see a snippet of connection using MYSQLi Extension of PHP

$db = mysqli_connect('hostname','username','password','databasename');

This single line code, is enough to get you started, you can mix such code, combined with HTML tags to create a HTML page, which is show data based pages. For example:

<?php
    $db = mysqli_connect('hostname','username','password','databasename');
?>
<html>
    <body>
          <?php
                $query = "SELECT * FROM `mytable`;";
                $result = mysqli_query($db, $query);
                while($row = mysqli_fetch_assoc($result)) {
                      // Display your datas on the page
                }
          ?>
    </body>
</html>

In order to insert new data into the database, you can use phpMyAdmin or write a INSERT query and execute them.

like image 71
Starx Avatar answered Oct 20 '22 21:10

Starx