示例#1
0
文件: model.php 项目: smith46102/koda
 /**
  * Basic find models, uses $where as array of conditions
  * $order and $limit to make query
  *
  * @param array $where
  * @param string $order
  * @param string $limit
  * @return \Collection
  */
 public static function find(array $where = null, $order = null, $limit = null)
 {
     if ($sql = Mysql::prepareSelect(static::getTable(), $where, $order, $limit)) {
         return Mysql::select($sql, get_called_class());
     }
     return null;
 }
示例#2
0
 * User: shaoting
 * Date: 15/7/26
 * Time: 下午5:25
 */
include "../Visitor.php";
$_GET['userId'] = getUserId();
$KeyList = array('userId', 'footprintId');
foreach ($KeyList as $k => $v) {
    if (!isset($_GET[$v])) {
        $res = ['ok' => 0, 'error' => "param invalid "];
        echo json_encode($res);
        die;
    }
}
$mysql = new Mysql();
$result = $mysql->select("*", "footprint", "`footId`", "'{$_GET['footprintId']}'");
if ($result) {
    if ($result['userId'] == $_GET['userId']) {
        $myMemcache = new MyMemcache();
        $footprintId = $result['id'];
        $removeFootprint = "delete from footprint where id={$footprintId}";
        //echo $removeFootprint;
        $mysql->query($removeFootprint);
        $myMemcache->delete($_GET['userId'] . "foot" . $result['footId']);
        if ($myMemcache->get("like" . $result['footId']) && $myMemcache->get("like" . $result['footId']) == 1) {
            //$removeFoot="delete from foot where id={$result['footId']}";
            //$mysql->query($removeFoot);
        }
        echo json_encode(['ok' => 1]);
    } else {
        echo json_encode(['ok' => 0, 'error' => "no permission"]);
示例#3
0
        $res = ['ok' => 0, 'error' => $error];
        echo json_encode($res);
        die;
    }
    if (isset($key)) {
        $key .= ",`" . $v . "`";
        $value .= ",'" . mysql_real_escape_string($_POST[$v]) . "'";
    } else {
        $key = "`" . $v . "`";
        $value = "'" . mysql_real_escape_string($_POST[$v]) . "'";
    }
}
$mysql = new Mysql();
//连接数据库
$userName = $_POST['userName'];
$result = $mysql->select("*", 'user', '`username`', "'{$userName}'");
if (!$result) {
    $mysql->replace("user", "{$key}", "{$value}");
    $userId = mysql_insert_id();
    $mysql->close();
} else {
    $res = ['ok' => 0, 'error' => 'username existed'];
    echo json_encode($res);
    die;
}
$myMemcache = new MyMemcache();
$expireTime = 7 * 24 * 3600;
$token = md5(uniqid(rand(), TRUE));
$myMemcache->set("u" . $userId, $token, $expireTime);
$myMemcache->set($token, $userId, $expireTime);
$myMemcache->close();
示例#4
0
<?php

/**
 * Created by PhpStorm.
 * User: shaoting
 * Date: 15/7/26
 * Time: 下午9:57
 */
include "../Visitor.php";
$userId = getUserId();
$mysql = new Mysql();
$result = $mysql->select("*", "`user_regular`", "`user_id`", "{$userId}");
if ($result) {
    //echo "SELECT * FROM user_regular u inner join regular r WHERE r.id=u.regular_id and u.user_id={$userId}";
    $regular_array = $mysql->query_array("select * from (SELECT u.*,r.host,r.threshold FROM user_regular u inner join regular r WHERE r.id=u.regular_id and u.user_id={$userId} order by time desc ) a group by host");
} else {
    //echo "select * from (SELECT *,count(r.id) count FROM user_regular u inner join regular r WHERE r.id=u.regular_id group by r.id)a limit 10";
    //无规则时返回大家用的最多的规则
    $regular_array = $mysql->query_array("select * from (SELECT u.*,r.host,r.threshold,count(r.id) count FROM user_regular u inner join regular r WHERE r.id=u.regular_id group by r.id)a group by host order by time desc limit 10");
}
foreach ($regular_array as $v) {
    $regular = new Regular($v);
    $regulars[] = $regular;
}
$res = [ok => 1, data => $regulars];
echo json_encode($res);
示例#5
0
 public static function fetchAll()
 {
     return Mysql::select('SELECT * FROM music');
 }
示例#6
0
{
    public function select()
    {
        echo 'The class "', __METHOD__, '" was initiated!<br />';
    }
}
class Mssql extends Database
{
    public function connect()
    {
        echo 'The class "', __METHOD__, '" was initiated! User : '******' Pass : '******'<br />';
    }
    public function select()
    {
        echo 'The class "', __METHOD__, '" was initiated!<br />';
    }
}
$db = new Mysql();
$db->authentication('root', 'root');
$db->connect();
$db->select();
echo "<hr>";
$db = new Postgresql();
$db->authentication('root', 'root');
$db->connect();
$db->select();
echo "<hr>";
$db = new Mssql();
$db->authentication('ali', 'root');
$db->connect();
$db->select();