freak Posted February 9, 2010 Report Share Posted February 9, 2010 Man ir DB, kur dati glabājas utf8_general_ci kodingā. Problēma tāda, ka veicot meklēšanu šajā DB, neatrod, ja meklē pēc lielajiem, burtiem, ja tas ir latviešu burts ar garumzīmi vai mikstinājuma zīmi (Ā, Ē Š, Ķ) Piemēram, ja DB ir vārds Čiekurs un meklē čiekurs, tad neatrod! Ja ir Lapsa un meklē lapsa, tad atrod. Kā šo novērst? Quote Link to comment Share on other sites More sharing options...
briedis Posted February 9, 2010 Report Share Posted February 9, 2010 http://laacz.lv/2006/12/28/mysql-un-utf8/ Quote Link to comment Share on other sites More sharing options...
2easy Posted February 9, 2010 Report Share Posted February 9, 2010 (edited) utf8_latvian_ci no! tas ir vēlams, bet nebija svarīgi 1) php failu, kurā tev ir tas SELECT, saglabā kā UTF-8 bez BOM (sameklē savā koda redaktorā pie "save as", kur var norādīt faila kodējumu) 2) uzreiz, kad izveido savienojumu un izvēlies db, izsauc mysql_query('SET NAMES utf8'); tikai pēc tam izpildi SELECT, un ja tajā tabulā patiešām būs utf8 dati, tad arī lielie/mazie lv burti selektēsies pareizi kr4 simple example function dbconn($sSrv, $sDb, $sUsr, $sPw) { // inicializē mysql connection @mysql_connect($sSrv, $sUsr, $sPw) or exit('<b>mysql_connect() error ' . mysql_errno() . ':</b> ' . mysql_error()); mysql_select_db($sDb) or exit('<b>mysql_select_db() error ' . mysql_errno() . ':</b> ' . mysql_error()); go('SET NAMES utf8'); } function go($sSql) { // izpilda mysql query $h = mysql_query($sSql) or exit('<b>mysql_query() error ' . mysql_errno() . ':</b> ' . mysql_error() . '<br /><b>query:</b> ' . substr($sSql, 0, 1000)); return $h; } function qs($s) {return is_null($s) ? 'NULL' : "'" . mysql_real_escape_string($s) . "'";} // query str - sagatavo tekstu (any string) ievietošanai mysql query function esql($sSql) { // echo sql & its returned data echo $sSql . '<br />'; $h = go($sSql); while ($r = mysql_fetch_row($h)) echo implode(' | ', $r) . '<br />'; echo '<br />'; } dbconn('localhost', 'test', 'root', '123'); go('DROP TABLE IF EXISTS t'); go('CREATE TABLE t (s varchar(20)) ENGINE=MyISAM COLLATE=utf8_general_ci'); go('INSERT t (s) VALUES (' . qs('asdf') . '),(' . qs('āšņ') . '),(' . qs('Čiekurs') . ')'); esql('SELECT * FROM t WHERE s LIKE ' . qs('Ā%')); esql('SELECT * FROM t WHERE s LIKE ' . qs('č%')); Edited February 9, 2010 by 2easy Quote Link to comment Share on other sites More sharing options...
marrtins Posted February 9, 2010 Report Share Posted February 9, 2010 Vajadzētu "darboties" arī ar utf8_general_ci _ci=case insensitive Quote Link to comment Share on other sites More sharing options...
2easy Posted February 9, 2010 Report Share Posted February 9, 2010 (edited) vai vsp case sensitive arī ir? izmēģināju utf8_general un utf8_general_cs, bet tie fail ;) btw, nupat googlē ierakstīju "mysql like", un php.lv forums bija jau 4. rezultātā! baigi labais google reitings :)) laikam labi seo speciālisti te ir piestrādājuši ^^ Edited February 9, 2010 by 2easy Quote Link to comment Share on other sites More sharing options...
Rich Bitch Posted February 27, 2010 Report Share Posted February 27, 2010 kas 2easy skriptā būtu jāmaina, lai rakstot piekrasījumu SELECT * FROM t WHERE s LIKE 'Ā%' izvadītu tikai tos kas sākas ar Ā, nevis a? Quote Link to comment Share on other sites More sharing options...
waplet Posted February 27, 2010 Report Share Posted February 27, 2010 neatminos īsti, bet bija kaut kas ar datubāzes kodējumu jāmaina server side. vai arī pamēģini beigās pie kvērija. COLLATE Utf8_bin Quote Link to comment Share on other sites More sharing options...
Rich Bitch Posted February 28, 2010 Report Share Posted February 28, 2010 pieliku, bet nesanāca. tik un tā atlasa gan ā, gan a Quote Link to comment Share on other sites More sharing options...
2easy Posted February 28, 2010 Report Share Posted February 28, 2010 nju šis ir official http://dev.mysql.com/doc/refman/5.1/en/case-sensitivity.html bet vēl nepamēģināju ;) Quote Link to comment Share on other sites More sharing options...
Rich Bitch Posted February 28, 2010 Report Share Posted February 28, 2010 ja pareizi sapratu pēc teksta, tad jābūt šādi: esql('SELECT * FROM t WHERE s LIKE ' . qs('Ā%') . ' COLLATE utf8_latvian_ci '); nestrādā šāds variants Quote Link to comment Share on other sites More sharing options...
2easy Posted February 28, 2010 Report Share Posted February 28, 2010 (edited) šādi pat teorētiski nestrādātu, jo iekš utf8_latvian_ci "ci" nozīmē case-insensitive :D kkā jāmēģina piedabūt utf8_bin vai kaut vai COLLATE latin1_bin Edited February 28, 2010 by 2easy Quote Link to comment Share on other sites More sharing options...
briedis Posted February 28, 2010 Report Share Posted February 28, 2010 Moš te var atrast risinājumu: http://laacz.lv/2006/12/28/mysql-un-utf8/ Quote Link to comment Share on other sites More sharing options...
2easy Posted February 28, 2010 Report Share Posted February 28, 2010 (edited) tur jau runa iet tikai par konvertēšanu... protams, var jau arī pašu tabulu nodefinēt ar COLLATE=utf8_bin Edited February 28, 2010 by 2easy Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.