Download the PHP package sectoroverload2k/php-mysql-database without Composer

On this page you can find all versions of the php package sectoroverload2k/php-mysql-database. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package php-mysql-database

php-mysql-database

Latest Version

A lightweight PHP MySQL database wrapper with prepared statement support and automatic parameter binding.

Installation

Quick Start

⚠️ Important: Understanding Return Types

KEY CONCEPT: All query methods return a MySQL object, NOT an array. You must call fetch methods to retrieve data.

Two Ways to Query

Method 1: Simple Query (Recommended)

Pass parameters directly to query() - most concise and preferred method:

Method 2: Prepare/Bind/Execute (Advanced)

Use when you need more control or plan to execute the same query multiple times:

Complete Examples

Select Single Row

Select Multiple Rows

Insert with Auto-Increment ID

Update Records

Delete Records

Complex Query with Multiple Parameters

Join Query

Fetch Methods

After executing a SELECT query, use these methods to retrieve data:

Parameter Type Detection

Parameters are automatically typed based on PHP variable type:

Explicit Type Definition (Optional)

You can manually specify types if needed:

Type identifiers:

Error Handling

The library throws exceptions on database errors:

Common Patterns

Check if Record Exists

Count Records

Pagination

Conditional Queries

Transaction Support

Wrap multiple queries in a transaction to ensure atomicity - either all operations succeed or all fail.

Basic Transaction

Money Transfer Example

Transaction Methods

beginTransaction(): bool

Start a new transaction.

Returns: True on success Throws: DBErrorException on failure

commit(): bool

Commit the current transaction.

Returns: True on success Throws: DBErrorException on failure or if no transaction is active

rollback(): bool

Rollback the current transaction.

Returns: True on success Throws: DBErrorException on failure or if no transaction is active

inTransaction(): bool

Check if currently in a transaction.

Returns: True if in transaction, false otherwise

Transaction Best Practices

  1. Always use try-catch - Catch exceptions and rollback on errors
  2. Commit explicitly - Don't rely on auto-commit
  3. Keep transactions short - Minimize lock time on tables
  4. Handle all errors - Always rollback on any exception
  5. Check state when needed - Use inTransaction() if transaction state is uncertain

API Reference

Database Class

__construct(array $config)

Creates database connection.

Config array:

query(string $sql, array $params = []): MySQL|null

Execute a query with optional parameters.

Returns: MySQL object on success, null on failure Throws: DBErrorException, ForeignKeyException

prepare(string $sql): MySQL|null

Prepare a statement for execution.

Returns: MySQL object on success, null on failure

bind_param(MySQL $stmt, mixed $params, string $types = null): MySQL

Bind parameters to prepared statement.

Returns: MySQL object

execute(MySQL $stmt): MySQL

Execute a prepared statement.

Returns: MySQL object with results

insert_id(): int

Get the last inserted auto-increment ID.

Returns: Integer ID

affected_rows(): int

Get the number of affected rows from the last query.

Returns: Number of rows affected by the last INSERT, UPDATE, DELETE, or REPLACE query

beginTransaction(): bool

Start a database transaction.

Returns: True on success Throws: DBErrorException

commit(): bool

Commit the current transaction.

Returns: True on success Throws: DBErrorException

rollback(): bool

Rollback the current transaction.

Returns: True on success Throws: DBErrorException

inTransaction(): bool

Check if currently in a transaction.

Returns: Boolean transaction state

MySQL Class (Result Object)

fetchAssoc(): array|null

Fetch single row as associative array.

Returns: Array on success, null if no more rows

fetchAll(): array

Fetch all remaining rows as array of associative arrays.

Returns: Array of arrays (empty array if no rows)

fetchRow(): array|null

Fetch single row as numeric array.

Returns: Array on success, null if no more rows

numRows(): int

Get number of rows in result set.

Returns: Integer count

numFields(): int

Get number of columns in result set.

Returns: Integer count

Best Practices

  1. Always use parameterized queries - Never concatenate user input into SQL
  2. Always fetch results - Call fetchAssoc() or fetchAll() on SELECT queries
  3. Check for null - fetchAssoc() returns null when no rows found
  4. Use try-catch - Catch database exceptions in production
  5. Close connections - Call $db->disconnect() when done (optional, happens automatically)

Common Mistakes to Avoid

Don't use result object as array:

Do fetch the data first:

Don't forget parameters for INSERT/UPDATE/DELETE:

INSERT/UPDATE/DELETE don't return data:

License

MIT License

Contributing

Pull requests are welcome. For major changes, please open an issue first.

Support

For issues and questions, please use the GitHub issue tracker.


All versions of php-mysql-database with dependencies

PHP Build Version
Package Version
Requires php Version >=8.0.0
sectoroverload2k/rest-router Version ^1.1
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package sectoroverload2k/php-mysql-database contains the following files

Loading the files please wait ...