时间:2021-07-01 10:21:17 帮助过:3人阅读
<?php class DB { const HOST='127.0.0.1'; const USER='root'; const PASS='root'; const DATA='mooc'; static public $_instance; private function __construct() { mysql_connect(DB::HOST,DB::USER,DB::PASS); mysql_set_charset('utf8'); mysql_select_db(DB::DATA); } public static function getInstance() { if(!self::$_instance instanceof self) { self::$_instance=new self; } return self::$_instance; } } $model=DB::getInstance(); //连接数据库,并且测试 $sql="select * from user"; $res=mysql_query($sql); while($row=mysql_fetch_assoc($res)) { var_dump($row); } ?>
以上就是PHP万能连接数据库方法的详细内容,更多请关注Gxl网其它相关文章!