mysql_errno

(PHP 3, PHP 4, PHP 5)

mysql_errno -- Retorna o valor numérico da mensagem de erro da operação MySQL anterior

Descrição

int mysql_errno ( [resource link_identifier] )

Retorna o número do erro da ultima função MySQL.

Erros vindos o MySQL não geram mais avisos. Ao invés, use mysql_errno() para obter o código do erro. Note que esta fução apenas retorna o código apenas da função to MySQL mais recentemente usada (não incluindo mysql_error() e mysql_errno()), assim se você quiser usa-la, tenha certesa de conferir o valor antes de executar 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 número de erro da ultima função MySQL, ou 0 (zero) se não houve erro.

Exemplos

Exemplo 1. Exemplo mysql_errno()

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

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

mysql_select_db("kossu", $link);
if (!
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_error()
códigos de erro MySQL