Visualizzazione dei risultati da 1 a 6 su 6
  1. #1

    caratteri speciali in query mysql

    ciao a tutti.
    ho questo problema:
    ho un database mysql interamente configurato con character set utf8-bin.
    ho un sito con codifica iso-8859-1.
    Premesso che sono ignorantissimo in mataria e questa lacuna andrà prima o poi colmata, ho una problematica legata ad una query dal db.
    Infatti se con mysql query builder faccio la seguente query

    Codice PHP:
    SELECT b.id as id,b.cognome as cognome,b.nome as nomeb.societa as societa                  
              FROM utenti a
    ,clienti b
            WHERE a
    .idcliente b.id
                
    AND lower(cognome) = 'banì' 
        
    ORDER BY cognome asc LIMIT 0 10 
    tutto funziona a meraviglia...
    il problema arriva nel codice php quando eseguo la query con il parametro di ingresso (all'interno del superglobal $_GET ho il parametro 'banì').
    Di fatti se io lascio tutto com'è, almeno in debug sembra che la query si componga proprio come indicato sopra, ed effettivamente nel db poi vedo il carattere "ì" correttamente codificato, ma quando eseguo la query in debug, non estrae niente.
    Ho pensato allora di utilizzare la funzione htmlentities() applicata al parametro in ingresso, ma anche così, non mi tira fuori niente.
    Qualcuno ha un'idea? devo convertire il characterset del db?
    spero proprio di no.
    grazie in anticipo.

  2. #2
    Codice PHP:
    <?php 
    $link1 
    mysql_connect('localhost','user1','pass1',TRUE); 
    $link2 mysql_connect('localhost','user1','pass1',TRUE); 

    mysql_selectdb('db1',$link1); 
    mysql_selectdb('db2',$link2); 

    mysql_set_charset('latin1',$link1); 
    mysql_set_charset('utf8',$link2); 
    ?>

  3. #3
    niente da fare...
    il cambio di character set sembra non risolvere il problema...

  4. #4
    Cambia l'header

    <?php header("Content-Type: text/html; charset=ISO-8859-1"); ?>

  5. #5
    è già presente il cambio di header nella pagina ma niente ...

  6. #6
    ti incollo paro paro lo script...

    considera che è un source di un ajax.

    Codice PHP:
    <?php

    //include the information needed for the connection to MySQL data base server. 
    // we store here username, database and password 
    include("../../connect.inc.php");

    // to the url parameter are added 4 parameters as described in colModel
    // we should get these parameters to construct the needed query
    // Since we specify in the options of the grid that we will use a GET method 
    // we should use the appropriate command to obtain the parameters. 
    // In our case this is $_GET. If we specify that we want to use post 
    // we should use $_POST. Maybe the better way is to use $_REQUEST, which
    // contain both the GET and POST variables. For more information refer to php documentation.
    // Get the requested page. By default grid sets this to 1. 
    // we should set the appropriate header information. Do not forget this.
    header("Content-type: text/xml;charset=iso-8859-1");

    $type $_GET['type'];

    switch (
    $type) {
        case 
    'delete':
            
    //recupero l'id
            
    $id $_GET['id'];
            
    $SQL "UPDATE utenti SET obsoleto = 1 where id = " $id ";";
            
    $result mysql_query($SQL) or die(mysql_error($db));
            break;
        case 
    'update':
            break;
        case 
    'insert':
            break;
        case 
    'select':
            
    $page $_GET['page'];
            
    // get how many rows we want to have into the grid - rowNum parameter in the grid 
            
    $limit $_GET['rows'];

            
    // get index row - i.e. user click to sort. At first time sortname parameter -
            // after that the index from colModel 
            
    $sidx $_GET['sidx'];

            
    // sorting order - at first time sortorder 
            
    $sord $_GET['sord'];

            
    // if we not pass at first time index use the first column for the index or what you want
            
    if (!$sidx) {
                
    $sidx 1;
            }

            
    // calculate the number of rows for the query. We need this for paging the result 
            
    $result mysql_query("SELECT COUNT(1) AS count FROM utenti");
            
    $row mysql_fetch_array($resultMYSQL_ASSOC);
            
    $count $row['count'];

            
    // calculate the total pages for the query 
            
    if ($count && $limit 0) {
                
    $total_pages ceil($count $limit);
            } else {
                
    $total_pages 0;
            }

            
    // if for some reasons the requested page is greater than the total 
            // set the requested page to total page 
            
    if ($page $total_pages) {
                
    $page $total_pages;
            }

            
    // calculate the starting position of the rows 
            
    $start $limit $page $limit;

            
    // if for some reasons start position is negative set it to 0 
            // typical case is that the user type 0 for the requested page 
            
    if ($start 0) {
                
    $start 0;
            }
            
    //modifica per gestione ricerca
            
    if (trim($_GET['searchString']) == "") {
                
    // the actual query for the grid data 
                
    $SQL "SELECT b.id as id,b.cognome as cognome,b.nome as nome, b.societa as societa,
                            if(a.obsoleto=0,1,0) as attivo, a.amministratore as amministratore 
                        FROM   utenti a,clienti b
                        WHERE  a.idcliente = b.id
                        ORDER BY 
    $sidx $sord LIMIT $start , $limit";
            } else {
                if (
    $_GET['searchField'] == 'id') {
                    
    $_GET['searchField'] = 'b.id';
                }
                if (
    $_GET['searchField'] == 'attivo') {
                    
    $_GET['searchField'] = 'a.obsoleto';
                    if (
    $_GET['searchString'] == '1') {
                        
    $_GET['searchString'] = '0';
                    } else {
                        
    $_GET['searchString'] = '1';
                    }
                }
                switch (
    $_GET['searchOper']) {
                    case 
    'eq'://(uguale stretto)

                        
    $filter "lower(" $_GET["searchField"] . ") = '" . ($_GET["searchString"]) . "'";
                        break;
                    case 
    'cn'//(contiene)
                        
    $filter "lower(" $_GET["searchField"] . ") like '%" . ($_GET["searchString"]) . "%'";
                        break;
                    default:
                        
    $filter "lower(" $_GET['searchField'] . ") like '%'";
                        break;
                }

                
    $filter strtolower($filter);
                
    $SQL "SELECT b.id as id,b.cognome as cognome,b.nome as nome, b.societa as societa,
                            if(a.obsoleto=0,1,0) as attivo, a.amministratore as amministratore 
                        FROM   utenti a,clienti b
                        WHERE  a.idcliente = b.id
                        AND    " 
    $filter 
                        ORDER BY 
    $sidx $sord LIMIT $start , $limit";
            }


            
    $result mysql_query($SQL) or die(mysql_error($db));

            
    $s "<?xml version='1.0' encoding='iso-8859-1'?>";
            
    $s .= "<rows>";
            
    $s .= "<page>" $page "</page>";
            
    $s .= "<total>" $total_pages "</total>";
            
    $s .= "<records>" $count "</records>";

            
    // be sure to put text data in CDATA
            
    while ($row mysql_fetch_array($resultMYSQL_ASSOC)) {
                
    $s .= "<row id='" $row['id'] . "'>";
                
    $s .= "<cell>" $row['id'] . "</cell>";
                
    $s .= "<cell>" $row['cognome'] . "</cell>";
                
    $s .= "<cell>" $row['nome'] . "</cell>";
                
    $s .= "<cell>" $row['societa'] . "</cell>";
                
    $s .= "<cell>" $row['attivo'] . "</cell>";
                
    $s .= "<cell>" $row['amministratore'] . "</cell>";
                
    $s .= "</row>";
            }
            
    $s .= "</rows>";

            echo 
    $s;
            break;
        default:
            break;
    }
    ?>
    naturalmente il punto in fondo allo script

    Codice PHP:
    // be sure to put text data in CDATA 
            
    while ($row mysql_fetch_array($resultMYSQL_ASSOC)) { 
    non verrà mai soddisfatto.

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.