aloyuu
V2EX  ›  问与答

普通类调用单例类 , 操作数据库 , 失败

  •  
  •   aloyuu · Jan 21, 2019 · 1078 views
    This topic created in 2691 days ago, the information mentioned may be changed or developed.

    https://s2.ax1x.com/2019/01/21/kieecn.png https://s2.ax1x.com/2019/01/21/kieZ1s.png

    class connectModel 单例数据库连接类 public static function getInstance() 来初始化自身

    class baseModel 普通数据库操作

    $conn = connectModel::getInstance(); $stmt = $conn->prepare("SELECT id,title,sname,hp from menu where st = 1 order by sort asc");

    错误提示: Fatal error: Uncaught Error: Call to undefined method connectModel::prepare()

    目的是很多实例化类中, 使用单例数据库连接, 避免数据库多次连接

    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5578 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 48ms · UTC 06:34 · PVG 14:34 · LAX 23:34 · JFK 02:34
    ♥ Do have faith in what you're doing.