The Artima Developer Community
Sponsored Link

PHP Buzz Forum
fighting C# just to do simple things.

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Alan Knowles

Posts: 390
Nickname: alank
Registered: Sep, 2004

Alan Knowles is Freelance Developer, works on PHP extensions and PEAR.
fighting C# just to do simple things. Posted: Feb 16, 2005 12:19 AM
Reply to this message Reply

This post originated from an RSS feed registered with PHP Buzz by Alan Knowles.
Original Post: fighting C# just to do simple things.
Feed Title: Smoking toooo much PHP
Feed URL: http://www.akbkhome.com/blog.php/RSS.xml
Feed Description: More than just a blog :)
Latest PHP Buzz Posts
Latest PHP Buzz Posts by Alan Knowles
Latest Posts From Smoking toooo much PHP

Advertisement
Another day at the C# school of torture.

Querying a database is nice and easy in PHP, especially with some of the nice code in PEAR, In the quick example below I just get a user account from the database and update the activity log (using DBDO - although DB_DataObject works the same.):

$tbl = DBDO::factory('mydb','user');
if (!$tbl->get('username', $_POST['username']) ||
    !($tbl->password == md5($_POST['password'])) {
      return false; // access denied....
}

Logging the access:
$log = DBDO::factory('mydb','activity');
$log->user_id = $tbl->id;
$log->at_time = date('Y-m-d H:i:s');
$log->insert();

Now turning to C#, this nice clear piece of code turns into a noisy mess with potential to explode at any time.

SqlCommand dbcmd = new SqlCommand(
            "SELECT * FROM user_details_basic WHERE " + 
            "username = @username"
            ,dbcon);
        SqlParameter param = new  SqlParameter("@username",  
SqlDbType.VarChar );
param.Value = Request.params['username'];
        dbcmd.Parameters.Add(param);
        ArrayList user = getResults(dbcmd); // This is a 40 line method!
        if (user.Count < 1) {
            closeDB();
            return 0; // not found..
        }
// as I said before (md5 is a 10 line method)
        if (0 != String.Compare((String) qmd5(password) , 
(String) ((Hashtable) user[0])["password"])) {
            closeDB();
            return 0;
        }

.....
  SqlCommand dbcmd = new SqlCommand(
                 "INSERT INTO activity " + 
                "   ( user_id,   at_time   )" +
                " VALUES ( @user_id , GETDATE() )",dbcon); 
        param = new SqlParameter("@user_id", SqlDbType.Int);
        param.Value = (int) ((Hashtable) user[0])["id"])
        dbcmd.Parameters.Add(param);
        // imagine this code with quite a few more parameters.
        reader = dbcmd.ExecuteReader();


The more I code in C#, The more I wonder if it's ever going to grow on me... it seems that although it's got a standard library, the quality of it is extremely poor, and not designed to help you solve problems, but rather waste time coding up simple things over and over again..

Read: fighting C# just to do simple things.

Topic: What's keeping you from PHP5? Previous Topic   Next Topic Topic: PHPBarnstormer 33

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use