Python-insert実行してもエラーはないのにデータが作成されない
下記のようにcommitとcloseを忘れないように
db = connect_to_cloudsql() cursor = db.cursor() cursor.execute('SET NAMES utf8;') cursor.execute('SET CHARACTER SET utf8;') cursor.execute('SET character_set_connection=utf8;') cursor.execute("insert into test.categories (name) values (%s)", (self.request.get('name').encode('utf-8'), )) db.commit() db.close()
Python-現在表示されているページのURLを取得
下記のように記載することで取得可能
class ShowQuestion(webapp2.RequestHandler): def get(self, id): question = Questions.get_by_id( int( id ) ) #数値idの場合intキャストする # いろいろする app = webapp2.WSGIApplication([ ('/questions/(.*)', ShowQuestion) ], debug=True)
Python-mysqlから取得した文字列をjsonで返却する際に??になってしまう
半日悩みました・・・ 下記のようにsql実行前にdbの型を変更すれば良いみたい
db = connect_to_cloudsql() cursor = db.cursor() cursor.execute('SET NAMES utf8;') cursor.execute('select * from test.categories;')
GETとPOSTの違い
①まずURLが違う
・POSTの場合
https://XXXX/form
・GETの場合
https://XXXX/form/?text=xxxx
②送信できるデータ量が違う
・POSTの場合
大量のデータを送信したい場合
HTTP通信で送信されるのでURLの影響を受けることがない
・GETの場合
URLに使用できる2083文字が最大
③使い分けかた
以下の場合はPOSTを使う
・データ量が多い時
・秘匿情報を送る場合
・サーバーでデータを更新する場合
⇒サーバー側に渡す値が見えていたら容易に改ざんできるから
Phalcon-Model作成コマンド
phalcon model --name=t_enquete_salons --get-set --extends=\Epark\App\Model\BaseModel --namespace=Epark\App\Model\MiPortal --doc
CakePHP3-Sessionの使い方
Cakephp3ではSessionComponentが廃止されController内から$this->Sessionができなくなった。代わりに$this->request->session()を使用する ①今までと同じように呼べるように設定
class AppController extends Controller { public function initialize() { parent::initialize(); $this->Session = $this->request->session(); } }
②後は下記のようにするだけ
// 読み $hoge = $this->Session->read('Hoge.hoge'); // 書き $this->Session->write('Hoge.hoge', 'hoge');