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

    Query errata o con risultato vuoto?

    Eseguo così le query.
    codice:
    $s_sql = "SELECT * FROM Utenti WHERE $username = '$username' AND password = '$password'";
    $rs = mysql_query($s_sql);
    
    if($rs)
    {
    	$row = mysql_fetch_array($rs);
    	....
    	...
    Il problema è che, a differenza di come accade in ASP, se la query è errata non viene restituito errore e quindi non so come distinguere tra il caso in cui il risultato è vuoto e quando invece la query ha restituito errore.

    Voi come fate? (apparte scrivere bene le query ovviamente )

  2. #2
    Ti suggerisco di iniziare leggendo il manuale ufficiale:

    http://www.php.net/mysql_query

    For SELECT, SHOW, DESCRIBE, EXPLAIN and other statements returning resultset, mysql_query() returns a resource on success, or FALSE on error.

    For other type of SQL statements, UPDATE, DELETE, DROP, etc, mysql_query() returns TRUE on success or FALSE on error.

  3. #3
    Avevo letto ma appunto non capivo bene.

    Comunque devo fare il controllo sia sul risultato che sul fetch, no?

    codice:
    $rs = mysql_query($s_sql);
    
    if($rs)
    {
        $row = mysql_fetch_array($rs);
        
        if($row)
            do
            {
                // Operazioni sui dati
                echo "
    Elaborazione riga numero: ";
                
                $row = mysql_fetch_array($rs);
            } while($row);
        else
            echo "
    Nessun risultato";
        
        mysql_free_result($rs);
    }
    else
    {
        echo "
    Errore nella query!";
    }
    Così dovrebbe andare bene?

    Grazie dell'aiuto

    PS - Come si fa ad ottenere il numero di riga che si sta elaborando?

  4. #4
    Devi usare un error handler, e poi generare un errore con la funzione "tigger_error".

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.