mysql

MySQL update, skip blank fields with PDO

邮差的信 提交于 2021-02-18 17:09:37
问题 I would like to update a MySQL row via the form below. The form works great as is but, if I leave a field blank, it changes the field in MySQL to blank as well. I would like to update the sql but skip over any fields that are blank. I have read a few ways of doing this but they didn't seem logical. I.e. using if statements in the sql string itself. (Having MySQL do the work that should be done in PHP). if($_SERVER['REQUEST_METHOD'] != 'POST') { echo '<form method="post" action=""> ID: <input

MySQL update, skip blank fields with PDO

我们两清 提交于 2021-02-18 17:09:27
问题 I would like to update a MySQL row via the form below. The form works great as is but, if I leave a field blank, it changes the field in MySQL to blank as well. I would like to update the sql but skip over any fields that are blank. I have read a few ways of doing this but they didn't seem logical. I.e. using if statements in the sql string itself. (Having MySQL do the work that should be done in PHP). if($_SERVER['REQUEST_METHOD'] != 'POST') { echo '<form method="post" action=""> ID: <input

MySQL update, skip blank fields with PDO

Deadly 提交于 2021-02-18 17:07:57
问题 I would like to update a MySQL row via the form below. The form works great as is but, if I leave a field blank, it changes the field in MySQL to blank as well. I would like to update the sql but skip over any fields that are blank. I have read a few ways of doing this but they didn't seem logical. I.e. using if statements in the sql string itself. (Having MySQL do the work that should be done in PHP). if($_SERVER['REQUEST_METHOD'] != 'POST') { echo '<form method="post" action=""> ID: <input

Whitespace in a database field is not removed by trim()

点点圈 提交于 2021-02-18 16:58:06
问题 I have some whitespace at the begining of a paragraph in a text field in MySQL. Using trim($var_text_field) in PHP or TRIM(text_field) in MySQL statements does absolutely nothing. What could this whitespace be and how do I remove it by code? If I go into the database and backspace it out, it saves properly. It's just not being removed via the trim() functions. 回答1: function UberTrim($s) { $s = preg_replace('/\xA0/u', ' ', $s); // strips UTF-8 NBSP: "\xC2\xA0" $s = trim($s); return $s; } The

SQLzoo JOIN tutorial #13

五迷三道 提交于 2021-02-18 16:53:17
问题 I have been working on the SQLzoo problems but having trouble with the last one in the JOIN tutorial question #13 - List every match with the goals scored by each team as shown. Link: http://sqlzoo.net/wiki/The_JOIN_operation In the sample code they gave, it uses a case. I modified it like this: SELECT game.mdate, game.team1, CASE WHEN goal.teamid=game.team1 THEN 1 ELSE 0 END score1, game.team2, CASE WHEN goal.teamid=game.team2 THEN 1 ELSE 0 END score2 FROM game, goal WHERE game.id=goal

SQL 性能起飞了!

强颜欢笑 提交于 2021-02-18 15:37:51
点击上方 Java后端 , 选择 设为星标 优质文章,及时送达 这篇文章总结了 52 条 SQL 性能优化技巧,用简洁明了的语言介绍给大家,不废话全是干货,需要的可以收藏,退出。不不不,收藏,看完再退出。 1. 对查询进行优化,应尽量避免全表扫描,首先应考虑在 where 及 order by 涉及的列上建立索引。 2. 应尽量避免在 where 子句中对字段进行 null 值判断,创建表时NULL是默认值,但大多数时候应该使用NOT NULL,或者使用一个特殊的值,如0,-1作为默 认值。 3. 应尽量避免在 where 子句中使用!=或<>操作符, MySQL只有对以下操作符才使用索引:<,<=,=,>,>=,BETWEEN,IN,以及某些时候的LIKE。 关于 MySQL 相关的文章和教程发布了很多,关注微信公众号 Java后端,回复 666 下载就行了。 4. 应尽量避免在 where 子句中使用 or 来连接条件, 否则将导致引擎放弃使用索引而进行全表扫描, 可以 使用UNION合并查询: select id from t where num = 10 union all select id from t where num = 20 5. in 和 not in 也要慎用,否则会导致全表扫描,对于连续的数值,能用 between 就不要用 in 了: Select id

2021新年最新分享:阿里Java岗5轮技术面经整理

