public function setData(array $data) { $mysql = new MMysql($this->_config['db']); $mysql->startTrans(); $mysql->insert('news', $data); $mysql->commit(); }
private function setData($json) { $mysql = new MMysql($this->_config['db']); $_ary = json_decode($json); $isExists = $mysql->field('count(1) as ct')->where(array('sku' => '"' . $_ary->sku . '"', 'lotid' => array('"' . $_ary->lotid . '"', '=', 'and'), 'supplyid' => array('"' . $_ary->supplyid . '"', '=', 'and')))->select('yy_reports'); if ((int) $isExists[0]['ct'] == 0) { $data = array('sku' => $_ary->sku, 'lotid' => $_ary->lotid, 'spec' => $_ary->spec, 'cdname' => $_ary->cdname, 'cdcode' => $_ary->cdcode, 'supplyid' => $_ary->supplyid, 'spname' => $_ary->spname, 'spcode' => $_ary->spcode, 'picpath' => $_ary->picpath); $mysql->insert('yy_reports', $data); return true; } return false; }
<?php include 'MMysql.php'; $mysql = new MMysql(); //插入 $data = array('name' => "忽必烈", 'sex' => 1, 'tel' => 16558656367); $mysql->insert('user_list', $data); //查询 $res = $mysql->field(array('name', 'sex', 'tel'))->select('user_list'); // $res = $mysql->field('sid,aa,bbc') // ->order('sid desc,aa asc') // ->where('sid=101 or aa>123455') // ->limit(1,2) // ->select('t_table'); echo "xxxxx query=> " . count($res) . " first person: " . $res[1]['name']; echo "<br>"; //获取最后执行的sql语句 $sql = $mysql->getLastSql(); //直接执行sql语句 $sql = "show tables"; $res = $mysql->doSql($sql); echo "<br>"; echo "xxxxx show=> " . count($res) . " first: " . $res[0];