Dynamic Website web development PHP, ASP or ASP. NET

Source: Internet
Author: User
Tags odbc connection php example

This is a frequently asked question, and it is easy to bring people into the debate about Linux or Windows. This debate actually reflects how difficult it is to conduct parallel analysis on competing Web development technologies, this difficulty is also greatly increased because developers have different opinions on any comparable operating systems.

So instead of continuing to participate in such a debate, we should look at the advantages of each technology for specific Web development and runtime environments. Although ASP and PHP are more similar than any of them, we still need to discuss ASP. NET. The reason is that developers often confuse ASP with ASP, and with Microsoft's efforts, ASP. NET will indeed replace ASP in the future.

Basic Theory-Overview of features
PHP -- Hypertext Pre-processor)
PHP is an open-source scripting language on the server, which is similar to the C language in syntax. Although originally designed for Linux-based Apache Web Server systems, PHP has been transplanted to any operating system and compatible with any standard Web server software. From this, we can also find three major advantages of PHP. First, it is a cross-platform technology, so PHP applications can be easily transplanted-of course, it depends on additional components that need to be integrated, such as the vendor-specific database. This portability also brings another advantage, that is, most Web host providers support PHP, so it is very convenient to change the host as needed.

Second, because PHP has many similarities with the C programming language, for developers who are familiar with the relevant syntax, PHP is very easy to use-this syntax is also applied in Java, JavaScript, and Perl. Third, because it is an open-source product, PHP will continue to develop rapidly. More importantly, related vulnerability patches will be implanted into the core library on a regular basis for free.

In addition, under some specific programming needs, PHP is more attractive to developers. First, PHP has an internal database to support direct creation of images and PDF documents and related operations. This means that when an application calls a dynamically created menu image containing the anti-aliased text, or needs to export a page in Acrobat format, PHP will be an ideal technology to solve this problem. Although these functions can also be obtained theoretically through other technologies competing with PHP, other technologies often require third-party custom components to be installed.

Another point that makes PHP the best choice for writing server scripts is that PHP performs well when dealing with problems such as connecting to mySOL or ipvs databases. Although access to the mySOL or ipvs database can be achieved through the ODBC connection through ASP technology, this usually requires additional configuration by the system administrator. Fortunately, this restriction has been corrected in ASP. NET. When you need to establish a direct database connection similar to using ms SQL Server, You can provide data through mySQL.

ASP-dynamic service page (Active Server Pages)
Microsoft introduces ASP to Windows NT Server 4 and uses it as the default platform for Dynamic Web applications under the IIS Web Server. Because it uses VBScript (a branch of Visual Basic), ASP is immediately sought after by developers familiar with Microsoft IDE-Visual Studio programming. With the continuous development of scripting language, the researchers did not introduce too many functions to ASP to join the technical competition. Therefore, the various image operations and other functions that can be seen in PHP are not integrated into ASP. However, developers can still write (or install) third-party COM objects in the form of DLL files to do similar work. With the server's own permission, you can write code to complete any action. Of course, the defect is that, in order to configure these services, developers have to interact with the Desktop System-this feature is not necessary for Web developers.

The advantage of ASP is that Microsoft servers are almost everywhere in the enterprise environment. In addition, ms SQL Server also has a broad market and supports ASP (which is not surprising ). Although in fact, ODBC can be compatible with any data source, SQL Server and file DSN access can be implemented at the code level.

