简体   繁体   中英

Can i use a variante as name for create a new table in MYSQLdb?

I have got this html source :

<div id="ceg">
        <span class="cegnev">THE_NAME</span><br>
        <span class="cim">XXX</span><br>
       YYY  </div>

I want to use this value : THE_NAME as a variante(or constante, doesnt matter), which one i can define the table name in MYSQL.

query = """ 
   CREATE TABLE 'THE_NAME(as variable)' (
  `X` varchar(100) DEFAULT NULL,
  `Y` varchar(100) DEFAULT NULL,
  `Z` varchar(100) DEFAULT NULL,
  `U` varchar(100) DEFAULT NULL,
  `I` varchar(100) DEFAULT NULL,
  `O` varchar(100) DEFAULT NULL,
  `ID` int(10) NOT NULL AUTO_INCREMENT,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8"""

How can i make a variable with this part of html code, and how can I reference to this name in my query code? Is it possible? - Python 2.7

尝试这个....

query = "CREATE TABLE IF NOT EXISTS "+ table_name+ " name VARCHAR(120), date CHAR(22)"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM