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

Wednesday, October 19, 2011

New Position: Lead PHP Developer

June of this year I was employed on my second job(PHP Developer) that paid me 133% more than PHP Programmer). My former officemate on my first job, told me about a job opening with the same salary, I wasn't able to entertain this because my second job's website got hacked and all files got wiped, so I needed to help. And I don't think it's a good idea to leave a company after 1 month cause I think it'll look ugly on my resume.

The offer

3 months later I called them again and to my surprise they asked me to go to there office right away located in Ortigas, NCR, Philippines that night because they need it urgent. I had a test which is a bit hard( I was expecting tests would be easy) then next day I was offered the job as PHP Software Developer (although I would just call it PHP Developer), for 14% more more salary but with 37% less working hours but it is night shift.

I came back to there office on night shift, then discovered the one that I will replace, who needs to go away for personal reason, is the PHP Lead Developer of two other developers. Of course I didn't expected that I will be the next team leader cause I've just worked for 2 years(+1 year by my own) and I am new to the company. This guy explained to me the current project status and the background of the company we will work in. When I asked him if I will be the next lead developer, he  said he don't know.

The challenge: being unexpected leader

Some days later I formally started and the surprising part is that the CEO assigned the leader. Although in doubt, I just thought this is my chance to experience it. Considering I'm still a young developer(but not generally young though :P, at age 22, I know it's not gonna be easy to lead team mates who don't know you.

I had to adjust with the codes I inherit, which I call (sorry) bad code. I had learned how to aim for benefit of simplicity on my first job while my second job thought me on the benefit of complexity. I had my first job for 2 years, had them both simultaneously for 2 months and had my second job for 3 months. I learned a lot from my two previous jobs and it's time to apply the lessons from both.

Sinking in

