http___blog.petkanski.com_2011_04_mysqlrealescapestring.html_1.xml
http___inspirevolunteer.co.uk_volunteer-in-transylvania-by-kirsteen-volunteer-advisor_.xml
1.1 2.1 2.2 2.3 3.1 4.1 4.2 5.1 5.2 5.3 6.1 7.1 8.1 9.1 9.2 10.1 11.1 12.1 12.2
По темата.. Днес ми се наложи да сравнявам предимства и недостатъци на няколко framework-чета. При едното от тях липсваше вграден database model, така че се наложи да ползвам нещо отделно. В конкретният случай се спрях на PDO и реших да си напиша няколко базови класчета.. За да съкратя историята, направо ще ви синтезирам това което Ви е нужно да знаете ;) При МySQL имате два вида сравнение на низ от символи (string) - това са равенство и сравнение с pattern, посредством LIKE или регулярен израз. В моят случай използвам LIKE, защото е най-бърз за имплементация и защото отговаря на нуждите ми и няма смисъл от overengineering. Случаят е простичък - имам данни в базата, имам и търсачка която търси с LIKE. Това което ме изненада, беше, че mysql_real_escape_string() допусна символи в низа които са със специално значение, а именно - символите за процент (%) и долно тире (_). В най-общият случай - при вмъкване на данни или сравнение със равенство това не ви бърка, но когато ползвате LIKE нещата стоят по малко по-различен начин. Получи се ситуация, при която аз търся в базата данни къде е споменато "100%", но тъй като символът за процент не се escape-ва, се получава, че търся низ който съдържа 100. SELECT * FROM SomeTable WHERE `textField` LIKE '%100%%' Очевидно, това не е поведението което би се очаквало, след като имаш илюзията, че данните са ти escape-нати правилно. След като разбрах какъв е проблема си помислих, че може би е проблем на mysql_real_escape_string() и веднага си отворих http://www.php.net/mysql_real_escape_string - но се оказа, че това е очаквано поведение. В документацията на функцията ясно са писали, че тя "prepends backslashes to the following characters: \x00, \n, \r, \, ', " and \x1a". Ето го точният цитат от сайта: Може би символите за wildcard попадат точно в тези изключения които са споменали.mysql_real_escape_string() calls MySQL's library function mysql_real_escape_string, which prepends backslashes to the following characters: \x00, \n, \r, \, ', " and \x1a.This function must always (with few exceptions) be used to make data safe before sending a query to MySQL. Изводът е простичък - винаги минавайте един профилактичен str_ireplace() или preg_replace() на данните които използвате при генериране на заявка за търсене в базата данни за да няма изненади. Нека това, че ползвате prepared statements не ви дава чувство за сигурност.
1.1 2.1 3.1 4.1 5.1 6.1 7.1 8.1 9.1 9.2 10.1 10.2 10.3 11.1 11.2 11.3 12.1 12.2 13.1 13.2 14.1 15.1
Volunteer in Transylvania, by Kirsteen, Volunteer Advisor Warning: mysql_real_escape_string(): No such file or directory in /var/sites/i/inspirevolunteer.co.uk/public_html/wp-content/themes/nouveau/includes/shortcodes/shortcodes.php on line 3244 Warning: mysql_real_escape_string(): A link to the server could not be established in /var/sites/i/inspirevolunteer.co.uk/public_html/wp-content/themes/nouveau/includes/shortcodes/shortcodes.php on line 3244 Warning: mysql_real_escape_string(): No such file or directory in /var/sites/i/inspirevolunteer.co.uk/public_html/wp-content/themes/nouveau/includes/shortcodes/shortcodes.php on line 3244 Warning: mysql_real_escape_string(): A link to the server could not be established in /var/sites/i/inspirevolunteer.co.uk/public_html/wp-content/themes/nouveau/includes/shortcodes/shortcodes.php on line 3244 Warning: mysql_real_escape_string(): No such file or directory in /var/sites/i/inspirevolunteer.co.uk/public_html/wp-content/themes/nouveau/includes/shortcodes/shortcodes.php on line 3309 Warning: mysql_real_escape_string(): A link to the server could not be established in /var/sites/i/inspirevolunteer.co.uk/public_html/wp-content/themes/nouveau/includes/shortcodes/shortcodes.php on line 3309 If you are looking for an opportunity to volunteer abroad for just 2-4 weeks and if you would prefer to volunteer within Europe, then Romania would be an ideal option for you. Inspire offer a fantastic opportunity to teach and support children living in care homes in Romania and you can volunteer for just 2 weeks, although an ideal duration would be 4 weeks. Given the relatively short travel time between UK and Romania it is a perfect destination for people who want to participate in a short-term volunteer placement. We work with the child protection services in Transylvania and we offer the opportunity for volunteers to help at children’s care homes in the region. This is a fantastic programme where volunteers are encouraged to play games with the children, arrange arts and crafts, dance, and drama and music activities. This project is ideal for anyone with a background in social work, child welfare or teaching. The care homes we work with are all located in the beautiful Transylvania region of Romania which is famous for its spectacular castles, thermal-spring spas, and charming villages set at the foothills of the Carpathian Mountains. The region is stunning with hardwood forests, lush pastures and wildflower meadows. In Transylvania you will see horse-drawn carts rumble along dirt roads and shepherds in the fields with their flock, and our volunteers often say that visiting Transylvania makes you feel like you have gone back 100 years. There are plenty of things to do during your weekends, such as hiking, visiting museums and incredible castles and fortified churches (don’t forget Bran Castle near Brasov which is better known as Dracula Castle). Our Romania team will be more than happy to give you information about local sightseeing. The best flight option for participants from the UK is usually with Wizz Air from Luton to Targu Mures. The flight is just 2 hours 55 minutes, and if you book in advance the tickets can be as cheap as £25.99 each way. If you would like any further information about any of our Romania programmes please call us on 01635 45556 or email [email protected] By Kirsteen Mahoney, Volunteer Advisor – Inspire