teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

2

自分で調べたことの追記

2016/11/19 22:58

投稿

nzaki
nzaki

スコア9

title CHANGED
File without changes
body CHANGED
@@ -29,4 +29,11 @@
29
29
  python,mysqlともに勉強中なのですが、これは構文エラーということでしょうか。
30
30
  mysqlでは上記のように'%s'指定してパラメータを渡すことはできないのでしょうか?
31
31
 
32
- よろしくお願いします。
32
+ よろしくお願いします。
33
+
34
+ 追記:
35
+ [http://nonbiri-tereka.hatenablog.com/entry/2014/08/17/104650
36
+ ](http://nonbiri-tereka.hatenablog.com/entry/2014/08/17/104650)
37
+
38
+ こちらのサイトを見ると普通にMySQLでも%s指定使えるようですね・・・。
39
+ バージョンとか見直してみます。

1

ソースコード追加

2016/11/19 22:58

投稿

nzaki
nzaki

スコア9

title CHANGED
File without changes
body CHANGED
@@ -3,19 +3,30 @@
3
3
  実行するとエラーになってしまうのですが、
4
4
  どなたかご教授いただけないでしょうか。
5
5
 
6
- エラーメッセージ
6
+ ###エラーメッセージ
7
+ ```
8
+ _mysql_exceptions.ProgrammingError:
9
+ (1064, "You have an error in your SQL syntax;
7
- _mysql_exceptions.ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '%s' at line 1")
10
+ check the manual that corresponds to your MySQL server version for the right syntax to use near '%s' at line 1")
11
+ ```
12
+ ###ソースコード
13
+ ```
14
+ # -*- coding: utf-8 -*-
15
+ import MySQLdb
8
16
 
9
- スコード
17
+ # DBに接続しカソルを取得する
18
+ connect = MySQLdb.connect(host='localhost',port=3306,user='test_user',passwd='test_passwd',db='test_db',charset='utf8')
19
+ cursor = connect.cursor()
10
20
  sql = "select * from test_table where id = %s"
11
21
  whereid = "1"
12
22
  cursor.execute(sql, [whereid]) # select文を実行
13
-
23
+ ```
24
+ ###バージョン
25
+ ```
26
+ python:3.4
27
+ mysql:5.5.52
28
+ ```
14
29
  python,mysqlともに勉強中なのですが、これは構文エラーということでしょうか。
15
30
  mysqlでは上記のように'%s'指定してパラメータを渡すことはできないのでしょうか?
16
31
 
17
- バージョン
18
- python:3.4
19
- mysql:5.5.52
20
-
21
32
  よろしくお願いします。