ASP. NET
The debate on choosing ASP or PHP is becoming increasingly redundant with the rise of. NET. Indeed, the debate over the past few years will end with the announcement of the answer to the choice of Java or. NET Technology (or both. ASP and ASP. NET use VBScript. For. NET alone, it can use VBScript and about 20 other languages.

For ASP and PHP, ASP. NET is considered another language because it runs on a completely different architecture. The former is the translation script language, while. NET is the compiled framework. This means that the running speed of the web page will be greatly improved first. At the same time, the source code is safer and more robust. In addition, ASP. NET brings a new idea to Web programming-the idea of "code-behind page. According to the code-behind idea, every HTML page is driven by compiled procedural commands. Therefore, HTML, or the presentation layer, is largely separated from the business logic of the application. Although such separation can also be implemented through PHP and ASP, it is a major part of its own technology, just like ASP. NET.

Another advantage of ASP. NET is that it fully integrates various support for XML and Web services. For. NET, a wide range of security and password system libraries can be used, which is especially useful for financial institutions and enterprise data applications. In terms of defects, even experienced developers may find that using. NET may confuse themselves. Without considering how familiar developers are with the programming languages they use, a significant increase in the difficulty of program examples may become a major obstacle for Web developers to integrate into ASP. NET. For ASP. NET applications, hosts are also a problem. ASP. NET is not widely supported by host providers like ASP or PHP and cannot compete at the same level.

Practice-Language Comparison
Variable Declaration

 
In VBScript (both ASP and ASP. NET Use VBScript), you do not have to declare a variable before using it, although this is usually recommended in technical documents. With Option Explicit declaration, developers can use programs to force variable declaration. In PHP, variables can be declared, although there is no way to force developers to do this. Indeed, variables are automatically declared before use. The advantage of PHP variables is that variables can be set to references of other variables. In VBScript, variables can only be defined by values.


<%

'Vbscript Example

Option Explicit

MyVar = 1

Mythervar = myVar

MyVar = 2

 

'Myresult will be 3

MyResult = myVar + mythervar

%>

 

<?

// PHP Example

$ MyVar = 1;

'Use the ampersand to make a reference

$ Mythervar = & $ myVar;

$ MyVar = 2;

// $ MyResult will be 4

$ MyResult = $ myVar + $ mythervar;

?>


Variable collection
The methods for using forms and query string variables in PHP and ASP are very similar. There are many ways to access the collection of forms and query string variables, such as using name or using it as an array. In ASP. NET, there are many differences, especially for form fields. Unlike blindly searching for submitted form variables, code-behind can be familiar with every form field on the HTML page, you can also trigger a check on the values of these form fields based on the execution of any known events. One of the events is "postback". This event is triggered when the form is submitted by the user. Other events can be client programs and can be triggered using JavaScript. ASP. NET has no difference in nature.

 
<%

'Asp Example

MyFormVal = request. form ("myInputField ")

MyQSval = request. querystring ("myQSitem ")

MyVal = request. item ("myFormOrQSitem ")

%>

 

<?

// PHP 4.1 + Example

$ MyFormVal = $ _ POST ['myinputfield'];

$ MyQSval =$ _ REQUEST ['myqsitem '];

 

// PHP 3 + Example

$ MyFormVal = $ HTTP_POST_VARS ['myinputfield'];

 

// If register_globals = on

$ MyVal = $ myFormOrQSitem;

?>

 

<! -- ASP. NET example -->

<Html>

<Script language = "VB" runat = server>

Sub SubmitBtn_Click (Sender As Object, E As EventArgs)

Message. Text = "Hello" & Name. Text

End Sub

</Script>

<Body>

<Form action = "action. aspx" method = "post" runat = "server">

Name: <asp: textbox id = "Name" runat = "server"/>

<Asp: button text = "OK" OnClick = "SubmitBtn_Click"

Runat = "server"/>

<Asp: label id = "Message" runat = "server"/>

</Form>

</Body>

</Html>


String Concatenation)
PHP seems to have paid enough attention to this issue, allowing variables to be inserted into strings without the need to consider the common Concatenation issue. ASP. NET makes the entire process more troublesome and requires the use of its StringBuilder class. However, ASP. NET runs much faster.

 
<?

// PHP Example

$ Link = mysql_connect ("host", "user", "password") or die ("mysql_error ());

Mysql_select_db ("database") or die ("cocould not select database ");

$ Query = "SELECT * FROM Table ";

$ Result = mysql_query ($ query) or die (mysql_error ());

 

While ($ line = mysql_fetch_array ($ result, MYSQL_ASSOC )){

Foreach ($ line as $ col_value ){

// Do something

}

}

?>

Connect to database
Each technology has its own outstanding specifications for database connection issues. First, you must establish a connection to the database in each case. For PHP, select the database after creation (ASP and ASP. NET will be completed in the connection phase ). A query will be created and sent to the database, which may or may not generate a return record.

 
Because ASP. NET is more object-oriented and supports complex error handling. Therefore, ASP is used to complete simple tasks, regardless of PHP or ASP. NET may need to write more code. However, in terms of advantages, ASP. NET requires much less code to complete the data display function than PHP and ASP -- especially if the built-in datagrid control is used to automatically create HTML output.

<%

'Asp Example

Set objConn = Server. CreateObject ("ADODB. Connection ")

ObjConn. Open "Driver = {SQL Server}; Server = MyServerName ;"&_

"Database = myDatabaseName; Uid =; Pwd ="

 

Const strSQL = "SELECT * FROM Table" Set objRS = Server. CreateObject ("ADODB. Recordset ")

ObjRS. OpenstrSQL, objConn

Do While Not objRS. EOF

'Do something

ObjRS. MoveNext

Loop

%>

 

'Asp. NET Example

<% @ Import Namespace = "System. Data" %>

<% @ Import Namespace = "System. Data. SqlClient" %>

 

<Html>

<Script language = "VB" runat = "server">

Sub Page_Load (Sender As Object, E As EventArgs)

Dim MyConn As SqlConnection = New SqlConnection ("server = (local )...")

Dim MyComm As SqlCommand = New SqlCommand ("select * from Table", MyConn)

MyConn. Open ()

Dim dr As SqlDataReader = MyComm. ExecuteReader ()

MyDataGrid. DataSource = dr

MyDataGrid. DataBind ()

MyConn. Close ()

End Sub

</Script>

<Body>

<ASP: DataGrid id = "MyDataGrid" runat = "server"

Width = "600"

BackColor = "# FFFFFF"

BorderColor = "#000000"

ShowFooter = "false"

CellPadding = 2

CellSpacing = "0"

Font-Name = "Verdana"

Font-Size = "8pt"

HeaderStyle-BackColor = "# EEEEEE"

EnableViewState = "false"

/>

</Body>

</Html>

Conclusion

Selecting ASP, PHP, or ASP. NET depends on the needs of the application and the system environment of the running program. A developer's familiarity with similar programming languages or examples can also be used as a choice. Remember that there are no perfect methods and individual situations to indicate which technology is the best choice. For example, using ASP. NET to create a single page form email application for a Windows server seems to be a little useful, but it is an excellent application environment for ASP. If a site needs to be connected to the mySQL database on the Linux Apache server, ASP or ASP. NET may be insufficient. If you can take into account your personal requirements in advance, the selection process by developers in these competing technologies is half done.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.