You don't have to "extend the compiler", but you have to do what you probably meant by this: write a PHP module/extension in C that talks to the database's (typically) C library API. What does that mean? A database typically comes with connector libraries that are often written in low level C and thereby offer a C based API. That more or less works like an include 'api.php'
which then allows you to call functions of whatever you just included, but it's specific to C. PHP code cannot talk to C code directly, but a PHP extension written in C can act as a "bridge" between PHP code and the C API.
That C library then has many options how it may talk to the actual database. It may talk directly to another C API of the database, though that's not necessarily typical. Often a UNIX socket or TCP socket is used, sometimes across the network if the database is on a different machine. You could be talking directly to that UNIX/TCP socket from your PHP code if you wanted to, but that means you'd have to reimplement the entire protocol to talk to the database in PHP code. That's typically inefficient, since PHP is a rather high level language and doesn't offer any direct access to raw computer resources like memory, which makes this implementation rather inefficient.
So, the way it typically goes is:
- the database offers a protocol to talk to it over a socket of some kind
- an official protocol client is implemented in a C library, because it's efficient and portable
- someone writes a PHP extension to bridge that C library API into PHP userland code
There's nothing stopping you from implementing that protocol in other languages in alternative clients, but since this is often a tedious process and C is a widely used system, people typically end up writing wrappers around the existing official C library.