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

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


$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.


Your intuition was correct as to what those variable names stand for, but that isn't to say that every use of PDO uses those variable names, just the particular code you're looking at.

Variable names are never significant to the correct execution of a function that you pass them to. I've seen people use obscenities for variable names in their entire project... it just doesn't matter to the functions. For your own sake, and the sake of any future developers who work with you, variable names should be concise and clear. Abbreviations should be avoided when you can help it, since it may not be clear to someone else that $hndlr is how you abbreviate "handler" - as this very question demonstrates, abbreviations are seldom intuitive.

It is more important that you develop or choose a coding standard and stick with it. If your variables are all lower_case_with_underscores, stick to that regardless of what you see people doing in other code outside of your project.


It's important to know what they are and use them right. You are free to call them anything you like. Considering the word 'handle' isn't seen often in other areas, I usually give my PDO variables different names.

My connection, I call $pdo_db. The statement handle I give a descriptive name based on what it represents, such as $pdo_user_info. It's a matter of balancing your own taste with making it understandable for future readers of your code.