Skip to content

Based on the DB class mysqli secondary packaging.Using pretreatment

Notifications You must be signed in to change notification settings

ninetybang2022/DB

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Simple Mysql DB Class

Based on the DB class mysqli secondary packaging.Using pretreatment

    //autoload class 
    spl_autoload_register(function($className){
        $dirName = dirname($className).DIRECTORY_SEPARATOR;
        $className = basename($className);
        $path = str_replace('\\', '/', realpath($dirName.$className.'.php'));
        if(file_exists($path))
        {
            require_once($path);
        }else{
            die('file not found'. $path);
        }
    });
    try
    {
        //Test query Return all result 

        $db = new Lib\DB\DB('localhost', 'root', '', 'article');
        $result = $db->query("SELECT * FROM select_table WHERE aid = ?",
           [
               'types'=>'i',
               'bindParams'=>[
                   'aid'=>1106
               ]
           ]
       );
    //Test Insert The Execute method return affected rows 
    $affected = $db->execute('INSERT INTO insert_table(`name`,weight,base) VALUES(?,?,?)',
        "SELECT * FROM tb_article_detail WHERE aid = ?",
        [
            'types'=>'i',
            'bindParams'=>[
                'aid'=>1106
            ]
        ]
    );
    echo $affected;
    echo '<br />';
    echo $db->getInsertId();
    //Test Insert The Execute method return affected rows 
    $affected = $db->execute('INSERT INTO tb_article_tag_name(`name`,weight,base) VALUES(?,?,?)',
    [
       'types'=>'sii',
       'bindParams'=>[
            'name'=>'66779988',
            'weight'=>100,
            'base'=>0
        ]
    ]);
        echo $affected;
        echo '<br />';
        echo $db->getInsertId();
    }
    catch(Exceptions\DB\ConnectFail $e)
    {
        echo $e->getMessage();
    }
    catch(Exceptions\DB\SQLException $e)
    {
        echo $e->getMessage();
        echo $e->getSql();
    }
    catch(\Exception $e)
    {
        echo $e->getMessage();
    }

About

Based on the DB class mysqli secondary packaging.Using pretreatment

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages