Crud php mysql github

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

Complete CRUD (Create, Read, Update & Delete) for MySQL in PHP (using OOP)

License

IsiRoca/PHP-CRUD

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Sign In Required

Please sign in to use Codespaces.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

Latest commit

Git stats

Files

Failed to load latest commit information.

README.md

PHP CRUD — Create, Read, Update and Delete

Complete CRUD (Create, Read, Update & Delete) for MySQL in PHP (using OOP)

Edit config file in path «src/config.php» and put your database access data.

 const DB_HOST = 'YOUR_DB_HOST'; // Your Database Host const DB_USER = 'YOUR_DB_USERNAME'; // Your Database User Name const DB_PASS = 'YOUR_DB_PASSWORD'; // Your Database Password const DB_NAME = 'YOUR_DB_NAME'; // Your Database Name const DB_CHARSET = 'UTF-8'; // Your Database Charset

Use the following code to connect with your database

 include('src/php_crud.php'); $db = new Database(); $db->connect();

Import a SQL file in your database

 $sqlFile = file_get_contents('src/example.sql'); $db->import($sqlFile);

Example SQL Data imported

-- Create syntax for TABLE 'users' CREATE TABLE IF NOT EXISTS `users` ( `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT, `username` varchar(255) NOT NULL, `email` varchar(255) NOT NULL, `password` varchar(255) NOT NULL, `first_name` varchar(255) NOT NULL, `last_name` varchar(255) NOT NULL, `role_id` int(11), `create` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `update` timestamp NOT NULL, `active` TINYINT(1) DEFAULT '0', PRIMARY KEY (`id`), UNIQUE KEY `username` (`username`), UNIQUE KEY `email` (`email`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE utf8_unicode_ci AUTO_INCREMENT=1; INSERT INTO users VALUES (NULL,'Username 1','username1@email.com',SHA1('password'),'first','last',1,NULL,NULL, TRUE); INSERT INTO users VALUES (NULL,'Username 2','username2@email.com',MD5('password'),'','',NULL,NULL,NULL, FALSE); INSERT INTO users VALUES (NULL,'Username 3','username3@email.com',SHA1('password'),'','',NULL,NULL,NULL, FALSE); INSERT INTO users VALUES (NULL,'Username 4','username4@email.com',MD5('password'),'','',NULL,NULL,NULL, TRUE); INSERT INTO users VALUES (NULL,'Username 5','username5@email.com',SHA1('password'),'','',NULL,NULL,NULL, FALSE); INSERT INTO users VALUES (NULL,'Username 6','username6@email.com',MD5('password'),'','',NULL,NULL,NULL, FALSE); INSERT INTO users VALUES (NULL,'Username 7','username7@email.com',SHA1('password'),'','',NULL,NULL,NULL, TRUE); INSERT INTO users VALUES (NULL,'Username 8','username8@email.com',MD5('password'),'','',NULL,NULL,NULL, FALSE); INSERT INTO users VALUES (NULL,'Username 9','username9@email.com',SHA1('password'),'','',NULL,NULL,NULL, FALSE);

Create a table in a Database

Truncate a table in a Database

Источник

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

PHP class that simplify SQL request from a MySQL database

License

XinTecK/crud-mysql-php

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Sign In Required

Please sign in to use Codespaces.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

Latest commit

Git stats

Files

Failed to load latest commit information.

README.md

PHP class that simplify SQL request from a MySQL database

config

  1. git clone https://github.com/XinTecK/crud-mysql-php.git
  2. cd crud-mysql-php
  3. copy the class Database.php into your project
  4. configure MySQL database in the class (see below)
  5. That’s all ! You’re ready to go !

You can do the CRUD operations (Create, Read, Update, Delete) using PDO, without spending time to prepare request and all that stuff !

Let’s review every operation :

I configured the Database object with a mysql database that I created with only 1 table : Persons .
The Persons table has three columns :

At the moment, I’ve got three rows in this which are :

  1. PersonID : 1 | LastName : Lefrancq | FirstName : Hugo
  2. PersonID : 2 | LastName : Norris | FirstName : Chuck
  3. PersonID : 3 | LastName : Parker | FirstName : Tony

Now let’s see what we can do with this (Database methods available) :

select

insert
select_with_zinedine
You can store the method return (which is a boolean) in a variable in order to check if the request successfully executed ! insert_with_callback
select_with_torvalds

Let’s pretend I want to change my FirstName into Tux
update
update_success

Now let’s pretend I want to delete myself because I can’t walk straight properly, then this is what I would do :
delete delete_success

Now you’re good to go !

crud-mysql-php is licensed under the MIT license; see the «LICENSE» file.

About

PHP class that simplify SQL request from a MySQL database

Источник

Читайте также:  Python datetime date range
Оцените статью