Dynamic Web Development PHP, ASP or asp.net

Source: Internet
Author: User
Tags error handling odbc mysql odbc connection variables php and php example web hosting
This is a frequently asked question, and it is easy to bring people into contention about Linux or Windows. Such arguments actually reflect how difficult it is to conduct parallel analysis of competing web development technologies, and this difficulty is also greatly increased by the differing views of developers on any comparable operating system.

So instead of continuing to engage in this debate, we might as well look at the advantages that each technology presents for a particular Web development and a running environment. Although the similarity between ASP and PHP is greater than any of the asp.net, we still have to discuss asp.net. The reason is that developers often confuse it with the ASP, and in the efforts of Microsoft ASP.net will indeed replace the ASP in the future.

Basic theory--Characteristics Overview
php--Hypertext Preprocessor (hypertext Pre-processor)
PHP is an open source server-side scripting language that is syntactically similar to the C language. Although originally designed for use on linux-based Apache Web server systems, PHP is now ported to any operating system and compatible with any standard WEB server software. From this you can also draw the three main advantages of PHP. First it is a cross-platform technology, so PHP applications can be ported easily-depending, of course, on the additional components that need to be integrated, such as vendor-specific databases. This portability also brings the advantage that most web hosting providers will support PHP, so it would be convenient to change the host as needed.

2nd, because PHP has much in common with the C programming language, PHP is easy to use for developers who are familiar with the syntax--a syntax that is also applied in Java, JavaScript, and Perl. Third, because it is open source products, PHP will continue to develop rapidly, and more importantly, the relevant vulnerability patch will be free to regularly implanted into the core library.

In addition, PHP has a much more appealing appeal to developers in the context of specific programming requirements. First, PHP has built-in libraries to support the direct creation of pictures and PDF documents and related operations. This means that when an application invokes a dynamically created menu image that contains anti-aliased type text, or if you need to export the Acrobat format page, PHP will be the ideal technique for solving such problems. Although these features can theoretically be obtained through other competing technologies, it is often possible for other technologies to install Third-party custom components.

Another thing that makes PHP the best choice for scripting server scripts is the good performance of PHP when dealing with issues such as connecting Mysol or Postgres databases. Although access to Mysol or Postgres databases can be implemented via an ODBC connection through ASP technology, this often requires additional configuration by the system administrator. Fortunately, this limitation was corrected in ASP.net, which provides data through MySQL when a direct database connection similar to that used for MS SQL Server is needed.

asp--Dynamic Services 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 the Visual Basic language), ASPs are immediately sought after by developers familiar with Microsoft Ide--visual Studio programming. With the development of scripting language, the researchers did not introduce too many functions to the ASP to join the competition of technology. As a result, features such as image manipulation that can be seen in PHP are not integrated into the ASP. However, developers can still write (or install) Third-party COM objects in the form of DLL files to do similar work. You can write code to do any action in this way, if the server itself allows it. Of course, the flaw is that this will lead to the ability to configure these service developers to interact with the desktop system-a feature that 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 wide range of markets and is well supported by ASP (which is not surprising). Although it is virtually compatible with any data source through ODBC, SQL Server and File DSN access (Files DSN access) can be implemented at the code level.

asp.net
The debate over whether to choose ASP or PHP is becoming more and more redundant with the rise of. Net. Indeed, the past years of debate will end with the announcement of the answer to either Java or. NET technology (or both). The only connection between ASP and ASP.net is that they both use VBScript. and alone. NET, it can use VBScript as well as some other approximately 20 languages.

For the ASP and PHP, the reason for asp.net to be another language is that it runs on a completely different architecture. The former is a translation scripting language, while. NET is a compiled framework. This means that the speed at which Web pages are run will be greatly improved. At the same time, the source code is more secure and more robust. In addition, ASP. NET brings a new idea to the Web programming--the idea of "Code-behind page". According to Code-behind thought, each HTML page is driven by its own compiled programmatic instructions. Thus, html--, or performance layer, is largely divorced from the business logic of the application. Although such separation can be achieved through PHP and ASP, this is not a major part of its own technology as asp.net.

