GithubHelp home page GithubHelp logo

milkywaysoft / php-mysql-class Goto Github PK

View Code? Open in Web Editor NEW

This project forked from a1phanumeric/php-mysql-class

1.0 1.0 0.0 85 KB

Simple MySQL class written in PHP, for interfacing with a MySQL database.

Home Page: http://www.edrackham.com

php-mysql-class's Introduction

PHP MySQL Class

This is a simple to use MySQL class that easily bolts on to any existing PHP application, streamlining your MySQL interactions.

Latest Changes

I have refactored the entire class, and improved the code somewhat. This means that some things now work differently to the original version.

Setup

Simply include this class into your project like so:

include_once('/path/to/class.MySQL.php');

Then invoke the class in your project using the class constructor (which now sets the db credentials):

$oMySQL = new MySQL(MYSQL_NAME, MYSQL_USER, MYSQL_PASS, [MYSQL_HOST]);

MYSQL_NAME The name of your database

MYSQL_USER Your username for the server / database

MYSQL_PASS Your password for the server / database

MYSQL_HOST The hostname of the MySQL server (optional, defaults to 'localhost')

Usage

To use this class, you'd first init the object like so (using example credentials):

$oMySQL = new MySQL('my_database','username','password');

Provided you see no errors, you are now connected and can execute full MySQL queries using:

$oMySQL->ExecuteSQL($query);

ExecuteSQL() will return an array of results, or a true (if an UPDATE or DELETE).

There are other functions such as Insert(), Delete() and Select() which may or may not help with your queries to the database.

Example

To show you how easy this class is to use, consider you have a table called admin, which contains the following:

+----+--------------+
| id | username     |
+----+--------------+
|  1 | superuser    |
|  2 | a1phanumeric |
+----+--------------+

To add a user, you'd simply use:

$newUser = array('username' => 'Thrackhamator');
$oMySQL->Insert($newUser, 'admin');

And voila:

+----+---------------+
| id | username      |
+----+---------------+
|  1 | superuser     |
|  2 | a1phanumeric  |
|  3 | Thrackhamator |
+----+---------------+

To get the results into a usable array, just use $oMySQL->Select('admin') ...for example, doing the following:

print_r($oMySQL->Select('admin'));

will yield:

Array
(
    [0] => Array
        (
            [id] => 1
            [username] => superuser
        )

    [1] => Array
        (
            [id] => 2
            [username] => a1phanumeric
        )

    [2] => Array
        (
            [id] => 3
            [username] => Thrackhamator
        )

)

License

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

php-mysql-class's People

Contributors

a1phanumeric avatar hunter-dolan avatar djmomo avatar sajhu avatar neurotroph avatar king52311 avatar

Stargazers

Aman Ullah avatar

Watchers

Milkyway Soft avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.