PHP code example of dinodev / my-sql

1. Go to this page and download the library: Download dinodev/my-sql library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

dinodev / my-sql example snippets


use DinoDev\MySql\Classes\MySql;

//Creating MySql
$MySql = new MySql(
    "localhost" /* Hostname */,
    "root"      /* Username */,
    "MySql"     /* Password */,
    "world"     /* Database */,
    $state      /* State of MySql Connect (Success or Error) */
);

$Create = new Create(
    $MySql /* Here, you pass the MySql Object */
);

//Create Table
$Create->Table(
    "TableName"                    /* The Table Name*/,
    ["Value 1", "Value2"]          /* The Name Of Values */,
    ["varchar(20)", "varchar(50)"] /* The Type Of Values*/
);

$Drop = new Drop(
    $MySql /* Here, you pass the MySql Object */
);

//Drop Table
$Drop->Table(
    "TableName" /* The Table Name */
);

$Select = new Select(
    $MySql /* Here, you pass the MySql Object*/
);

//Select All
$Select->All(
    "TableName" /* The Table Name */,
    "Order By"   /* Order By (Optional) */,
    5           /* The Limit of Rows (Optional) */
);

//Select Where
$Select->Where(
    "TableName" /* The Table Name */,
    "Field",    /* The Field Name */
    "Value",    /* Value */
    "Order By"   /* Order By (Optional) */,
    5           /* The Limit of Rows (Optional) */
);

//Select Like
$Select->Like(
    "TableName" /* The Table Name */,
    "Field",    /* The Field Name */
    "Value",    /* Value */
    "Order By"   /* Order By (Optional) */,
    5           /* The Limit of Rows (Optional) */
);

$Insert = new Insert(
    $MySql /* Here, you pass the MySql Object*/
);

//Insert
$Insert->Insert(
    "TableName"                  /* The Table Name */,
    [ "Field One", "Field Two" ] /* The Fields Name */ ,
    [ "Value One", "Value Two" ] /* Values */
);

//Delete Where
$Delete->Where(
    "TableName" /* The Table Name */,
    "Field"     /* The Field Name */,
    "Value",    /* Value */
);

//Delete Like
$Delete->Like(
    "TableName" /* The Table Name */,
    "Field",    /* The Field Name */
    "Value",    /* Value */
);



use DinoDev\MySql\Classes\{
    MySql,
    Create,
    Drop,
    Select,
    Insert,
    Delete
};



$Create = new Create($MySql);

$Drop = new Drop($MySql);
$Select = new Select($MySql);

$Insert = new Insert($MySql);

$Delete = new Delete($MySql);

//Creating Table
$Create->Table(
    "Users",
    ["Name",         "Mail",         "Pwd",          "Age"],
    ["varchar(20)",  "varchar(50)",  "varchar(70)",  "tinyint"]
); //Return True

//Insert 2 Users
insertUsers($Insert);

//Delete All Users
$Delete->All("Users"); //Return True

//Insert 2 Users
insertUsers($Insert);

$Delete->Where(
    "Users",
    "Age",
    32
); //Return True

$Delete->Like(
    "Users",
    "Name",
    "Mich"
); //Return True

//Insert 2 Users
insertUsers($Insert);

$Select->All("Users"); //Return All Users
$Select->All("Users", "mail"); //Return All Users (Order By Mail)
$Select->All("Users", limit: 1); //Return Joe User (Limit 1)

$Select->Where(
    "Users",
    "Age",
    32
); //Return Joe User
$Select->Like(
    "Users",
    "Name",
    "Mich"
); //Return Michael User

//Drop The Table Users
$Drop->Table("Users"); //Return True 


function insertUsers(Insert $Insert)
{
    //Insert Joe User
    $Insert->Insert(
        "Users",
        ["Name", "Mail",            "Pwd",    "Age"],
        ["Joe",  "[email protected]", "Joe123", 32]
    ); //Return True

    //Insert Michael User
    $Insert->Insert(
        "Users",
        ["Name",     "Mail",              "Pwd",    "Age"],
        ["Michael",  "[email protected]", "leahciM", 19]
    ); //Return True
}