After you build a website on a Cloud Web Hosting instance, you may need to debug some of its features. This topic provides website debugging examples to help you.
Precautions
These examples are for developers with some coding experience and for enthusiasts who want to understand basic program features. To learn more about program features or code details, you can visit websites such as W3Cschool or consult your website developer.
After you obtain a test example package, follow the provided instructions. You can also modify the code to meet your requirements.
NoteSome test example packages in this topic include both code and instructions.
Test example summary
Select a test example based on your business needs:
Cloud Web Hosting instances that run the Windows operating system support Access databases. If your website is hosted on a Windows instance, you can use an Active Server Pages (ASP) program to connect to an Access database. A code example is provided for your reference.
Test example package path: ASP connection to Access test example
ASP.NET is a web development platform based on the .NET Framework that you can use to build web applications. It supports multiple programming languages, such as C#, F#, and Visual Basic.
Cloud Web Hosting instances that run the Windows operating system support SQL Server databases. The recommended way to connect to SQL Server databases is to use Data Management (DMS). If you want to write code in an ASP.NET application to connect to a SQL Server database, a code example is provided for your reference.
Test example path: ASP.NET connection to database test example
NoteThis example uses C#. You must replace the database information in the example with the actual information for your Cloud Web Hosting database. For more information about how to obtain database information, see Obtain and configure database information.
PHP Data Objects (PDO) is an interface for connecting to databases in PHP. PDO is available as a PHP Extension Community Library (PECL) extension in PHP 5.0 and is included with PHP releases starting from version 5.1. Therefore, PDO is supported in PHP 5.0 and later.
Cloud Web Hosting instances that run the Linux operating system support MySQL databases. The recommended way to connect to MySQL databases is to use Data Management (DMS). If you want to use the PDO interface to connect to a MySQL database, a code example is provided for your reference.
Test example path: PDO connection to database test example
NoteYou must replace the database information in the example with the actual information for your Cloud Web Hosting database. For more information about how to obtain database information, see Obtain and configure database information.
Common Gateway Interface (CGI) is a standard for external gateway programs to interface with information servers such as HTTP servers. It facilitates communication between clients and servers by passing request information from the client. If you want to use CGI to allow a browser to run an external program, a code example is provided for your reference.
Test example package path: CGI test example
Flash Video (FLV) is a video format commonly used for online videos. Shock Wave Flash (SWF) is a graphics instruction format often used for webpage decorations and animations. If you want to add video and animation features to your webpage, a code example is provided for your reference.
Test example package path: FLV video test and SWF video test example
cURL is a PHP extension that enables data and file transfers between servers. It supports uploads and downloads. If you want to use the cURL tool to upload and download website files, a code example is provided for your reference.
Test example package path: cURL test example for PHP
A session is a conversation between a server and a client. It provides a type of temporary storage on the server side. If you want to use a Session command to pass parameter information between the server and the client, a code example is provided for your reference.
Test example package path: Test example for passing parameters using the Session command in PHP
The pseudo-static feature is often used to make dynamic webpage addresses appear static. If you want to use an ASP program to enable the pseudo-static feature on a Windows-based Cloud Web Hosting instance, a code example is provided for your reference.
Test example package path: ASP test example for setting up pseudo-static URLs on a Windows 2008 host (IIS7)
NoteThis example applies to Cloud Web Hosting instances that run Windows Server 2008. To enable the pseudo-static feature on instances that run other versions of the Windows operating system, you can refer to this example and write the appropriate code.
If your website is on a Linux-based Cloud Web Hosting instance, you can use an ASP.NET upload program to configure the file upload feature on your webpage. A code example is provided for your reference.
Test example path: ASP.NET upload program test example
ASP.NET connection to database test example
The test example is as follows:
<%@ Import Namespace="System.Data" %>
<%@ import="" namespace="System.Data.SQL" %>
<script language="C#" runat="server">
// Declare C#
public DataSet dsCustomer;
protected void Page_Load(Object Src, EventArgs E )
{
// Connect to the database when the page opens
SqlConnection myConnection = new SqlConnection("server=Cloud Web Hosting database address;uid=Cloud Web Hosting database username;pwd=Cloud Web Hosting database password;database=Cloud Web Hosting database name");
SqlDataSetCommand CustomersDSCommand = new SqlDataSetCommand("select from customers", myConnection);
dsCustomer = new DataSet();
CustomersDSCommand.FillDataSet(dsCustomer,"Customers");
foreach (DataRow Customer in dsCustomer.Tables["Customers"].Rows)
{
Response.Write(Customer["CustomerId"].ToString() + "" );
}
}
</script>PDO connection to database test example
The test example is as follows:
<?php
$pdo = new PDO("mysql:host=Cloud Web Hosting database address;dbname=Cloud Web Hosting database name","Cloud Web Hosting database username","Cloud Web Hosting database password");
if(!$pdo){
die('Could not connect to MySQL: ' . mysqli_error());
}else{
echo("success");
}
?>ASP.NET upload program test example
The test example is as follows:
<!--
Copyright statement: This sample program is authorized for use only by HiChina's ASP.NET Cloud Web Hosting users. Any other use requires written authorization from HiChina.
-->
<%@ Page language="c#" %>
<html>
<head>
<title>ASP.NET File Upload Example</title>
<style type=text/css>
.td {
font-size:12px
}
.big {
font-size:14px
}
</style>
</head>
<script language="C#" runat="server">
private void Page_Load(object sender, System.EventArgs e)
{
lblError.Text = "";
}
private void btnUpload_Click(object sender, System.EventArgs e)
{
try {
if (!uploadFile.Value.ToLower().EndsWith(".jpg") && !uploadFile.Value.ToLower().EndsWith(".gif")) throw new Exception("Only image files can be uploaded."); // Check the type of the uploaded file.
HttpPostedFile postFile = uploadFile.PostedFile; // Call the method of the standard class library.
int contentLength = postFile.ContentLength;
if (contentLength > 512*1024)throw new Exception("Cannot upload files larger than 512 KB."); // Check the size of the uploaded file.
string fileName = postFile.FileName; // fileName is the name of the file you just uploaded.
fileName=fileName.Substring(fileName.LastIndexOf("\\")+1);
postFile.SaveAs(Request.PhysicalApplicationPath + fileName); // Save the file.
lblError.Text = "Upload successful! <a href=\"../" + fileName + "\" target=\"_blank\">View</a> the uploaded file.";
} catch(Exception ex) {
lblError.Text = ex.Message; // When an error occurs, print the error message.
}
}
</script>
<form id="UploadForm" method="post" enctype="multipart/form-data" runat="server">
<table width="75%" align=center cellpadding=4 cellspacing=4>
<tr>
<td>
HiChina ASP.NET Sample Program
</td>
</tr>
<tr height="1" bgcolor="red">
<td></td>
</tr>
<tr>
<td align=center>
<b class="big">File Upload
</td>
</tr>
<tr>
<td align="center">
<input type="file" id="uploadFile" runat="server" />
<asp:Button ID="btnUpload" Text="Upload" Runat="server" OnClick="btnUpload_Click"></asp:Button>
</td>
</tr>
<tr>
<td align=center><asp:Label id="lblError" runat="server" ForeColor="Red" />
</td>
</tr>
<tr>
<td align=center>Copyright (c) HiChina</td>
</tr>
</table>
</form>
</body>
</html>