|
| 1 | +# MySql |
| 2 | +Classes you can modify your MySql database even if you don't know SQL. |
| 3 | + |
| 4 | +[View on Packagist](https://packagist.org/packages/dinodev/my-sql) |
| 5 | + |
| 6 | +## How to Use |
| 7 | +* Install PHP |
| 8 | +* Install MySql. |
| 9 | +* Run the Command `composer require dinodev/my-sql` |
| 10 | + |
| 11 | +### Connecting With Database |
| 12 | +```php |
| 13 | +use DinoDev\MySql\Classes\MySql; |
| 14 | + |
| 15 | +//Creating MySql |
| 16 | +$MySql = new MySql( |
| 17 | + "localhost" /* Hostname */, |
| 18 | + "root" /* Username */, |
| 19 | + "MySql" /* Password */, |
| 20 | + "world" /* Database */, |
| 21 | + $state /* State of MySql Connect (Success or Error) */ |
| 22 | +); |
| 23 | +``` |
| 24 | + |
| 25 | +### Features |
| 26 | +With MySql Library, you can run the following SQL commands: |
| 27 | +* Create |
| 28 | +* Drop |
| 29 | +* Select |
| 30 | +* Delete |
| 31 | +* Insert |
| 32 | + |
| 33 | +All theses Features are Classes, with namespace `DinoDev\MySql\Classes\` |
| 34 | + |
| 35 | +#### Create |
| 36 | +How to Use: |
| 37 | +```php |
| 38 | +$Create = new Create( |
| 39 | + $MySql /* Here, you pass the MySql Object */ |
| 40 | +); |
| 41 | + |
| 42 | +//Create Table |
| 43 | +$Create->Table( |
| 44 | + "TableName" /* The Table Name*/, |
| 45 | + ["Value 1", "Value2"] /* The Name Of Values */, |
| 46 | + ["varchar(20)", "varchar(50)"] /* The Type Of Values*/ |
| 47 | +); |
| 48 | +``` |
| 49 | + |
| 50 | +#### Drop |
| 51 | +How to Use: |
| 52 | +```php |
| 53 | +$Drop = new Drop( |
| 54 | + $MySql /* Here, you pass the MySql Object */ |
| 55 | +); |
| 56 | + |
| 57 | +//Drop Table |
| 58 | +$Drop->Table( |
| 59 | + "TableName" /* The Table Name */ |
| 60 | +); |
| 61 | +``` |
| 62 | + |
| 63 | +#### Select |
| 64 | +How to Use: |
| 65 | +```php |
| 66 | +$Select = new Select( |
| 67 | + $MySql /* Here, you pass the MySql Object*/ |
| 68 | +); |
| 69 | + |
| 70 | +//Select All |
| 71 | +$Select->All( |
| 72 | + "TableName" /* The Table Name */, |
| 73 | + 5 /* The Limit of Rows (Optional) */ |
| 74 | +); |
| 75 | + |
| 76 | +//Select Where |
| 77 | +$Select->Where( |
| 78 | + "TableName" /* The Table Name */, |
| 79 | + "Field", /* The Field Name */ |
| 80 | + "Value", /* Value */ |
| 81 | + 5 /* The Limit of Rows (Optional) */ |
| 82 | +); |
| 83 | + |
| 84 | +//Select Like |
| 85 | +$Select->Like( |
| 86 | + "TableName" /* The Table Name */, |
| 87 | + "Field", /* The Field Name */ |
| 88 | + "Value", /* Value */ |
| 89 | + 5 /* The Limit of Rows (Optional) */ |
| 90 | +); |
| 91 | +``` |
| 92 | + |
| 93 | +#### Insert |
| 94 | +How to Use: |
| 95 | +```php |
| 96 | +$Insert = new Insert( |
| 97 | + $MySql /* Here, you pass the MySql Object*/ |
| 98 | +); |
| 99 | + |
| 100 | +//Insert |
| 101 | +$Insert->Insert( |
| 102 | + "TableName" /* The Table Name */, |
| 103 | + [ "Field One", "Field Two" ] /* The Fields Name */ , |
| 104 | + [ "Value One", "Value Two" ] /* Values */ |
| 105 | +); |
| 106 | +``` |
| 107 | + |
| 108 | +#### Delete |
| 109 | +How to Use: |
| 110 | +```php |
| 111 | +//Delete Where |
| 112 | +$Delete->Where( |
| 113 | + "TableName" /* The Table Name */, |
| 114 | + "Field" /* The Field Name */, |
| 115 | + "Value", /* Value */ |
| 116 | +); |
| 117 | + |
| 118 | +//Delete Like |
| 119 | +$Delete->Like( |
| 120 | + "TableName" /* The Table Name */, |
| 121 | + "Field", /* The Field Name */ |
| 122 | + "Value", /* Value */ |
| 123 | +); |
| 124 | +``` |
| 125 | + |
| 126 | + |
| 127 | + |
| 128 | +## Example |
| 129 | +```php |
| 130 | +<?php |
| 131 | + |
| 132 | +use DinoDev\MySql\Classes\{ |
| 133 | + MySql, |
| 134 | + Create, |
| 135 | + Drop, |
| 136 | + Select, |
| 137 | + Insert, |
| 138 | + Delete |
| 139 | +}; |
| 140 | + |
| 141 | +require_once __DIR__ . "/vendor/autoload.php"; |
| 142 | + |
| 143 | +//Creating MySql |
| 144 | +$MySql = new MySql( |
| 145 | + "localhost", |
| 146 | + "root", |
| 147 | + "MySql", |
| 148 | + "world", |
| 149 | + $state |
| 150 | +); |
| 151 | + |
| 152 | +$Create = new Create($MySql); |
| 153 | + |
| 154 | +$Drop = new Drop($MySql); |
| 155 | +$Select = new Select($MySql); |
| 156 | + |
| 157 | +$Insert = new Insert($MySql); |
| 158 | + |
| 159 | +$Delete = new Delete($MySql); |
| 160 | + |
| 161 | +//Creating Table |
| 162 | +$Create->Table( |
| 163 | + "Users", |
| 164 | + ["Name", "Mail", "Pwd", "Age"], |
| 165 | + ["varchar(20)", "varchar(50)", "varchar(70)", "tinyint"] |
| 166 | +); //Return True |
| 167 | + |
| 168 | +//Insert 2 Users |
| 169 | +insertUsers($Insert); |
| 170 | + |
| 171 | +//Delete All Users |
| 172 | +$Delete->All("Users"); //Return True |
| 173 | + |
| 174 | +//Insert 2 Users |
| 175 | +insertUsers($Insert); |
| 176 | + |
| 177 | +$Delete->Where( |
| 178 | + "Users", |
| 179 | + "Age", |
| 180 | + 32 |
| 181 | +); //Return True |
| 182 | + |
| 183 | +$Delete->Like( |
| 184 | + "Users", |
| 185 | + "Name", |
| 186 | + "Mich" |
| 187 | +); //Return True |
| 188 | + |
| 189 | +//Insert 2 Users |
| 190 | +insertUsers($Insert); |
| 191 | + |
| 192 | +$Select->All("Users"); //Return All Users |
| 193 | +$Select->All("Users", 1); //Return Joe User (Limit 1) |
| 194 | + |
| 195 | +$Select->Where( |
| 196 | + "Users", |
| 197 | + "Age", |
| 198 | + 32 |
| 199 | +); //Return Joe User |
| 200 | +$Select->Like( |
| 201 | + "Users", |
| 202 | + "Name", |
| 203 | + "Mich" |
| 204 | +); //Return Michael User |
| 205 | + |
| 206 | +//Drop The Table Users |
| 207 | +$Drop->Table("Users"); //Return True |
| 208 | + |
| 209 | + |
| 210 | +function insertUsers(Insert $Insert) |
| 211 | +{ |
| 212 | + //Insert Joe User |
| 213 | + $Insert->Insert( |
| 214 | + "Users", |
| 215 | + ["Name", "Mail", "Pwd", "Age"], |
| 216 | + ["Joe", " [email protected]", "Joe123", 32] |
| 217 | + ); //Return True |
| 218 | + |
| 219 | + //Insert Michael User |
| 220 | + $Insert->Insert( |
| 221 | + "Users", |
| 222 | + ["Name", "Mail", "Pwd", "Age"], |
| 223 | + ["Michael", " [email protected]", "leahciM", 19] |
| 224 | + ); //Return True |
| 225 | +} |
| 226 | + |
| 227 | +``` |
0 commit comments