PHP Singleton PDO

后端 未结 5 1564
臣服心动
臣服心动 2021-02-09 08:45

from http://www.php.net/manual/en/class.pdo.php

###### config.ini ######
db_driver=mysql
db_user=root
db_password=924892xp

[dsn]
host=localhost
port=3306
dbname         


        
5条回答
  •  时光取名叫无心
    2021-02-09 09:16

    setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT);
            } catch(PDOException $error) {
                echo $error->getMessage();
            }
        }
    
    }
    public static function getInstance() {
        if(empty(self::$instance)) {
            try {
                new DB();
                //var_dump(self::$instance);
            } catch(PDOException $error) {
                echo $error->getMessage();
            }
        }
        //var_dump(self::$instance);
        return self::$instance;
    }
    
    private function __clone() {
        // Stopping Clonning of Object
    }
    
    private function __wakeup() {
        // Stopping unserialize of object
    }
    }
    ?>
    prepare($sqlExample);
    $stm->execute();
    $result = $stm->fetchAll(PDO::FETCH_ASSOC);
    
    var_dump($db);
    var_dump($db1);
    echo "
    ";
    print_r($result);
    echo "
    "; } catch (Exception $e) { print $e->getMessage(); } ?>

提交回复
热议问题