All seems to be good, the catch is it takes 2 hours to go office. Including the time to prepare before and after office it takes away extra 6 hours of my daily life. I always say this same phrase "Tatanda ako ng maaga" (I'll get old early) :)). So I am preparing to rent-to-own a condo 15 minutes away from office. I just wish I can budget my money well cause it'll cost 65% of my current salary. XD

Labels: , ,

Tuesday, October 11, 2011

Realizing I'm Outdated. Love at 2nd "site" towards HTML5

I have been hearing about HTML5 for about a year now but I haven't paid too much attention cause coding with it means browser compatibility issues.

However, I came across a code on a form of mailchimp newsletter. I saw some attributes and attribute values that are new to my eyes. placeholder and required attributes, and the "email" input type.

At first I thought they are just used for the signup form's javascript, I assigned my teammate to make the jquery validate for it. but a minute later I was surprised by my browser pops me up a message saying one of the fields is required. Then I realized I was seeing placeholder texts on them while we don't add them yet.

I opened my test file and experimented with the third one, the "email" input[type] attribute which I replaced with 'text' cause the css was just targeting the classic "text" and "password" input[type] values. And to my surprise, this attribute shows a warning when the input does not contain a valid email address.

After this I googled about html5 and saw the reference  page on w3.org . I pasted it on document editor and it appears to be 1000 pages, I trimmed it abit and came out to be 700 pages. I will print it(cause I don't like reading alot on computer screens) perhaps 200 pages a time then read about it to add up on my web developing knowledge.

Labels: ,

Back And Blogging

Web Developing
It's been a while since I last posted a blog post here. It's because my free webhost cancelled my account for some ambiguous reason, that is, I broke one the terms of use. Which is weird cause only two website of mine was active that time, this site and my gaming guide website. Which I didn't edit for some months. It took me awhile to fix things cause I'm busy working as a PHP developer.

For the past 6 months I my workflow evolved more than it did for the past 2 years. I had a part time job on  a client based on europe which after 2 months hired me full time so I had to quit my first job which I had for 2 years. After 3 months of working I was hired by another local company. So in 4 months I had my salary increase by 2 and 2/3.

Religion
I thank the Lord for that cause 8 months ago I had been back and going to church again after a decade. And what's better, it's a christian church.

I can say that I'm converted now since I'm enjoying going to that church every week.

Financial Point of View

I've gone through a lot of other change such as my financial point of view. I've reading Robert Kiyosaki's book for awhile and it gives me alot of idea. Specially the part where he says that creating assets are better than buying them, like thinking of an idea that can give you money instead of buying a property that gives your money.

3 years ago this is the way I think. Create a good website that sustains itself. A website that visitors come on and those visits attracts more visit. After a year I realized it was almost impossible and started working as employee.

Now that I'm a highly paid employee I realized that that thinking 3 years ago was the right thinking. While preserving my job(s) I will think of website ideas that can be turned into assets.

At the same time I will save money for building business one at a time starting from small to large. And I'm also interested on studying stocks.

I plan to avail a condo 15 minutes away from office which I'll have to pay for 3 years, with no interest. And because it's just 3 years, it'll be 3x more expensive.


Education
I'm still an undergraduate of Technological University of the Philippines. Although I plan to study on a more sophisticated school as soon as I can support it, I plan to finish what's undone on my college. I will just have to process the papers on my Training(SIT) exemption (cause I've worked already) and I can graduate by march.

My financial plan though, states I can't quit being employe until I'm around 27 years old :P


Labels: , , , ,

Saturday, December 25, 2010

RTL Character: Weird Discovery On HTML ISO Characters

I was looking for the html entity version of ► (obviously I found it already)

For those who doesn't know html entity, it is the equivalent code for a character, which is used for characters that are not on the keyboard or for preventing a character to be interpreted as html character such as the less than sign (<)

I used PHP for loop to find it, however, I discovered a weird behavior, I was confused because I saw the numbers are all rumbled.

The PHP Code was:

<?php for($x=1;$x<=10000;$x++) { echo "$x: &#$x; <br />"; } ?>

It is coded to show the number on the right side and the character corresponding(ascii or iso)

This discovery means that it adding &#8238; can actually mess up a website, and I think I should watch out for such vulnerability. Making it look gibberish and unreadable.

<div> This text will stay as left to right <div>Hi, I will put RTL character after <b>this</b><span>&#8238; it will become</span> <span>right to left</span> and unreadable/gibberish </div> </div>
This code results to:
This text will stay as left to right
Hi, I will put RTL character after this‮ it will become right to left and unreadable/gibberish

This affects all the child elements, and all sibling elements and ancestor elements as long as they are all contained in the same <div>, which gives another reason to use <div>

Security Solution

Use htmlspecialchars() or htmlentities() on user input data, when printing them on your html. You can also use div's but that's just not reliable.

You can also target this character via str_replace or preg_replace but who knows what other characters can mess up your website

Or you can just ignore it. After all it will appear rarely, affect your website temporarily and it will require real intension to destroy your website even temporarily. But one day you'll be forced to choose your defense against it

Labels: , ,

Friday, October 22, 2010

Randomness Problems

learned alot about php's randomness today. PHP on windows biased on a specific number on specific range. For example this afternoon between 1-47, 24 is favored. Tonight as I post this, it favors 21.

While around 5:00(I believe time has something to do with random number generation) of this afternoon Unix hates 30. It gives this number, no matter how many the choices are, 2/3 of the normal chance.

I generated random integer from 1 to 1000, 1 million times(not exaggerating here), the normal answer should be 10,000 (1M/1K) but 30 is getting just around 6,000 after alot of reset and retries

But tonight as I post this, no bias occurs. It could be that I've just encountered a rare occurrence of a random number generation bug.

What to use when you don't trust php's rand() commands? the mt_rand() function. My boss told me about it just now and I think I'll be using it from now cause it shows no bias when I tested it.

Also, shuffle shuffle() works better than array_rand() when dealing with picking a random item from an array. I used this and get only 0.04% error

Or you can use this function(haha)

I'm a big fan of destiny so it's ironic how I seek the the perfection of randomness XD

Labels:

Friday, September 17, 2010

php function to truncate string upto x characters

My sidebar now looks better now that I implement one of the codes I use on another project to truncate strings upto a certain chars, without cutting or truncating words

The Code

/**
* truncate_upto_chars
* @param string $string the string to truncate
* @param int $chars the number of characters, this will not "cut" words
* @param string $ellipsis the string to concatenate or put in the end of the string if truncated
* @see http://albertdiones.co.cc/blog/2010/09/php-function-to-truncate-string-upto-x.html
*/
function truncate_upto_chars($string,$chars,$ellipsis='…') {
  if (preg_match(sprintf('/^.{0,%u}(.*?\b|$)/',$chars),$string,$preg_matches)) {
    $str=$preg_matches[0];
    if (strlen($str)>=$chars)
      $str.=$ellipsis;
    return $str;
  }
  else
    ;#throw new Exception("failed to truncate $string");
}

I'm kinda amused to exceptions so I used them almost all the time. And I know not all are amused haha, that's why I commented it out

And I'm not really sure why I used sprintf there. You can edit it anyway if you like to use it. :)

Labels:

Friday, September 3, 2010

Google Buckyball Logo - Another CSS Sprite Animation

I have found another CSS sprite animation on the web, the Google's buckyball logo for today, September 4, 2010.

Although it's a bit crappy cause makes my Firefox slow down, it gives me the idea that web developers really consider using this method to animate "images" although they are not just images.

This case is very complex that it makes me crazy thinking how they get the motivation on making around 50+ parts that moves around and making sure that the bond line (divs with background) and the bond point(img) would be perfectly bonded. However the browser would pay the performance price.

I have save a copy of it just in case you really want to see it in the future (since tomorrow it will be gone): View Google buckyball animation Although it's up to Google if they'll remove these files on there website.

Now I wonder, what's better? gif animation or canvass animation or flash animation or css sprite animation?

Note: I'm not really sure about the correct term for "css sprite animation"

Labels:

Saturday, August 7, 2010

Pointer Gesture - Firefox User Script

I just made a new user script for firefox's greasemonkey addon.

It's gesture user script cause I want a customizable gesture script.

I made this just for fun, next for my tablet (fun first cause I would have searched for gesture addons or wait till I got windows 7 installed. Actually what I'm really proud are my better debugging and MATH skills :)

Aside from those reason, I also like the fact that I can customize it to add all the features and other gestures that I want (Yeah I'm so selfish)

http://www.userscripts.org/scripts/show/83147

I'm still thinking of adding new gestures like refresh when drawing a circle, and a way to google search using selected text (unfortunately select then double click won't work smoothly so I need to find another way)

Current features:
  • 1. Mousedown then drag upward then mouseup to page down
    • 1.1 Mousedown, hold, then drag upward then mouseup to go to page's bottom
  • 2. Mousedown then drag downward then mouseup to page up
    • 2.1 Mousedown, hold, then drag downward then mouseup to go to page's top
  • 3. Mousedown then drag to the left then mouseup to go back(history)
  • 4. Mousedown then drag to the right then mouseup to go forward)history)
  • Drag links diagonally right-upward then mouseup to open them in new tab
  • 6. Drag links diagonally left-upward then mouseup to open them in current window
  • 7.Tabs opened using gesture # 5 can be closed by drawing a cross / then \

Labels:

Saturday, March 27, 2010

Travians' CSS Sprite Animation

I have came across a browser game website, http://travians.com/ . This website at first glance looks like a flash animated or GIF animated website as you hover your mouse on the characters and other things on the page, specially on the mouse on the sign post(the login form). When you hover on the mouse(not the one you're holding right now). It performs a tumbling(backtive), then goes back hanging on the signpost. On first glance I thought this is a GIF or flash, but when I inspected it it was actually a CSS sprite. http://travians.com/img/portal/interface/chars/mouse.png I wonder where I can use this technique.

Labels:

Monday, March 8, 2010

Blogger now deprecating FTP publishing

Source: http://blogger-ftp.blogspot.com/2010/01/deprecating-ftp.html

Blogger is deactivating FTP publishing starting on may 1, 2010. This is a very bad news for me because most of my blogs are published this way.

I use this publishing so that I can use the html blog files to create a dynamic php blog pages. Now I am forced to create a blogging backend or maybe just use Wordpress. This might be a good idea because Wordpress do something I can't figure out to index pages on google.

Labels:

Sunday, March 7, 2010

New Layout

I have added a new layout to this website. This new layout includes a dropdown menu on the header, jquery integration, border-radius. I am just basically applying what I learned on my work.

I also used the IE only css property, expression() which uses javascript in css layout. This seems to be a cool way to fix the % problem, the absolute-fixed problem, the auto margin problem and many problems that IE gives to web designers (well I consider myself more of a programmer).

I also used my own database program which I temporary call RSDB(Real Simple DataBase). I am still having trouble making the backend though :P.

Labels:

Tuesday, November 3, 2009

A (crazy) PHP AntiVirus

I often find myself unsatisfied of what my antivirus can detect, so I often wish I can tell my antivirus, hey! delete all files like this one, everything identical with this file should be deleted! delete them all.

But, I didn't found anything like that, and I am a PHP programmer, and I can't do anything? So one night I started to create a simple antivirus program using PHP. So I created it, but lol, what's the sense? I bet it can only be used on localhost, so I won't be able to share it.

It simply compare contents of files from the virus signatures folder, one by one, but of course, for efficiency, it also records the file sizes, making it possible to check for possible threats, without really opening the contents of the files that is currently on scan, that makes it more efficient

The next problem will be, how to make it run continously, overcoming the maximum execution time, which is, by default, is 60 seconds, and on free webhosts, 30 seconds. Well implementing it on another host will popup another problem that I will figure out later.

This maximum execution time problem is defeated by using ajax and jquery, by using the $().replace which creates a chain reaction of ajax. And by using a get parameter that tells where the scan stopped, that will be used as "bookmark", that will be used to indicate where the script should start scanning.

I actually slept accidentally, and in the morning, I have found out that the script actually still runs, and it really ran continously, which is nice, just like a real antivirus

The funny part is, my (real)antivirus deletes my php antivirus' quarantine, *lol* . But I got i fixed later on by making the file extension not to be scanned. I actually always changed the file extensions of my virus collection( I actually call them pokemons sometimes ) into ".dangerous" so that it would say under the file name "DANGEROUS FILE" *lol*. After this all went right.

But in the end, what's the use of this PHP antivirus anyway? I dunno, but I know I can use this to scan my files with new threats that my antivirus can't detect as threat. If you find it to be useful for yourself, hmm maybe leave a comment

Labels:

Thursday, May 28, 2009

WoW300's Direct Traffic Inflation

It is weird but, My WoW Macro Website, WoW300 is receiving more direct traffic than I expect.For those who doesn't know, direct traffic is number of website visitors that directly typed the name of the website on there browsers.

Before, it was steady at below 20 visitors per day, I understand that this is just normal for a not-so-popular website. But these past weeks, I am receiving around 50 direct traffic per day, which really surprises me.

This could be a result of my more world of warcraft-like design especially on the icons of the spells, like the Polymorph Macros (I am talking about the sheep icon there). This kind of icons would have giving the visitors closer to the world of warcraft environment

If this continues, and add to the search engine traffic I expect as soon as I got most of the pages indexed by google(around 500 pages), I expect gradual inflation on the direct traffic and a big bang inflation on the organic traffic on every google indexation of pages(since I am noticing that google index many pages on each indexing)

Labels:

Wednesday, April 22, 2009

At last google indexed more of my pages

After about 2 weeks, from 21 pages from my website wow300.web44.net indexed by google now it is 47, but I still got more than 500 pages that waits to be indexed, and it seems it will take a long time for this to happen.

I still remember the times that I rejoice everytime that I see this website's search traffic jump from 30 to 60, then to 80 and before march it even peaked to 120 organic visitors per day

I am pretty confident that when this new site's page is indexed as many as the old one, this would get better search traffic than the previous one, but this takes too long

But anyway, that's how google goes.

Labels:

Thursday, April 16, 2009

Form Submission Objects Programs

I had an idea to make a object oriented program for html forms. I realized making a process for each of the submissions on my websites are inefficient, so I made this plan for OO Form objects

I will use this for uniformity and security. I think the __construct() and __toString() will become very handy this time.

I will start it out today and try it out in the future.

Labels:

Wednesday, April 15, 2009

My Website Membership program

I am developing a new program for my website, wow300.web44.net. It's a simple membership program.

I have been thinking it's a big help if users can help developing the website. And I may even make a self-sustaining website once the traffic inflates. I have made two object classes, a visitor class and a member class, the member class extends the first one.

It took me 2 and half hour, to make it work. Next I will be designing the GUI for the users. As of now, I think it's a real good and convenient program, I can import it to my other website in the future. I have used a pattern I read about, the singleton.

Anyway I have been practicing to have a cleaner codes in the sense that I am now putting spaces between equal signs, the function arguments and the parenthesis. But sometimes I am still doubting if I am doing a better habit or it's just a step back.

But I am sure that I am doing better on naming variables. From one letter variables, I am now using better names and as much as possible I am using English words with right spellings.

It's really hard to be a lone programmer, I hope someone would give me a distinct direction in the future. Maybe my boss in the future, or anyone with more experience.

Labels:

Sunday, April 12, 2009

Haha my inaccurate tongue

I just realized that I undersold myself last tuesday's job interview when the HR asked me how long I make page like what I showed her, I answered 2 days for 3hours/day which sums up to 6 hours

I think I was stupid to answer that that way. I meant I make that PHP program to make hundreds of pages (spells category on wow300). Haha she might have thought I was making a single page for two days =S my bad.

Anyway, I have just finished the program for the sitemap for the said page category and it now sums up to 162 pages. I am excited for all of this to be indexed by Google, I am sure that my former wow300.co.cc's Organic traffic will be doubled because of these new pages.

Labels:

Wednesday, April 8, 2009

Improving my designer skills

wow300.web44.net, my oldest website and once became a 200 visitor per day trafficked website, is a world of warcraft macro guide website. Although WoW servers are widely pirated, this game has a fairly high system requirement and it is a trend that players would take the best PC modification that they can.

By this trend, we can say that users who browse the net that is a WoW playeer is playing on an optimal PC with optimal connection, thus it is wise to focus on the attractiveness of the page than focusing on minimizing the page load, this theory is reflected on world of warcraft website, worldofwarcraft.com

But, what if they are browsing while they are playing? low Framerates on WoW is really annoying to players.Low framerates is often caused by excessive multi-tasking that there PC cannot handle. By this thought, would attractiveness really give them pleasure, or they would just be annoyed by there low framerate and long page load?

As of now I am able to redesign some of the parts of this website and I am also thinking if having the same look on all the pages is benificial to my website.

Maybe I should research more about the relation of these things with each other

Labels:

Tuesday, April 7, 2009

Finished the Per-Spell Pages of wow300

I have just finished one of my projects on wow300.web44.net, the categorization by spells. Where every spells, for example Heroic Strike , is contained on many macros on the website. When a user requests that spell page, the PHP will query the database for the macros that uses this spell.

In my opinion and experience, dividing your website in multiple pages, tackling atomic topics, will help so much in your SEO. So I am very excited to see my SE traffic as soon as Google Indexes all the pages. As of now I finished most of the spell extracting from my macro pages.

The fun part is that I added real icons from WoW to all these spells, which really makes my website look better. and more WoW'ish :P

I had a hard time making preg_match'es for extracting the spells. And the harder part is, these new spells will be recorded and I will still add details about it one by one. Now I have more than a hundred of spells. And the spell moderation and detail adding is almost done. So now I will just have to wait for new spells that needs details.

Labels: