Guides

Access to MySQL databases

Examples in ASP and PHP code

Hosting Solutions offers MySQL database solutions for its services (http://www.mysql.com), which can be purchased as an additional service to a hosting plan..

Why use MySQL?

MySQL is one of the most advanced and secure RDBMS on the market. It is ideal for dynamic websites with a high number of visits and guarantees high performance and stability. MySQL also has no additional costs and is included free of charge in our hosting plans..

The complete documentation for MySQL is available at the following address:http://dev.mysql.com/doc/

The data to access the database are sent to the email address indicated when ordering/purchasing the service, but can also be viewed later from the control panel.

The data to be used to connect to the database are as follows:

  • Database Server: of the type mysqlXX.sqlhosting.it,where XX is a number that indicates the version of MySQL (e.g. mysql41, mysql51, etc) or IP address.
  • database name: the name provided in the email that confirms activation of the MySQL service.
  • Login: the name assigned when the MySQL service was activated.
  • Password: The password assigned when the MySQL service was activated.

Access to MySQL via ASP

The data used in this example are:

  • Database Server:of the type mysqlXX.sqlhosting.it,where XX is a number that indicates the version of MySQL (e.g. mysql41, mysql51, etc) or IP address.
  • database name: nomedb
  • User id: username
  • Password: password

<%
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open "driver={MySQL ODBC 3.51 Driver};server=mysql41.sqlhosting.it;port=3306;uid=nomeutente;pwd=passwprd;database=nomedb;"
interrogazione = "select * from test"
rs = Server.CreateObject("ADODB.Recordset")
set rs = conn.execute(interrogazione)
html_risultato = ""
do while not(rs.eof)
    html_risultato = html_risultato & "<tr>"
    html_risultato = html_risultato & "<td> " & rs("id") & "</td>"
    html_risultato = html_risultato & "<td>" & rs("descrizione") & "</td>"
    html_risultato = html_risultato & "</tr>"
    rs.movenext
loop
rs.close
conn.close
set rs = nothing
set conn = nothing
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
		"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<HTML>
<head>
<title> Test Connessione ADODB a MySql</title>
<meta name="Generator" content="EditPlus">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
</head>
<body>
<table border="1">
    <tr>
        <th colspan="3">
            <h3>Tabella Risultati Query: <%=interrogazione%></h3>
        </th>
    </tr>
    <tr>
        <th>ID categoria</th>
        <th>Nome categoria</th>
    </tr>
    <%=html_risultato%>
</table>
</body>
</html>

Access to MySQL via PHP

The complete guide of the MySQL library for PHP is available at the following address:

http://it.php.net/manual/it/ref.mysql.php

I dati usati in questo esempio sono:

  • Server name: mysql41.sqlhosting.it
  • Database name: nomedb
  • User id: username
  • Password: password

<?php
$connessione = mysql_connect("mysql41.sqlhosting.it", "nomeutente", "password")
       or die("Connessione non riuscita: " . mysql_error());
mysql_select_db("nomedb") or die ("database non presente");
$interrogazione = "select * from test";
$risultato = mysql_query($interrogazione);
while ($riga = mysql_fetch_array($risultato)) {
    $html_risultato .= '<tr>';
    $html_risultato .= '<td> '.$riga["id"].'</td>';
    $html_risultato .= '<td> '.$riga["descrizione"].'</td>';
    $html_risultato .= '</tr>';
}
mysql_close($connessione);
// HTML ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
		"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<HTML>
<head>
<title> Test Connessione ADODB </title>
<meta name="Generator" content="EditPlus">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
</head>
<body>
<table border="1">
    <tr>
        <th colspan="3">
            <h3>Tabella Risultati Query: <?php echo $interrogazione; ?></h3>
        </th>
    </tr>
    <tr>
        <th>ID categoria</th>
        <th>Nome categoria</th>
    </tr>
    <?php echo $html_risultato; ?>
</table>
</body>
</html>