PHP PDO - What do $dbh and $sth stand for?

JDelage picture JDelage · Jun 17, 2011 · Viewed 18.9k times · Source

In PDO examples I often find the acronyms $dbh and $sth used. I suppose $dbh stands for "database handle" - correct? What about $sth? "Statement handle"?

Are there good reasons to use the above instead of $db_connection and $query (or other as appropriate)?

Answer

George Cummins picture George Cummins · Jun 17, 2011

$dbh = "Database Handle"

$sth = "Statement Handle"

I prefer the longer forms, as they are more descriptive. It is often helpful to future maintainers if you are explicit, even when using common acronyms and abbreviations.

In the past, when hard drive capacity, memory and bandwidth were scarcer, the abbreviations may have made sense. Today there is (arguably) greater value in producing readable, maintainable code.