Ok, one step better is the built in context switching action helper. This will make my code much easier to work with (I miss this from Solar

PHP Trickery

March 14th, 2009 by Ray in Computer Related, PHP/MySQL | Tags: | 2 Comments

While studying for my Zend certification, I came across a practice test question that asks what the primary difference is between a static method and a normal method. I figured this would be an easy question but I was almost tricked with false promises of language structure consistency*!

I was able to narrow my choices down to two answers: 1) static methods can’t be called from an instance and can only be called using the :: syntax, or 2) $this is not provided by static methods. I decided to play around with PHP a bit to find the answer and it turns out that the correct answer is number 2, which I knew but number 1 was throwing me off.

It turns out that you can call a static method from an instance, why you would want to I’m not sure.

Here’s an example:

class A {
    public static function foo() {
        return 'Hello';
    }
    public function bar() {
        return $this->foo();
    }
}
// normally I would just call:
echo A::foo();
// but this also works:
$instance = new A();
echo $instance->foo();
// and even this works!
$instance2 = new A();
echo $instance2->bar();

All of the examples above produce Hello.

Update: I will point out that this functionality is documented under Static Keyword in the PHP manual. Also, yesmarklapointe has a nice breakdown on what is returned under certain scenarios.

* PHP and Java have a lot of similarities when it comes to language structure but I guess most modern day languages do. I believe Java treats static methods the way you would expect–the only way to access a static method from outside of a Java class is by using the class name followed by the static method (e.g. A.foo()). To access foo() from within the same class you would just call foo().


Cost to run my desktop

March 13th, 2009 by Ray in Computer Related, The Bin, Uncategorized | Tags: | No Comments

Tonight I decided to plug my Kill-A-Watt into the outlet my computer* is plugged into just to see how much it costs to run it. Conclusion–it costs less than I thought.

According to Maine.gov delivery rates, it costs 6.76 cents per kWh (average residential rate). Right now my Kill-A-Watt has been running for about an hour and is registering 0.15 kWh and my computer is idle (minus my time right now posting this article).

All else equal, ($0.0676kWh * 0.15kWh) * 24hrs/day * 30days/month = $7.3008 or ~$7.30 a month. Of course I don’t run my computer 24×7 so my actual cost is a lot less.

What I want to do, to get a more accurate reading, is to plug my computer and LCD monitor into the same surge strip that will be plugged into the Kill-A-Watt and run Folding@Home 24×7 for a day or two. This would give me a good idea as to what it would cost per month under full computing load.

Just FYI, if you live in Maine and don’t want to shell out the cash for a Kill-A-Watt, go to your local library and check one out for free! This is a program being run by Efficiency Maine to help push Mainers to be more energy conscientious. My girlfriend was slightly irritated after she bought me one for Christmas and we found out about the Kill-A-Watts at the local library ;-)

* It is not just my computer that is plugged into this outlet. I also have Samsung 17″ wide screen LCD, a Cannon USB LIDE scanner, and a HP DeskJet color printer. My computer itself has the following hardware: AMD 5000+ BE (OC’d from 2.8Ghz to 3.01Ghz) w/2GB RAM, a 320GB Seagate HDD, and a nVidia 9600GT OC.


Google Chrome Annoyance

March 10th, 2009 by Ray in The Bin | No Comments

I have been using Google Chrome for some time now and I love it. I love it except for the fact that it can be a pain sometimes, more specifically, when it ignores my request for a non-cached web page. This has happened to me more than once at work (and now tonight at home) while debugging web applications.

Basically the scenario starts out where I am making changes to a web page, save my changes, move over to Chrome and hit the refresh button (or F5) to see the changes. If I don’t see the changes on the web page I’ll hit Shift+F5 to reload a fresh copy of the page–this does not always work and this is where I get annoyed. I get annoyed because I’ll end up spending 5-10 minutes trying to figure out why my changes are not taking effect. I’ll double, triple, even quadruple check my changes to see why there was no change on the web page, thinking “maybe I screwed up or missed some logic somewhere.” I’ll bug my co-workers, read the documentation on the function(s) I have updated in the application, swear up and down, and finally, finally once I am at the brink of going insane I’ll load up FireFox, Safari, or IE to see if the page loads…usually it does. The only remedy is clearing Chrome’s cache or restarting the browser–annoying!

