obtener errores mysql con pdo

43 views
Skip to first unread message

Jonathan Morales Salazar

unread,
Aug 31, 2013, 11:12:31 AM8/31/13
to programa...@googlegroups.com
hola, estoy tratando de obtener errores de mysql usando pdo pero solo logro tener el SQLSTATE a través de:

try{
 consulta
}catch(PDOException $e){
 echo $e->getCode();
}

al parecer debo lanzar las excepciones manualmente con throw new exception

Error: 1452 SQLSTATE: 23000 (ER_NO_REFERENCED_ROW_2)

¿alguien sabe si puedo tener el Error en lugar del SQLSTATE sin lanzar manualmente la excepción?

César Cancino

unread,
Aug 31, 2013, 2:30:15 PM8/31/13
to programa...@googlegroups.com
Hola Jonathan y mysql_error no te sirve ?


--
--
Publicar: programa...@googlegroups.com
Anular suscripción: programando-an...@googlegroups.com
Webs: http://www.blonder413.com/ - http://www.cesarcancino.com/ - http://www.oscar-gomez.net/ - http://www.keyphercom.com/blog/
 
---
Has recibido este mensaje porque estás suscrito al grupo "Programando Ando" de Grupos de Google.
Para anular la suscripción a este grupo y dejar de recibir sus correos electrónicos, envía un correo electrónico a programando-an...@googlegroups.com.
Para obtener más opciones, visita https://groups.google.com/groups/opt_out.



--
Atentamente Web Master César Cancino
          www.cesarcancino.com

Jeison Varilla Mendoza

unread,
Aug 31, 2013, 3:19:40 PM8/31/13
to programa...@googlegroups.com
HOla Jhonas.


Prueba con el segundo ejemplo. Ademas de mostrarte el que el error SQLSTATE tambie te dice la linea php en conflicto.
tambien busca los atributos de PDO para manejo errores. setAttribute
O crea tus propias excepciones. Si tengo algo mas, te lo hago llegar.

Jonathan Morales Salazar

unread,
Aug 31, 2013, 4:46:37 PM8/31/13
to programa...@googlegroups.com
listo jóvenes, ya lo logré. César con mysql_error no funciona. Jeison ya había probado eso, solo faltaba obtener el número del error. Sólo es tomar el siguiente valor:

$e->errorInfo[1];

si quiero el SQLSTATE tomo

$e->errorInfo[2];

Gracias por tomarse su tiempo. Revisar de nuevo lo que compartió Jeison como que me abrió la mente .Ahora sí a lanzar excepciones al cien :)

César Cancino

unread,
Aug 31, 2013, 4:55:11 PM8/31/13
to programa...@googlegroups.com
Excelente!!!


--
--
Publicar: programa...@googlegroups.com
Anular suscripción: programando-an...@googlegroups.com
Webs: http://www.blonder413.com/ - http://www.cesarcancino.com/ - http://www.oscar-gomez.net/ - http://www.keyphercom.com/blog/
 
---
Has recibido este mensaje porque estás suscrito al grupo "Programando Ando" de Grupos de Google.
Para anular la suscripción a este grupo y dejar de recibir sus correos electrónicos, envía un correo electrónico a programando-an...@googlegroups.com.
Para obtener más opciones, visita https://groups.google.com/groups/opt_out.

Jeison Varilla Mendoza

unread,
Aug 31, 2013, 5:26:28 PM8/31/13
to programa...@googlegroups.com
Siguiendo con estos errores, te pregunto algo ya que estas metido mas esto.

las respuestas del Drive PDO para sql ....que significado tiene 0 - 1 etc... mas o menos como esta lista. MYSQL

The error codes for SQLite version 3 are unchanged from version 2. They are as follows: 
#define SQLITE_OK           0   /* Successful result */ 
#define SQLITE_ERROR        1   /* SQL error or missing database */ 
#define SQLITE_INTERNAL     2   /* An internal logic error in SQLite */ 
#define SQLITE_PERM         3   /* Access permission denied */ 
#define SQLITE_ABORT        4   /* Callback routine requested an abort */ 
#define SQLITE_BUSY         5   /* The database file is locked */ 
#define SQLITE_LOCKED       6   /* A table in the database is locked */ 
#define SQLITE_NOMEM        7   /* A malloc() failed */ 
#define SQLITE_READONLY     8   /* Attempt to write a readonly database */ 
#define SQLITE_INTERRUPT    9   /* Operation terminated by sqlite_interrupt() */ 
#define SQLITE_IOERR       10   /* Some kind of disk I/O error occurred */ 
#define SQLITE_CORRUPT     11   /* The database disk image is malformed */ 
#define SQLITE_NOTFOUND    12   /* (Internal Only) Table or record not found */ 
#define SQLITE_FULL        13   /* Insertion failed because database is full */ 
#define SQLITE_CANTOPEN    14   /* Unable to open the database file */ 
#define SQLITE_PROTOCOL    15   /* Database lock protocol error */ 
#define SQLITE_EMPTY       16   /* (Internal Only) Database table is empty */ 
#define SQLITE_SCHEMA      17   /* The database schema changed */ 
#define SQLITE_TOOBIG      18   /* Too much data for one row of a table */ 
#define SQLITE_CONSTRAINT  19   /* Abort due to contraint violation */ 
#define SQLITE_MISMATCH    20   /* Data type mismatch */ 
#define SQLITE_MISUSE      21   /* Library used incorrectly */ 
#define SQLITE_NOLFS       22   /* Uses OS features not supported on host */ 
#define SQLITE_AUTH        23   /* Authorization denied */ 
#define SQLITE_ROW         100  /* sqlite_step() has another row ready */ 
#define SQLITE_DONE        101  /* sqlite_step() has finished executing */

Jonathan Morales Salazar

unread,
Aug 31, 2013, 6:17:26 PM8/31/13
to programa...@googlegroups.com
Los errores los tomo de acá http://dev.mysql.com/doc/refman/5.0/es/error-handling.html el SQLSTATE es violación a la integridad referencial, pero lo que les decía, me interesa los errores que sale y no el estado
Reply all
Reply to author
Forward
0 new messages