Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- IDENTIFICATION DIVISION.
- PROGRAM-ID. CustomerMaria.
- ENVIRONMENT DIVISION.
- CONFIGURATION SECTION.
- DATA DIVISION.
- WORKING-STORAGE SECTION.
- 01 DB-HANDLE USAGE POINTER.
- 01 WS-STATUS PIC 9(9) COMP-5.
- 01 WS-MYSQL-VERSION PIC X(20).
- PROCEDURE DIVISION.
- MAIN-PROGRAM.
- DISPLAY "Starting MySQL connection test..."
- *> Verificar versión de MySQL
- CALL "mysql_get_client_info"
- USING BY REFERENCE WS-MYSQL-VERSION
- ON EXCEPTION
- DISPLAY "ERROR: Cannot get MySQL version"
- PERFORM PROGRAM-END
- END-CALL
- DISPLAY "MySQL Client Version: " FUNCTION TRIM(WS-MYSQL-VERSION)
- *> Inicializar puntero
- SET DB-HANDLE TO NULL
- DISPLAY "Initial DB-HANDLE: " DB-HANDLE
- *> Intentar inicializar MySQL
- CALL "mysql_init"
- USING BY REFERENCE DB-HANDLE
- MOVE RETURN-CODE TO WS-STATUS
- DISPLAY "Status after init: " WS-STATUS
- DISPLAY "DB-HANDLE after init: " DB-HANDLE
- IF DB-HANDLE = NULL
- DISPLAY "mysql_init failed - NULL handle returned"
- ELSE
- DISPLAY "mysql_init successful - attempting connection"
- *> Intentar conexión
- CALL "mysql_real_connect"
- USING BY REFERENCE DB-HANDLE
- BY CONTENT z"localhost"
- BY CONTENT z"testuser"
- BY CONTENT z"testpassword"
- BY CONTENT z"customer_db"
- BY VALUE 0
- BY VALUE 0
- BY VALUE 0
- END-CALL
- MOVE RETURN-CODE TO WS-STATUS
- IF WS-STATUS = 0
- DISPLAY "Connection failed"
- ELSE
- DISPLAY "Connection successful"
- END-IF
- END-IF
- PERFORM PROGRAM-END.
- PROGRAM-END.
- IF DB-HANDLE NOT = NULL
- CALL "mysql_close"
- USING BY REFERENCE DB-HANDLE
- END-CALL
- DISPLAY "Connection resources freed"
- END-IF
- STOP RUN.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement