cancel
Showing results for 
Search instead for 
Did you mean: 

How to get server messages in PHP Api?

487

Hello, I have a PHP Api which executes various procedures in a Sql Anywhere 17 database. In some of the procedures "messages" are output via the "messsage" function. Is there a way to read these messages in PHP and display them in the frontend? I use the SqlAnywhere PHP extension.

I have already tried to solve it via the system procedure "sa_server_messages()" but unfortunately it is not possible to recognize which connection/user triggered the message.

P.s. I don't want to change the procedures with the messages because they are also used in a desktop application.

Accepted Solutions (0)

Answers (1)

Answers (1)

chris_keating
Product and Topic Expert
Product and Topic Expert

The procedure sa_server_messages only applies to messages written to the server console.

It sounds like you want message ... to client. This is available in embedded SQL and ODBC requiring a message callback to be registered.

For more information, see MESSAGE STATEMENT.

VolkerBarth
Contributor
0 Kudos

Chris, I wonder whether the PHP API (which presumably is based on the SA C API, which offers the sqlany_register_callback() function) does support/offer those callbacks, too?

chris_keating
Product and Topic Expert
Product and Topic Expert
0 Kudos

Based on the PHP driver source in %sqlany17%\\SDK\\PHP, I am not able to find any invocations of sqlany_register_callback in the PHP driver implementation.

0 Kudos

Chris, so it is not possible to get these messages via PHP cause its not implemented in the driver right. Any ideas how i can provide those messages for users in a web application? Maybe i should add the message(s) as a result set to the procedure.

VolkerBarth
Contributor
0 Kudos

so it is not possible to get these messages via PHP cause its not implemented in the driver right.

Well, technically the driver's source code is available in the SQL Anywhere installation (see Chris's comment), so in case you are familiar with C and PHP programming, you might be able to enhance the driver to add an according callback facility. My knowledge of PHP is rather limited, so I can't tell whether this is doable and how difficult this would be - AFAIK, PHP itself does support callback functions, and the underlying SQL Anywhere C API does provide that according sqlany_register_callback with type CALLBACK_MESSAGE, so there should be chances it will work.

That being said, it is probably way easier to enhance your stored procedures with according result sets...