npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

mfm-db

v1.0.7

Published

The `db.php` file is a PHP script that handles database operations such as connection, query execution, and data retrieval. It also includes utility functions for handling HTTP requests and responses.

Downloads

518

Readme

db.php Documentation

Overview

The db.php file is a PHP script that handles database operations such as connection, query execution, and data retrieval. It also includes utility functions for handling HTTP requests and responses.

Database Connection

The script connects to a MySQL database using the mysqli extension. The connection parameters are retrieved from a properties.php file.

HTTP Request Handling

The script handles HTTP POST and PUT requests with a content type other than application/x-www-form-urlencoded. The request body is parsed as JSON and the parameters are added to the $_POST superglobal.

Database Query Functions

The script provides several functions for executing SQL queries and retrieving data:

  • query($sql, $show_query = false): Executes an SQL query and returns the result. If $show_query is true, the query is also outputted for debugging purposes.
  • select($sql, $show_query = false): Executes an SQL SELECT query and returns the result rows as an associative array.
  • scalar($sql, $show_query = false): Executes an SQL SELECT query and returns the first column of the first row.
  • selectMapList($sql, $column, $show_query = false): Executes an SQL SELECT query and returns the result rows as an associative array, using the specified column as the key.
  • selectList($sql, $show_query = false): Executes an SQL SELECT query and returns the first column of the result rows as an array.
  • selectRow($sql, $show_query = false): Executes an SQL SELECT query and returns the first row as an associative array.

Error Handling

The script includes a error($error_message) function that sends an HTTP 500 response with a JSON body containing the error message. If the DEBUG constant is true, the function also includes a stack trace in the response.

Utility Functions

The script includes several utility functions for handling arrays, strings, and HTTP requests. These include functions for encoding and decoding JSON, generating random IDs, and retrieving request parameters.

Constants

The script uses several constants for configuration:

  • DEBUG: If true, the script includes a stack trace in error responses.
  • MYSQLI_OPT_INT_AND_FLOAT_NATIVE: This constant is used to configure the mysqli extension to return integer and float columns as native PHP types.

Global Variables

The script uses several global variables:

  • $mysql_conn: The mysqli connection object.
  • $host_name: The host name for the database connection.
  • $GLOBALS["conn"]: A reference to the mysqli connection object.
  • $GLOBALS["params"]: An associative array of request parameters.