当前位置: 首页 > news >正文

美丽寮步网站建设价钱私活做网站

美丽寮步网站建设价钱,私活做网站,做哪一类网站能赚钱,如何分析一个网站前言 本章继续介绍MySQL - mysql-connector 驱动。 where 条件语句 如果我们要读取指定条件的数据#xff0c;可以使用 where 语句#xff1a; demo_mysql_test.py 读取 name 字段为 CSDN 的记录#xff1a; import mysql.connectormydb mysql.connector.connect(host…前言 本章继续介绍MySQL - mysql-connector 驱动。 where 条件语句 如果我们要读取指定条件的数据可以使用 where 语句 demo_mysql_test.py 读取 name 字段为 CSDN 的记录 import mysql.connectormydb mysql.connector.connect(hostlocalhost,userroot,passwd123456,databaseCSDN_db ) mycursor mydb.cursor()sql SELECT * FROM sites WHERE name CSDNmycursor.execute(sql)myresult mycursor.fetchall()for x in myresult:print(x)执行代码输出结果为 (1, CSDN, https://www.CSDN.com)也可以使用通配符 % demo_mysql_test.py import mysql.connectormydb mysql.connector.connect(hostlocalhost,userroot,passwd123456,databaseCSDN_db ) mycursor mydb.cursor()sql SELECT * FROM sites WHERE url LIKE %oo%mycursor.execute(sql)myresult mycursor.fetchall()for x in myresult:print(x)执行代码输出结果为 (1, CSDN, https://www.CSDN.com) (2, Google, https://www.google.com)为了防止数据库查询发生 SQL 注入的攻击我们可以使用 %s 占位符来转义查询的条件 demo_mysql_test.py import mysql.connectormydb mysql.connector.connect(hostlocalhost,userroot,passwd123456,databaseCSDN_db ) mycursor mydb.cursor()sql SELECT * FROM sites WHERE name %s na (CSDN, )mycursor.execute(sql, na)myresult mycursor.fetchall()for x in myresult:print(x)排序 查询结果排序可以使用 ORDER BY 语句默认的排序方式为升序关键字为 ASC如果要设置降序排序可以设置关键字 DESC。 demo_mysql_test.py 按 name 字段字母的升序排序 import mysql.connectormydb mysql.connector.connect(hostlocalhost,userroot,passwd123456,databaseCSDN_db ) mycursor mydb.cursor()sql SELECT * FROM sites ORDER BY namemycursor.execute(sql)myresult mycursor.fetchall()for x in myresult:print(x)执行代码输出结果为 (3, Github, https://www.github.com) (2, Google, https://www.google.com) (1, CSDN, https://www.CSDN.com) (5, stackoverflow, https://www.stackoverflow.com/) (4, Taobao, https://www.taobao.com) (6, Zhihu, https://www.zhihu.com)降序排序实例 demo_mysql_test.py 按 name 字段字母的降序排序 import mysql.connectormydb mysql.connector.connect(hostlocalhost,userroot,passwd123456,databaseCSDN_db ) mycursor mydb.cursor()sql SELECT * FROM sites ORDER BY name DESCmycursor.execute(sql)myresult mycursor.fetchall()for x in myresult:print(x)执行代码输出结果为 (6, Zhihu, https://www.zhihu.com) (4, Taobao, https://www.taobao.com) (5, stackoverflow, https://www.stackoverflow.com/) (1, CSDN, https://www.CSDN.com) (2, Google, https://www.google.com) (3, Github, https://www.github.com)Limit 如果我们要设置查询的数据量可以通过 “LIMIT” 语句来指定 demo_mysql_test.py 读取前 3 条记录 import mysql.connectormydb mysql.connector.connect(hostlocalhost,userroot,passwd123456,databaseCSDN_db ) mycursor mydb.cursor()mycursor.execute(SELECT * FROM sites LIMIT 3)myresult mycursor.fetchall()for x in myresult:print(x)执行代码输出结果为 (1, CSDN, https://www.CSDN.com) (2, Google, https://www.google.com) (3, Github, https://www.github.com)也可以指定起始位置使用的关键字是 OFFSET demo_mysql_test.py 从第二条开始读取前 3 条记录 import mysql.connectormydb mysql.connector.connect(hostlocalhost,userroot,passwd123456,databaseCSDN_db ) mycursor mydb.cursor()mycursor.execute(SELECT * FROM sites LIMIT 3 OFFSET 1) # 0 为 第一条1 为第二条以此类推myresult mycursor.fetchall()for x in myresult:print(x)执行代码输出结果为 (2, Google, https://www.google.com) (3, Github, https://www.github.com) (4, Taobao, https://www.taobao.com)删除记录 删除记录使用 “DELETE FROM” 语句 demo_mysql_test.py 删除 name 为 stackoverflow 的记录 import mysql.connectormydb mysql.connector.connect(hostlocalhost,userroot,passwd123456,databaseCSDN_db ) mycursor mydb.cursor()sql DELETE FROM sites WHERE name stackoverflowmycursor.execute(sql)mydb.commit()print(mycursor.rowcount, 条记录删除)执行代码输出结果为 1 条记录删除注意要慎重使用删除语句删除语句要确保指定了 WHERE 条件语句否则会导致整表数据被删除。 为了防止数据库查询发生 SQL 注入的攻击我们可以使用 %s 占位符来转义删除语句的条件 demo_mysql_test.py import mysql.connectormydb mysql.connector.connect(hostlocalhost,userroot,passwd123456,databaseCSDN_db ) mycursor mydb.cursor()sql DELETE FROM sites WHERE name %s na (stackoverflow, )mycursor.execute(sql, na)mydb.commit()print(mycursor.rowcount, 条记录删除)执行代码输出结果为 1 条记录删除更新表数据 数据表更新使用 “UPDATE” 语句 demo_mysql_test.py 将 name 为 Zhihu 的字段数据改为 ZH import mysql.connectormydb mysql.connector.connect(hostlocalhost,userroot,passwd123456,databaseCSDN_db ) mycursor mydb.cursor()sql UPDATE sites SET name ZH WHERE name Zhihumycursor.execute(sql)mydb.commit()print(mycursor.rowcount, 条记录被修改)执行代码输出结果为 1 条记录被修改注意UPDATE 语句要确保指定了 WHERE 条件语句否则会导致整表数据被更新。 为了防止数据库查询发生 SQL 注入的攻击我们可以使用 %s 占位符来转义更新语句的条件 demo_mysql_test.py import mysql.connectormydb mysql.connector.connect(hostlocalhost,userroot,passwd123456,databaseCSDN_db ) mycursor mydb.cursor()sql UPDATE sites SET name %s WHERE name %s val (Zhihu, ZH)mycursor.execute(sql, val)mydb.commit()print(mycursor.rowcount, 条记录被修改)执行代码输出结果为 1 条记录被修改删除表 删除表使用 “DROP TABLE” 语句 IF EXISTS 关键字是用于判断表是否存在只有在存在的情况才删除 demo_mysql_test.py import mysql.connectormydb mysql.connector.connect(hostlocalhost,userroot,passwd123456,databaseCSDN_db ) mycursor mydb.cursor()sql DROP TABLE IF EXISTS sites # 删除数据表 sitesmycursor.execute(sql)
http://www.hkea.cn/news/14317964/

