Download the PHP package colshrapnel/safemysql without Composer

On this page you can find all versions of the php package colshrapnel/safemysql. 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 safemysql

SafeMySQL

SafeMySQL is a PHP class for safe and convenient handling of MySQL queries.

This class is distinguished by three main features

Yet, it is very easy to use. You need to learn only a few things:

  1. You have to always pass whatever dynamical data into the query via placeholder
  2. Each placeholder have to be marked with data type. At the moment there are six types:
    • ?s ("string") - strings (also , and )
    • ?i ("integer") - the name says it all
    • ?n ("name") - identifiers (table and field names)
    • ?a ("array") - complex placeholder for operator (substituted with string of 'a','b','c' format, without parentesis)
    • ?u ("update") - complex placeholder for operator (substituted with string of field='value',field='value' format)
    • ?p ("parsed") - special type placeholder, for inserting already parsed statements without any processing, to avoid double parsing.
  3. To get data right out of the query there are helper methods for the most used:
    • query($query,$param1,$param2, ...) - returns mysqli resource.
    • getOne($query,$param1,$param2, ...) - returns scalar value
    • getRow($query,$param1,$param2, ...) - returns 1-dimensional array, a row
    • getCol($query,$param1,$param2, ...) - returns 1-dimensional array, a column
    • getAll($query,$param1,$param2, ...) - returns 2-dimensional array, an array of rows
    • getInd($key,$query,$par1,$par2, ...) - returns an indexed 2-dimensional array, an array of rows
    • getIndCol($key,$query,$par1,$par2, ...) - returns 1-dimensional array, an indexed column, consists of key => value pairs
  4. For the whatever complex case always use the parse() method. And insert

The rest is as usual - just create a regular SQL (with placeholders) and get a result:

The main feature of this class is a type-hinted placeholders. And it's a really great step further from just ordinal placeholders used in prepared statements. Simply because dynamical parts of the query aren't limited to just scalar data! In the real life we have to add identifiers, arrays for operator, and arrays for and queries. So - we need many different types of data formatting. Thus, we need the way to tell the driver how to format this particular data. Conventional prepared statements use toilsome and repeating bind_* functions. But there is a way more sleek and useful way - to set the type along with placeholder itself. It is not something new - well-known function uses exactly the same mechanism. So, I hesitated not to borrow such a brilliant idea.

To implement such a feature, no doubt one have to have their own query parser. No problem, it's not a big deal. But the benefits are innumerable. Look at all the questions on Stack Overflow where developers are trying in vain to bind a field name. Voila - with the identifier placeholder it is as easy as adding a field value:

Nothing could be easier!

Of course we will have placeholders for the common types - strings and numbers. But as we started inventing new placeholders - let's make some more!

Another trouble in creating prepared queries - arrays going to the IN operator. Everyone is trying to do it their own way, but the type-hinted placeholder makes it as simple as adding a string:

The same goes for such toilsome queries like and .

And, of course, we have a set of helper functions to turn type-hinted placeholders into real brilliant, making almost every call to the database as simple as one or two lines of code for all the regular real life tasks.


All versions of safemysql with dependencies

PHP Build Version
Package Version
Requires php Version >=5.0.0
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 colshrapnel/safemysql contains the following files

Loading the files please wait ....