protected function initLink() { $option = $GLOBALS['config']['database']; $this->db = MySQLDBTool::getInstance($option); $this->prefix = $option['prefix']; $this->getFileds(); }
/** * 单例模式的公共接口 * @access public * * @param $params 配置参数 */ public static function getInstance($params) { if (!self::$instance instanceof self) { //实例化时,需要将参数传递到构造方法内 self::$instance = new self($params); } return self::$instance; }
public function sess_open() { $this->db = MySQLDBTool::getInstance($GLOBALS['config']['database']); }
public static function sess_open() { $GLOBALS['db'] = MySQLDBTool::getInstance($GLOBALS['config']['database']); }
/** * 保存数据库到数据库 不可用,最好的方式还是提交到dede * @param array $obj 文章对象 */ function saveToDatabase($obj) { $option = array('host' => 'localhost', 'port' => '3306', 'user' => 'root', 'password' => 'sa123', 'charset' => 'utf8', 'database' => 'dedecmsv57utf8sp1', 'prefix' => 'dede_'); $db = MySQLDBTool::getInstance($option); $sql = "select count(*) from dede_archives where title='{$obj['title']}'"; $count = $db->executeScalar($sql); if ($count > 0) { return false; } $sql1 = "INSERT INTO dede_arctiny(typeid,typeid2,arcrank,channel,senddate,sortrank,`mid`) VALUES ('{$obj["typeid"]}','{$obj["typeid2"]}',0,1,'{$obj["senddate"]}','{$obj["sortrank"]}',1)"; $id = $db->last_insert_id($sql1); if ($id > 0) { $sql2 = "INSERT INTO dede_archives(id,typeid,typeid2,sortrank,flag,ismake,channel,arcrank,click,money,title,shorttitle,color,writer,source,litpic," . "pubdate,senddate,`mid`,keywords,lastpost,scores,goodpost,badpost,voteid,notpost,description,filename,dutyadmin,tackid,mtype,weight) VALUES" . "({$id},'{$obj['typeid']}','{$obj['typeid2']}','{$obj['sortrank']}','{$obj['flag']}','-1','1','0','{$obj['views']}','0','{$obj['title']}','','','{$obj['writer']}'," . "'{$obj['source']}','{$obj['litpic']}','{$obj['pubdate']}','{$obj['pubdate']}','1','{$obj['keywords']}','0','0','0','0','0','0','{$obj['description']}','','1','0','0','0')"; $sql2_r = $db->exec($sql2); $sql3 = "INSERT INTO dede_addonarticle(aid,typeid,body,redirecturl,templet,userip,qianbian,zhichi,zhaoma,gaoxiao,chedan,bujie,chijing,henbang,music) VALUES " . "({$id},{$obj['typeid']},'{$obj['body']}','','','127.0.0.1','{$obj['qianbian']}','{$obj['zhichi']}','{$obj['zhaoma']}','{$obj['gaoxiao']}','{$obj['chedan']}','{$obj['bujie']}','{$obj['chijing']}','{$obj['henbang']}','{$obj['music']}')"; $sql3_r = $db->exec($sql3); if ($sql3_r < 0 or $sql2_r < 0) { $db->exec('delete from dede_archives where id=' . $id); $db->exec('delete from dede_addonarticle where aid=' . $id); $db->exec('delete from dede_arctiny where id=' . $id); return false; } return true; } else { return false; } }