fighting C# just to do simple things.
Published 2005-02-16 15:57:59
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.):
Logging the access:
Now turning to C#, this nice clear piece of code turns into a noisy mess with potential to explode at any time.
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(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..
"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();
Mentioned By:
google.com : C# explode (218 referals)
google.com : february (208 referals)
google.com : december (77 referals)
google.com : explode c# (57 referals)
google.com : SQLite c# (52 referals)
google.com : c# explode string (47 referals)
google.com : C# SQLite (36 referals)
google.com : c# string explode (36 referals)
www.planet-php.net : Planet PHP (26 referals)
google.com : explode string C# (23 referals)
google.com : akbkhome.com (16 referals)
google.com : C# TODO (15 referals)
google.com : sqlite c# example (15 referals)
www.artima.com : PHP Buzz Forum - fighting C# just to do simple things. (13 referals)
google.com : c# php explode (11 referals)
google.com : Explode in C# (10 referals)
google.com : PHP explode C# (10 referals)
google.com : string explode c# (10 referals)
www.artima.com : PHP Buzz (8 referals)
google.com : c# php comparison (8 referals)
google.com : C# explode (218 referals)
google.com : february (208 referals)
google.com : december (77 referals)
google.com : explode c# (57 referals)
google.com : SQLite c# (52 referals)
google.com : c# explode string (47 referals)
google.com : C# SQLite (36 referals)
google.com : c# string explode (36 referals)
www.planet-php.net : Planet PHP (26 referals)
google.com : explode string C# (23 referals)
google.com : akbkhome.com (16 referals)
google.com : C# TODO (15 referals)
google.com : sqlite c# example (15 referals)
www.artima.com : PHP Buzz Forum - fighting C# just to do simple things. (13 referals)
google.com : c# php explode (11 referals)
google.com : Explode in C# (10 referals)
google.com : PHP explode C# (10 referals)
google.com : string explode c# (10 referals)
www.artima.com : PHP Buzz (8 referals)
google.com : c# php comparison (8 referals)
Follow us
-
- Some thoughts on the language server and its usefulness in the roobuilder
- Roo Builder for Gtk4 moving forward
- Clustered Web Applications - Mysql and File replication
- GitLive - Branching - Merging
- PDO_DataObject Released
- PDO_DataObject is under way
- Mass email Marketing and anti-spam - some of the how-to..
- Hydra - Recruitment done right
Blog Latest
-
Twitter - @Roojs