相关文章:

  • wordpress虚拟3d网站tp做网站
  • 郑州七彩网站建设公司 评论app开发网站开发教程
  • 国外移动端网站模板寻加工厂合作订单
  • 网站制作模板下载甘肃省兰州市新闻
  • 河北省建设厅网站网上建设大厅从域名到网站
  • 学网站开发难吗wordpress 舆情管理系统
  • 网站开发系统设计怎么写360神搜网站建设
  • 环保公司网站架构怎么做加强部门网站建设工作
  • 手机网站用什么软件信得过的网站开发推广
  • 优化方案官方网站网站首页的重要性
  • 福州网站怎么做的莆田网站建设
  • 找人做仿网站wordpress chuxin
  • 有什么字体设计网站好如何做推广链接
  • 个人网站备案描述外贸网络营销方案
  • 聊城做网站推广地方WordPress注册插件中文
  • 个人网站盈利模式推广普通话的意义论文
  • 校园网站建设考核最新足球消息
  • 名牌网站设计的图片wordpress 模板下载失败
  • 怎么低成本做网站画册设计网站
  • app 门户网站宜昌市做网站
  • 网站开发语言为免费申请qq靓号
  • 文山网站建设求职简历wordpress 输出缩略图
  • 个人网站设计开题报告品牌型网站设计推荐
  • 厦门的网站建设公司哪家好wordpress 更换空间阿里云
  • 建e网室内设计效果图新中式湖北优化网站建设
  • 肃宁哪里建网站常州规划网站
  • 正规营销型网站定制网站公司seo
  • 鹤壁建设网站推广公司网站建设平台推广
  • 金州新区规划建设局网站网站建设哪个品牌好
  • 中外商贸网站建设百度seo排名在线点击器