티스토리 뷰
php mysql 혹은 mariaDB 프로그래밍을 처음 할때 한번쯤 경험하는 것이 바로 싱글쿼트 single quote 에러일 것이다.
쿼리문은 제대로 쓴거 같은데 왜 에러가 나지...
하고 에러문을 보니
title=adidas Women's Cloudfoam QT Racer w Running Shoe, Clear Onix/White/Clear Onix, 8 M US
Error: INSERT INTO godo_item (srl,cateCd,goodsNm,create_at) VALUES ('B01HSIH68K','001','adidas Women's Cloudfoam QT Racer w Running Shoe, Clear Onix/White/Clear Onix, 8 M US',now())
You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 's Cloudfoam QT Racer w Running Shoe, Clear Onix/White/Clear Onix, 8 M US',now())' at line 2title=Zhuanglin Women's Quick Drying Aqua Water Shoes
해석을 해보니 's Cloudfoam 근처에서 에러가 난다고 써있다.
원인은 바로 Women's Cloudfoam 이였다.
특히 외국은 Men's Women's 처럼 ' 를 많이 쓴다.
흠.. 저 처리를 해줘야 되는구나..
mybatis 같은 경우는 변수가 통째로 문자열로 취급하여 문제 없으나 php는 변수에 대입하는 방식이라 ' 가 걸린다.
그래서 ' 처리를 해줘야 하는데 escape 하면 된다.
즉, \' 이런식으로..
php에서는 이런걸 해주는 addslash 함수가 있다.
그래서
$title=addslash($title);
했더니 insert가 오류 안나고 잘 되었다.
쿼리문은 제대로 쓴거 같은데 왜 에러가 나지...
하고 에러문을 보니
title=adidas Women's Cloudfoam QT Racer w Running Shoe, Clear Onix/White/Clear Onix, 8 M US
Error: INSERT INTO godo_item (srl,cateCd,goodsNm,create_at) VALUES ('B01HSIH68K','001','adidas Women's Cloudfoam QT Racer w Running Shoe, Clear Onix/White/Clear Onix, 8 M US',now())
You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 's Cloudfoam QT Racer w Running Shoe, Clear Onix/White/Clear Onix, 8 M US',now())' at line 2title=Zhuanglin Women's Quick Drying Aqua Water Shoes
해석을 해보니 's Cloudfoam 근처에서 에러가 난다고 써있다.
원인은 바로 Women's Cloudfoam 이였다.
특히 외국은 Men's Women's 처럼 ' 를 많이 쓴다.
흠.. 저 처리를 해줘야 되는구나..
mybatis 같은 경우는 변수가 통째로 문자열로 취급하여 문제 없으나 php는 변수에 대입하는 방식이라 ' 가 걸린다.
그래서 ' 처리를 해줘야 하는데 escape 하면 된다.
즉, \' 이런식으로..
php에서는 이런걸 해주는 addslash 함수가 있다.
그래서
$title=addslash($title);
했더니 insert가 오류 안나고 잘 되었다.
'php' 카테고리의 다른 글
[php] 엑셀파일 db에 insert (0) | 2018.04.19 |
---|---|
php 엑셀 읽기 쓰기 - PHPExcel (0) | 2018.04.19 |
php 파일명만 추출. 확장자 제거 (0) | 2018.04.13 |
php 한글 header (0) | 2018.04.10 |
초보자를 위한 php,mysql,apache 본문 소스 코드 (0) | 2018.03.25 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- xe addon
- C
- 플러터
- 파이썬
- 파싱
- 스크래핑
- proc
- KG
- 인포믹스
- 포인터
- C언어
- ocajp
- 문자열
- EC
- xe애드온
- XE
- 라이믹스 모듈
- ocjap
- XE3
- JDBC
- 프로씨
- php
- 오라클
- Python
- MySQL
- webix
- esql
- 이클립스
- 자바 smtp
- 자바
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
글 보관함