This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php namespace Repositories\Pokemon; | |
// model\Repositories\Pokemon\PokemonRepositoryServiceProvider.php | |
use Entities\Pokemon; | |
use Repositories\Pokemon\PokemonRepository; | |
use Illuminate\Support\ServiceProvider; | |
/** | |
* Register our Repository with Laravel | |
* 註冊我們的資源庫到 Laravel |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php namespace Repositories\Pokemon; | |
// model/Repositories/Pokemon/PokemonRepository.php | |
use Illuminate\Database\Eloquent\Model; | |
use \stdClass; | |
/** | |
* Our pokemon repository, containing commonly used queries | |
* 我們的 pokemon 資源庫,包含一些常用的查詢 | |
*/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php namespace Repositories\Pokemon; | |
// model/Repositories/Pokemon/PokemonInterface.php | |
/** | |
* A simple interface to set the methods in our Pokemon repository, nothing much happening here | |
* 簡單的介面去設定我們的 Pokemon 資源庫 | |
*/ | |
interface PokemonInterface | |
{ | |
public function getPokemonById($pokemonId); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php namespace Entities; | |
// model/Entities/Pokemon.php | |
class Pokemon extends \Eloquent { | |
/** | |
* The database table used by the model. | |
* | |
* @var string | |
*/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 引用MySQL函式庫 | |
var mysql = require('mysql'); | |
// 建立資料庫連線池 | |
var pool = mysql.createPool({ | |
user: '資料庫帳號', | |
password: '資料庫密碼', | |
host: '主機位置', | |
port: '資料庫port' | |
database: '資料庫名稱', | |
// 無可用連線時是否等待pool連線釋放(預設為true) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 關閉資料庫連線 | |
connection.end(function(err) { | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 引用MySQL函式庫 | |
var mysql = require('mysql'); | |
// 資料庫設定 | |
var db_config = { | |
user: '資料庫帳號', | |
password: '資料庫密碼', | |
host: '主機位置', | |
port: '資料庫port' | |
database: '資料庫名稱' | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// 連線Memcache | |
$meminstance = new Memcache(); | |
$meminstance->pconnect('localhost', 11211); | |
// 存放資料到Memcache | |
$cache_key = 'hello_memcache'; | |
$cache_data = 'cache_info'; | |
$meminstance->set($cache_key, $cache_data, 0, 600); | |
// 讀取Memcached存放的資料 | |
$res = $meminstance->get($cache_key); |