美文网首页首页投稿(暂停使用,暂停投稿)
MySQL常用命令(PHP的medoo和Python)

MySQL常用命令(PHP的medoo和Python)

作者: ZYK的轮子 | 来源:发表于2017-09-26 00:01 被阅读0次

PHP快速复制轮子

PHP的medoo

数据库初始化

$database = new medoo(
        array(
        // 必填
        'database_type' => 'mysql',
        'database_name' => 'domain',
        'server' => '127.0.0.1',
        'username' => 'root' ,
        'password' => 'root',

        // 可选参数
        'port' => '3306',
        'charset' => 'utf8',
        // 连接参数可参考官方手册: http://www.php.net/manual/en/pdo.setattribute.php
        'option' => array(
            PDO::ATTR_CASE => PDO::CASE_NATURAL
        )
));

查询

$list = $database->select("wxcontent",
          array(
               "id",
               "wxtitle",
               "wxcontent"
               ), 
          array(
               "AND" => array(  
                    "wxkeyword" => ''
               ),
               "LIMIT" =>1,
               "ORDER"=>"wxtime desc"
          )
     );

更新

$result = $database->update("wxcontent", array(
         "wxkeyword" => $k,
         "wxtime"=>time()
     ),array("id" => $list1[0]['id']));

插入

$result = $database->insert("wxsearch", array(
                   "wxsearchname" => $wxname,
                   "wxcate"=>$cate,
                   'wxpub'=>0
               ));

删除

$database->delete("domain", array(
              "AND" => array(
                  "id" => $_POST['id']
              )
          ));

计算和

$money = $database->sum(
            "answer",
            "money",
            array(
               "AND" => array(  
                    "user_id" => $user_id
               ),
                "ORDER" =>"id DESC"
            )
        );

总数

$total = $database->count("wxcontent", array(
        "wxcate" => $category
    )); 

总数

Python

data = sqlSelect("SELECT id,domain FROM domain WHERE domain = '%s' ORDER by id DESC limit 1" % (domainList[i][1]))

r = sqlInUp("INSERT IGNORE INTO domain(\
                              id,domain,wxtime,price,link,wxstatus) VALUES (\
                              NULL,'%s', '%s','%d', '%s','%d')" % (\
                                   domainList[i][1],time.time(),int(domainList[i][2].replace(unicodeStr('元'), '')),str(domainList[i][0]),status))

sqlInUp(db,"UPDATE wxname SET wxpub = 1 , wxtime = '%s',wxlink = '%s' where wxname2 = '%s' " % (time.time(),wxlink,data[0]['wxname2']))

相关文章

网友评论

    本文标题:MySQL常用命令(PHP的medoo和Python)

    本文链接:https://www.haomeiwen.com/subject/huyjextx.html