mysql_error

(PHP 3, PHP 4, PHP 5)

mysql_error -- Retorna o texto da mensagem de erro da operação MySQL anterior

Descrição

string mysql_error ( [resource link_identifier] )

Retorna o texto do erro da ultima função MySQL. Erros vindos do banco de dados MySQL não geram mais avisos. Ao invés, use mysql_error() para obter o texto do erro. Note que esta função apenas retorna o texto do erro da função MySQL mais recentemente executada (não incluindo mysql_error() e mysql_errno()), assim se você quiser usa-la, tenha certesa de usar o valor antes de utilizar outra função MySQL.

Parâmetros

link_identifier

The MySQL connection. If the link identifier is not specified, the last link opened by mysql_connect() is assumed. If no such link is found, it will try to create one as if mysql_connect() was called with no arguments. If by chance no connection is found or established, an E_WARNING level warning is generated.

Valores de retornado

Retorna o texto do erro da ultima função MySQL, ou '' (uma string vazia) se não houve erro.

Exemplos

Exemplo 1. Exemplo mysql_error()

<?php
$link
= mysql_connect("localhost", "mysql_user", "mysql_password");

mysql_select_db("nonexistentdb", $link);
echo
mysql_errno($link) . ": " . mysql_error($link). "\n";

mysql_select_db("kossu", $link);
mysql_query("SELECT * FROM nonexistenttable", $link);
echo
mysql_errno($link) . ": " . mysql_error($link) . "\n";
?>

O exemplo acima irá imprimir algo similar a:

1049: Unknown database 'nonexistentdb'
1146: Table 'kossu.nonexistenttable' doesn't exist

Veja também

mysql_errno()
códigos de erro MySQL