Monday, October 24, 2011

ADOdb and MSSQL: Differences from MySQL and my ADOdb impression

On our first project that I'm in that utilizes MSSQL, a database server made by Microsoft, I've chose to use ADOdb abstraction, to prevent possible incompatibility. However it wasn't that easy. I had problem connecting, problem with SQL and more.

What is PHP ADOdb?

ADOdb is an abstraction library. Abstraction aims to simplify coding by doing the procedure but hiding the code that does the procedure. It is not actually hidden though, you can always dig in to the code but that defeats the purpose of abstraction, which is, to require less thinking for the programmer.

It is also designed to have shortcuts on stuffs that are frequently done. Therefore it lessens the lines of codes and making it easier to read.

Unsolved Connection Problem To MSSQL

2 of us on our team had problem connecting using SQL clients like SQL Server 2005,Visual Studio and Navicat. It says Login failed for user <username>. My team mate though, using mac, can connect using Navicat using the same credentials. Then I theorize that there's something weird on windows (or vista[our office PCs uses vista]) that maybe preventing us to connect.

The PHP on our server can connect, and since it's not a requirement to browse the db on a desktop client, I shifted my effort on creating a simple querying script on the server, so we can use it on querying.

Differences of MSSQL and MySQL

It wasn't as smooth as I imagined it, since the role of abstraction layer is to prevent compatibility issues. Here are some of the issues I had running PHP ADOdb on MSSQL as compared on PHP ADOdb on MySQL
  • backticks ( ` ) - it was my habit to backtick tables and field names on mysql, I realized it is not supported on MSSQL and I later learned that it uses brackets instead ( [ ] )
  • LIMIT clause - this is not supported on MSSQL, you will have to use something like: SELECT TOP 10 * FROM tablename
  • Floats you see might not be what you see. I found out that even with SQL where clause " fieldName > 0 ", I see results returning fieldName which seems to be equal to 0.00 , I then tried ROUND(fieldName,2), a suggestion of my teammate and it worked. Our theory is, it might be containing values beyond the 2nd decimal digit.
  • SHA1 and MD5 - these encryption algorithms are not called like SHA1() and MD5() on MSSQL. They are called by a function named HashBytes,(eg. HashBytes("SHA1","123") ) which returns binary version, like if php sha1() is called with 2nd parameter as true. To convert to hex, you have to use a function named master.dbo.fn_varbintohexstr() , which converts it to 0x01234 hex version, which then leads you to SUBSTR() it so you can remove the "0x". Messy isn't it?
    • example: SELECT SUBSTRING(master.dbo.fn_varbintohexstr(HashBytes('SHA1', '123')), 3,512)
    • The big limit is 512 is a play safe solution for MD5(32 hex characters) and SHA1(40 hex characters)
  • Random order - there's no clear support on MSSQL on MySQL's ORDER RAND() ... you can use a unique id seeder which is newid() though. Pretty slow though.
  • SUBSTRING() -  the third parameter (length) is required. SUBSTR() alias is non existent. Second parameter when set to 0 does not return blank string does not return blank string.

ADOdb Functions I Like

I've used ADOdb before on my second job, what I liked about it is that it has functions like the following:
  • getRow($sql) which gets the first row of select as php array,
  • getOne($sql) which gets the first row's first column(first cell), (eg. for sum(), count()) (as string)
  • getAssoc($sql,...) which returns array(first column =>  second column) format which is very useful in a lot of instances specially when combined with smarty template's html_options
  • autoExecute($table,$data,$mode,$where,...) - which inserts or update table. Useful specially for my situation having MSSQL which I am unfamiliar with. However I was not able to use it on MSSQL since this current project was read-only on DB.


Things I wish ADOdb has

  • escape string - it has quote() function, but sometimes I want an escape function that will not quote my strings
  • one dimensional list array query - it has getAssoc(), but sometimes I want a numeric list of array which is messy to do with getAssoc(), take this sql for example:SELECT country_id FROM countries

    Although it can be  done by crappy way like array_values(), I still wish there is a built in function on it.
  • meta quote (quoting for fields or table)  - a way to quote the field name like `field_name`, probably useful for reserved names

Achieving The Real Abstraction

  • Field quoting - use a function. (eg. string(7) "`date`" db_quote_field('date') ) or a class method
  • LIMIT clause - omit it. Then use GetArray([$number_of_rows]) if needed a specific limit or GetRow()
  • SHA1 / MD5 - you may not be able to use the same variable approach here, since MSSQL and MySQL SHA1() and MD5 it has a parameter and differ in number of closing parenthesis. Because of this, you may use a PHP function or an SQL procedure. I suggest using a PHP function.
    • eg. string "SHA1('123')" db_proc('SHA1','123')
  • Random ordering, Substring and other functions - Concat, IfNull, length, random, substr page of phplens appears to have list of abstraction functions and properties.

Conclusion

Always remember to use a user with limited permission when using a new SQLanguage.  On this case I specifically requested for a read-only user.

Although I had a experience that is not so smooth on using MSSQL, I understand that I have to learn more and use it before I conclude (although sometimes I'm a Microsoft hater :)) ), so I can't say that MSSQL is bad. Yes every PHP Developer likes MySQL, but there are people that are comfortable with it you'll have to face that fact if you want to be a good developer.

Labels: , , , ,

Monday, February 2, 2009

PHP/JS/CSS/HTML Code Previewer

For my comfort of practicing web programming easily, I made a new public tool that would also parse PHP, instead of the old HTML/CSS/JS only, now it can view PHP/JS/CSS/HTML at the same time

This tool can parse any PHP commands that my good webhost, 000webhost can parse try PHP/JS/CSS/HTML Previewer

Labels: ,

My Discovery of CSS2

I just read more about CSS2 and I discovered alot of new tricks on CSS2, specially on selectors and pseudo elements, and since I am a self-study guy, it's my first time to know the standard terms for each part of the CSS StyleSheet,(rule,selector[this one I already know before],block,property,value and the at-rules)

This is a very interesting new addition to my skill and I can't wait(I already implemented some of these[specially the cute :first-letter pseudo-class]) to use the new selectors I discovered.

Labels: ,

My First RegExp Try

Whenever I see the pattern I see on the examples of php.net/preg_match, I get much frustrated because I can't understand a thing, but when I saw the term "regular expressions" on a job pre-test question and it got connected with preg_match.

I discovered that this pattern is called regular expression which is explained in Regular Expression Details on php.net and from this I studied about regular expressions and applied it tonight using my new PHP code result previewer, and here's one of my bookmarked test

Labels: ,

Thursday, January 22, 2009

My Websites Descriptions

http://wow300.co.cc
This is the first website made, on November 2008. This website acquires average 100 visitors per day (37.49% Organic, 47.14% Referral, 15% Direct), peaking up to 257 visitors. This is a MMO Role-playing-game guide.
All except blog and forum manually coded. (This include: in-game code generator(PHP), spam-proof open-source(PHP), auto 404 keyword matcher and redirector(JS), Object oriented template functions(PHP), RSS Feed Generator(PHP), Sitemap Generator with auto updating lastmod tag(PHP) ,comment program(PHP)).
http://howit.co.cc
Created: October 2009. Website programming and website tools website
All except blog page is manually coded (This include: HTML/JS/CSS Code Parser, customizable calendar script (JS), HTML to JavaScript Converter(PHP), Friendster app codes generator(JS&PHP) and all JS code generator).
http://trueorpolls.co.cc
Created: November 2009. Aimed to be a free poll widget website. As of now this website can create a working poll equipped with graph representation, with a flawless security feature.
All programs and pages in this website are manually coded using PHP JS CSS and HTML
http://printversion.co.cc
Created December 17, 2009. Aimed to create printer friendly version of website pages, both usable by publishers or visitors.
All programs and pages in this website are manually coded using PHP JS CSS and HTML

Labels: , ,

Monday, January 19, 2009

My Debugging Exam Answer

I reviewed and researched much for my MS-debug exam this morning, and as I expected, I was overpowered over the exam, since it was basic logic problems only, here are my answer to the first question:(This exam was written)

Type 2 characters and if one of them is Y then print Y or else Print N both followed by a line break
100:mov ah,1; //COMMENT: activate function 1 of int21(Keyboard Scan w/ Echo) 102:int21; //Execute function 1 104:mov dl,al //Move the first one to a temporary register 106:int21;//Execute function 1 again 108:cmp dl,59; //is first equal to "Y"(ascii of Y is 59) ? 10A:je 11A //Jump to line 11A "mov ah,2" 10E:cmp al,59; //is 2nd equal to "Y"? 110:je 11A 112:mov ah,2 //activate function 2 of int21 (Char Output) 114:mov dl,4e //4e = ascii of "N" 116:int21 //print the N 118:jmp 120//Jump to the mov dl,0d for line breaks 11A:mov ah,2 11C:mov dl,59 11E:int21 //Print "Y" 120:mov dl,0d 122:int21 124:mov dl,0a 126:int21 //0d and 0a = line break 128:int20 //Terminate
This is the logic of my program but I am not sure if my messy writing would let my prof to read it well XD

Labels: ,

Sunday, January 18, 2009

Chat-Box Progam

I have successfully created a chat box program with security features and highly customizable source code.

Some of the security features of this program is a bad-word density limiter, Recent post limiter, and it can also be installed with a captcha.

This program runs without using databases which will be useful for web-host with poor database uptime

This 7KB program can make unlimited message archiving depending on the set limit(default is 100 messages). These automatically archived messages are stored and can be accessed trough "older post" and "newer posts" links

Once I successfully made a BBcode program for this chat box I will distribute this script soon for free

Labels: ,

Tuesday, January 13, 2009

Programming Languages I Know

PHP (Above Intermediate)

This is one of the language I enjoy the most, and I am coming far better each day, this programming language made it possible for me to control my websites anyway I want it to be, and almost anything I think of I can do in PHP.

Some of my PHP creations are Poll Programs, Print Version Generator Program, FTP Blogger Manipulator(I used it in this website and wow300.co.cc), Open Source program and my planned scripts like chat boxes and calendar

Note: I'm not using WYSIWYG (What you see is what you get) editors for my website codes anymore

JavaScript(Intermediate)

At first it was hard to learn JavaScript since it is a silent-error language, and sometimes I just can't get the error, but as time goes by, learning and optimizing gradually, I have been successfully using JavaScript on each of my website

CSS(Intermediate)

I am not comfortable using ready made templates and seeing there name on the comments not being too egoistic, I rather experience the pain of learning than be satisfied of being fed by other people.

HTML(Above Intermediate)

It started as logic based knowledge, trying to use it on friendster, and when I started web-publishing the HTML studying went alil serious. Now it became an addiction, addiction to learning. Even though this is not thought on my course, I persuaded to learn HTML and as I try to learn simple HTML harder and harder challenges I see and conquered.

From simple HTML I learned CSS,JS and PHP

LUA (Intermediate)

This programming language is the base language of wow macros, I learned this language while making my first website(wow300.co.cc - wow macros)

Assembly Language(Beginner)

This is actually thought in school and I like this programming language because it is interesting and challenging, additionally I like learning low level languages which I think is the root/base of most high level programming languages I know

Borland C++(Beginner)

Before I started web-publishing I know C++ better, but as I focus more about web-publishing and seeing that web-publishing is more object oriented and easy to learn that C++, I didn't developed my skills on C++ programming

Also, this is included in my course which is CoET on TUP, but seriously we didn't came far from the basic since (damn) we have a ratio of 5 is to 1 on a pentium II computer

Turbo Pascal(Beginner)

One year before I started web-publishing I know Pascal and C++ but because of the little fundamental knowledge and the thought of it as a not so useful program language to learn I didn't developed my skills about Pascal.

Labels:

My history of web-publishing

Late November 2008 as I was playing World of Warcraft and got bored, I went to YouTube and looked for some WoW Videos, and stumbled upon one of the (good)videos of wowhobbs.blogspot.com when I heard on that video the word "subscribe" the word "profit" came to my mind by then I went to blogspot.com and redirected blogger.com

I made my own blogs there which was 5, I wasn't satisfied with the ready made templates and made my own touch on them even I am not very good even at HTML at all.Settled for about 4 weeks and got unsatisfied with the static template of blogger. I want a host with more dynamic and controllable template. Among the early blogs I made in blogger, wow300.blogspot.com (world of warcraft macro blog) is one of the most successful(most successful doesn't mean success XD)

Searching by Google, I found own-free-website.com and made a site there, because I love red, I love making headers with red backgrounds, the result is a crappy interface which only me appreciates XD. In this part of my journey I also got innocently tempted by the wrong SEO spam approach which I stopped using until I became a Google admirer(and stopped hacking too) the only website I made in own-free-website.com(or page.tl) is wow300.page.tl (world of warcraft macro website). At the same time I was already trying to make videos to advertise my websites.

CO.CC:Free Domain

At this time I also discovered www.co.cc a free domain registrar and used the redirect service for my long url, wow300.blogspot.com, I was unsatisfied with the poor control ability page.tl about Cascading StyleSheets(CSS), this lead for another search for a better and more controllable webhosting.

By then I found webng.com which I really won't endorse on you. They are deceptive and they would fool there consumers saying there will be no ads placed on your website but the truth is they will try to put ads on your website secretly. When I have encountered this, I looked for another web-host as I felt betrayed by webng which I almost trusted.

Until I found 000webhost from most free webhosting listing on the web, I never found anything as good as this although I was a bit skeptic about the long URL of 000webhost.com and made me think my URL will be wow300.000webhost.com or something, I found out that they offer different domain name.

Free Web Hosting with Website Builder

In 000webhost I built wow.web44.net which is still my wow macro website, the only difference is I have control I never imagine I would have. I control every single character of my HTML codes, which gave way to blooming of my JavaScript and the start of my PHP learning.

And a little more time I discovered about DNS Support of 000webhost that made me really happy, now I moved wow.web44.net to wow300.co.cc and merged my 5 wow websites to one(wow300.blogspot.com, wowcommand.blogspot.com, wowparameter.blogspot.com, wowcondition.blogspot.com, wowscript.blogspot.com)

At the start I was thinking about profit, but after all I have learned and want to learn I became addicted to programming itself, I am now not using any WYSIWYG(What You See Is What You Get) Editors and is coding my websites manually and I find a real pleasure upon doing so

If I could describe how I love programming, I would say I love programming like a fat kid loves cake =)

Labels: