Jamie Balfour

Welcome to my personal website.

Find out more about me, my personal projects, reviews, courses and much more here.

Official ZPE/YASS documentationWorking with databases

Overview

ZPE provides driver-neutral JDBC access through the built-in Database and DatabaseStatement structures. The packaged runtime includes drivers for MySQL, MariaDB, Microsoft SQL Server and PostgreSQL.

Database operations require permission level 3. Keep credentials outside source code in real applications and use named parameters for user-supplied values.

Connecting

YASS
$database = new Database(
  "postgresql", "localhost", 5432,
  "school", "zpe_user", "secret"
)

if ($database->is_open())
  print("Connected")
end if
  

Queries and updates

query returns a list of maps, with each map representing one row. execute returns the affected-row count for an update.

YASS
$people = $database->query(
  "SELECT id, name FROM people WHERE age >= :age",
  ["age" => 18]
)

$updated = $database->execute(
  "UPDATE people SET active = :active WHERE id = :id",
  ["active" => true, "id" => 42]
)
  

Prepared statements

YASS
$statement = $database->prepare(
  "SELECT id, name FROM people WHERE surname = :surname"
)
$statement->bind(["surname" => "Balfour"])
$rows = $statement->query()
$statement->close()
  

Named placeholders use :name. Names inside quoted SQL text or SQL comments are not interpreted as placeholders.

Transactions

YASS
if ($database->begin())
  if ($database->execute("UPDATE accounts SET balance = balance - 10 WHERE id = :id", ["id" => 1]))
    $database->commit()
  else
    $database->rollback()
  end if
end if
  

Errors and cleanup

Call get_last_error() after a failed operation. Close statements and database connections when they are no longer required.

Its implementation was made available in ZPE 1.14.9 (Spurriergate, September 2026).

Comments

There are no comments on this page.

New comment

Comments are welcome and encouraged, including disagreement and critique. However, this is not a space for abuse. Disagreement is welcome; personal attacks, harassment, or hate will be removed instantly. This site reflects personal opinions, not universal truths. If you can’t distinguish between the two, this probably isn’t the place for you. The system temporarily stores IP addresses and browser user agents for the purposes of spam prevention, moderation, and safeguarding. This data is automatically removed after fourteen days. Your email address is stored so that replies can be sent to your email address.

Comments powered by BalfComment

Feedback 👍
Comments are sent via email to me.