北慕城南 提交于 2021-02-18 15:37:05
写在前面 又到了收割Offer的季节,你准备好了吗?曾经的我,横扫各个大厂的Offer。还是那句话:进大厂临时抱佛脚是肯定不行的,一 定要注重平时的总结和积累,多思考,多积累,多总结,多复盘,将工作经历真正转化为自己的工作经验。 面经分享 今天给大家分享一个面试大厂的完整面经,小伙伴们可以对照下,这些面试题自己是否都会了呢? 同时后面还整理了这些问题的一套面试解析文档及架构学习笔记资料,有需要的小伙伴 一轮技术面(90分钟) hashmap和hashtable区别 为什么会产生死锁 jvm类加载 java反射获取私有属性,改变值 反射用途 所用数据库 项目难点,问题 如何解决项目中遇到的问题 项目中遇到的最难解决的地方 二轮技术面(120分钟) 讲项目 数据库乐观锁使用 如何分库分表 MySQL极限 HashMap源码 设计一个线程安全的HashMap 快排的实现,时间复杂度和空间复杂度 会什么算法 如何把项目变成SOA架构 Spring源码,最深刻的模块,aop用途 JVM内存模型 垃圾回收机制 项目中查看垃圾回收 三轮技术面(150分钟) ConcurrentHashMap底层原理? 手写一个LRU(用LinkedHashMap) HashMap底层数据结构? JDK1.8中的HashMap为什么用红黑树不用普通的AVL树? 为什么在8的时候链表变成树?

不满于CRUD,五面阿里成功斩获Offer!鬼知道我怎么过来的!

孤者浪人 提交于 2021-02-18 14:59:15
写在前面 又到了收割Offer的季节,你准备好了吗?曾经的我,横扫各个大厂的Offer。还是那句话:进大厂临时抱佛脚是肯定不行的,一 定要注重平时的总结和积累,多思考,多积累,多总结,多复盘,将工作经历真正转化为自己的工作经验。 面经分享 今天给大家分享一个面试大厂的完整面经,小伙伴们可以对照下,这些面试题自己是否都会了呢? 同时后面还整理了这些问题的一套面试解析文档及架构学习笔记资料,有需要的小伙伴点赞收藏后,添加小助理vx:bjmsb2020 即可 一轮技术面(90分钟) hashmap和hashtable区别 为什么会产生死锁 jvm类加载 java反射获取私有属性,改变值 反射用途 所用数据库 项目难点,问题 如何解决项目中遇到的问题 项目中遇到的最难解决的地方 二轮技术面(120分钟) 讲项目 数据库乐观锁使用 如何分库分表 MySQL极限 HashMap源码 设计一个线程安全的HashMap 快排的实现,时间复杂度和空间复杂度 会什么算法 如何把项目变成SOA架构 Spring源码,最深刻的模块,aop用途 JVM内存模型 垃圾回收机制 项目中查看垃圾回收 三轮技术面(150分钟) ConcurrentHashMap底层原理? 手写一个LRU(用LinkedHashMap) HashMap底层数据结构? JDK1.8中的HashMap为什么用红黑树不用普通的AVL树?

How to check if “'MySQL server has gone away'”

廉价感情. 提交于 2021-02-18 14:39:45
问题 cursor.execute(sql) File "/usr/lib64/python2.6/site-packages/MySQLdb/cursors.py", line 173, in execute self.errorhandler(self, exc, value) File "/usr/lib64/python2.6/site-packages/MySQLdb/connections.py", line 36, in defaulterrorhandler raise errorclass, errorvalue _mysql_exceptions.OperationalError: (2006, 'MySQL server has gone away') I'm running an infinite loop, but every 30-60 minutes, I get the error above. I think I want to add a conditional at the start of each loop iteration to check

How to check if “'MySQL server has gone away'”

我与影子孤独终老i 提交于 2021-02-18 14:38:33
问题 cursor.execute(sql) File "/usr/lib64/python2.6/site-packages/MySQLdb/cursors.py", line 173, in execute self.errorhandler(self, exc, value) File "/usr/lib64/python2.6/site-packages/MySQLdb/connections.py", line 36, in defaulterrorhandler raise errorclass, errorvalue _mysql_exceptions.OperationalError: (2006, 'MySQL server has gone away') I'm running an infinite loop, but every 30-60 minutes, I get the error above. I think I want to add a conditional at the start of each loop iteration to check