According to Google’s documentation, Crtl+F5 or Shift+F5 should work. As stated though, this doesn’t always work. What’s the deal?


SQL-92 SQLSTATE Codes

March 8th, 2009 by Ray in Computer Related | Tags: , | No Comments

So I was looking for the SQLSTATE code that tells me that there were no errors during my SQL operation. I assumed the SQLSTATE code was 00000, but bad things happen when you assume, especially while programming.

So I did some hunting and searching and found the SQL-92 standards, which I found in a nice, very long text file. The document was difficult to search through just to find what I needed.

So I’ll save the rest of the world some trouble and post the SQL-92 SQLSTATE codes here. Tada!

Condition Class Subcondition Subclass
ambiguous cursor name 3C (no subclass) 000
cardinality violation 21 (no subclass) 000
connection exception 08 (no subclass) 000
connection does not exist 003
connection failure 006
connection name in use 002
SQL-client unable to establish SQL-connection 001
SQL-server rejected establishment of SQL-connection 004
transaction resolution unknown 007
data exception 22 (no subclass) 000
character not in repertoire 021
datetime field overflow 008
division by zero 012
error in assignment 005
indicator overflow 022
interval field overflow 015
invalid character value for cast 018
invalid datetime format 007
invalid escape character 019
invalid escape sequence 025
invalid parameter value 023
invalid time zone displacement value 009
null value, no indicator parameter 002
numeric value out of range 003
string data, length mismatch 026
string data, right truncation 001
substring error 011
trim error 027
unterminated C string 024
dependent privilege descriptors still exist 2B (no subclass) 000
dynamic SQL error 07 (no subclass) 000
cursor specification cannot be executed 003
invalid descriptor count 008
invalid descriptor index 009
prepared statement not a cursor specification 005
restricted data type attribute violation 006
using clause does not match dynamic parameter specifications 001
using clause does not match target specifications 002
using clause required for dynamic parameters 004
using clause required for result fields 007
feature not supported 0A (no subclass) 000
multiple server transactions 001
integrity constraint violation 23 (no subclass) 000
invalid authorization specification 28 (no subclass) 000
invalid catalog name 3D (no subclass) 000
invalid character set name 2C (no subclass) 000
invalid condition number 35 (no subclass) 000
invalid connection name 2E (no subclass) 000
invalid cursor name 34 (no subclass) 000
invalid cursor state 24 (no subclass) 000
invalid schema name 3F (no subclass) 000
invalid SQL descriptor name 33 (no subclass) 000
invalid SQL statement name 26 (no subclass) 000
invalid transaction state 25 (no subclass) 000
invalid transaction termination 2D (no subclass) 000
no data 02 (no subclass) 000
Remote Database Access HZ (See ISO/IEC 9579-2 for the definition of protocol subconditions and subclass code values) 000
successful completion 00 (no subclass) 000
syntax error or access rule violation 42 (no subclass) 000
syntax error or access rule violation in direct SQL statement 2A (no subclass) 000
syntax error or access rule violation in dynamic SQL statement 37 (no subclass) 000
transaction rollback 40 (no subclass) 000
integrity constraint violation 002
serialization failure 001
statement completion unknown 003
triggered data change violation 27 (no subclass) 000
warning 01 (no subclass) 000
cursor operation conflict 001
disconnect error 002
implicit zero-bit padding 008
insufficient item descriptor areas 005
null value eliminated in set function 003
privilege not granted 007
privilege not revoked 006
query expression too long for information schema 00A
search condition too long for information schema 009
string data, right truncation 004
with check option violation 44 (no subclass) 000