Well continueing with my ASP.NET to PHP comparisons I am also amazed at how similar they are to connect to a database.
PHP:
$connection = mysql_connect($host, $user, $password) or die("error connecting");
mysql_select_db($database, $connection);
echo "You have connected to the database";
ASP.NET:
string ConnectionString = "server=myServer;uid=User;pwd=Password;database=NorthWind"
SqlConnection Connection = new SqlConnection(ConnectionString);
Try
{
Connection.Open(); //Opens the connection
Response.WriteLine("Hello"); //Prints out: Hello to the web page
Connection.Close(); //Close the connection
}
catch()
{
Response.WriteLine("Error connection");
}
There are definatly differences, but what I find interesting is how
close the actually connection strings are. It just shows the power of
once you learn one then learning another language is fairly simple.
The
one thing I do like about connecting to the database with C# or in .NET
is the connecting is universal accross all .NET technologies. Include
windows forms and embedded devices. Quit cool I think.
The
cool thing about php is you can actually run scripts on the command
line like a bash script and in that you can even do database
connections for data. That is very cool too. I am not sure how to do
it, but I have seen it done.