Asp. NET is a complete integration of the various support for XML and Web services. A very broad range of security and password system libraries can be used for. NET, which is especially useful for financial institutions and enterprise data applications. As far as defects are concerned, even experienced developers will find it to be used. NET may confuse itself. Regardless of how familiar the developer is with the programming language they are using, a significant increase in the difficulty of the program paradigm may be a major obstacle for web developers to integrate into ASP.net. Host is also a problem for asp.net applications, and asp.net does not have the same level of support from the host provider as ASP or PHP to compete at the same levels.

Practice--language comparison
Variable declaration


In VBScript (both ASP and asp.net use VBScript), you do not have to declare a variable before you use it, although technical documentation is usually recommended. Using the Option Explicit declaration, a developer can enforce a variable declaration through a program. In PHP, variables can be declared, although there is no way to force developers to do this. Indeed, variables are declared automatically before they are used. The advantage of PHP variables is that variables can be set as references to other variables (references), whereas in VBScript variables can be defined only by value.


<%

' VBScript Example

Option Explicit

MyVar = 1

Myothervar = MyVar

MyVar = 2

' Myresult would be 3

Myresult = MyVar + Myothervar

%>

?

PHP Example

$myVar = 1;

' Use of the ampersand to make a reference

$myOtherVar = & $myVar;

$myVar = 2;

$myResult would be 4

$myResult = $myVar + $myOtherVar;

?>


Variable Collection
The way you use forms and query string variables in PHP and in ASP is very similar. There are many ways to access a form and a collection of query string variables, such as by name or as an array. There are many different situations in asp.net, especially for form fields. Unlike blindly looking for a submitted form variable, Code-behind can know every form field in an HTML page and can trigger a check on the values of those form fields as a condition for any known event execution. One of these events is "postback", which is triggered when the form user submits. Other events can be client-side programs and can be triggered by JavaScript. In ASP.net, there is no difference in nature between the two.


<%

' 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-->

<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"

runat= "Server"/>

<asp:label id= "message" runat= "Server"/>

</form>

</body>


strings concatenation (string concatenation)
PHP seems to give enough attention to this issue, which allows you to insert variables into a string without having to consider the usual concatenation (concatenation) problem. Asp. NET will make the whole process more troublesome, need to use its StringBuilder class, but this asp.net running speed is also much faster.


?

PHP Example

$link = mysql_connect ("host", "User", "password") or Die ("mysql_error ());"

mysql_select_db ("database") or Die ("could 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

}

}

?>

Connecting to a database
For the connection problem of the database, each kind of technology has demonstrated each outstanding normative. First, in each case, a connection to the database is established. For PHP, select the database after the build (for ASP and ASP.net will be completed during the connection phase). A query is then created and routed to the database, which may or may not produce a return record.


Because in essence asp.net is more object-oriented and supports complex error handling (the error handling), asp.net may need to write more code to accomplish simple tasks, whether it is relative to PHP or ASP. But in terms of advantages, ASP. NET to complete the display of data functionality is much less than PHP and asp--especially if you use built-in DataGrid control 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 as Not objrs.eof

' Do something

Objrs.movenext

Loop

%>

' ASP.net Example

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

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

<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>

Conclusion

Choosing ASP, PHP, or asp.net will ultimately depend on the needs of your application and the system environment in which you run your program. Developers ' familiarity with similar programming languages or paradigms can also be a factor of choice. Remember that there is no perfect method or personal reality to show which technology is the best choice. For example, using ASP.net to create a one-page form mail application for a Windows server may seem a bit overkill, but this is an excellent application environment for ASPs. If a site needs to be connected to a MySQL database on a Linux Apache server, then using an ASP or asp.net will appear powerless. If the user's personal requirements are carefully considered in advance, the developer's choice of competing technologies is half the battle.



Related Article

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.