各位大神,下面是我写的一个连接类有些疑问,望解答
class dboperator{ private static $db = null; public static function getinstance() { try { if($db == null) { $db = new pdo("mysql:host=".localhost.";dbname=".test,root,root, array(pdo::attr_persistent => true)); $db->setattribute(pdo::attr_case, pdo::case_upper); } return $db; } catch (exception $e) { die("数据库连接失败!".$e->getmessage()); } } function __destruct () { $db = null; } /** * 次函数主要是以集合的形式返回,或插入集合数据。 * @param unknown $strsql * @param unknown $array */ public static function executearraysql($strsql, $array) { try { dboperator::getinstance()->begintransaction(); $stms = dboperator::getinstance()->prepare($strsql); foreach ($array as $value) { $stms->execute($value); } dboperator::getinstance()->commit(); }catch (pdoexception $e) { print "error: " . $e->getmessage() . "<br/>"; die(); } } /** * 次函数主要是用来指定条件查询 * @param unknown $strsql * @param unknown $array 查询参数 */ public static function executesql($strsql,$array) { try { $stms = dboperator::getinstance()->prepare($strsql); $bret = $stms->execute($array); return $bret; }catch (pdoexception $e) { print "error: " . $e->getmessage() . "<br/>"; die(); } }}
$db 都改成 self::$db
private static $db = null;
这个不要改
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号