logs archiveIRC Archive / Freenode / #php / 2015 / August / 25 / 1
TML
pfifo: php.net/pdostatement.rowCount
pfifo
TML: so, then, I think you have a clear picture of what the issue is, despite the terminology. Is there a way to get the info Im after? Or some way to determine if its safe to call fetch()
TML
pfifo: Well, if it's not a SELECT statement, it's not safe to call fetch
that seems easy enough
pfifo
TML: 'CALL blackBox();' is not a SELECT statement, returns rows, and is completly safe to use fetch() on
Majeh
blackBox() is a statement that contains a select, right?
*procedure
pfifo
Majeh: exactly
Majeh
then it's a select
i think you know what TML meant :)
pfifo
Majeh: and.. how am i supposed to know if it did a select and if there are rows available?
TML
pfifo: You're looking for an abstract, one-PHP-block-fits-all-queries solution that I don't think exists.
         

Majeh
pfifo interesting question. without trying to be sarcastic, i am 100% certain that i did a select or any other type of query
pfifo
Majeh: as am I, however my code is not, it needs a way to determin that information
TML
pfifo: You get to implement a partial SQL parser in your code, then.
Majeh
well, your code has two options then. call fetch() and succeed or fail
ez
seeing that you don't know and code doesn't know, the only option (realistically) is that you just try to call fetch
pfifo
TML: that is far too much work for such a simple request
Majeh
i won't try asking how you got into such a situation, but you planted quite a few mines for yourself
TML
pfifo: The way most code solves this is by having distinct methods for select, insert, update, call, etc.
rather than having one, completely abstract "pass all possible SQL through here"
Because, even if you manage what you're asking for, the amount of branching logic is going to make the code pretty ugly
pfifo
Majeh: The only problem with the try and see method is that the error is 'HY000 General Error' Really, I cant work with that one way or the other, was it because fetch() had no rows or did something else happen? TML: a specialized method for CALL? That is still going to have this same cavet
Majeh
when there are no rows, you get an empty array
in other cases, you inspect the error code returned by the db. in this case, it would be HY000
that's also a neat way for databases to "throw exceptions" if you will (in mysql it's called SIGNAL SQLSTATE, no clue about other dbs)
TML
pfifo: Well, CALL isn't actually one I've ever seen anyone try and support, and I don't use mysql, so I'm not familiar with the specifics of CALL. Most of the databases I work with provide a result set on a successful procedure call, even if it's an empty result set.
(fetch doesn't throw an exception on an empty result set - aka "no rows"; only if there is no result set at all)
pfifo: But you can see that, for one example, phpmyadmin (as terrible as it is) does exactly what I suggested - https://github.com/phpmyadmin/phpmyadmin/tree/0e1fcdd5bbd25b2a5a0eb3fb692eaf6f9f40203c/libraries/sql-parser/src
pfifo
At this point I am going to do just that, Look for HY000 and an empty array. Its not elegant, and really could create other issues if HY000 is raised for other reasons. But seeing as how this will 'work' and Ive never gotten an hy000 before. it seems to be the work around
Majeh
i'd argue that it is elegant
if a result existed, you get an array (even if it's empty)
if something bad happened, you move on to exception and inspect what the db said by using the error code and reason
pfifo
elegant for me would be 'HY123 Meaningful Error Code'
alright, im moving on, too much work to do, Thank you TML and Majeh for the insight
Majeh
good luck
TML
https://github.com/phpmyadmin/phpmyadmin/blob/5c7d5bfcb01bb2de76ad67f845f46318144a43ad/libraries/sql.lib.php#L988 - PMA_getNumberOfRowsAffectedOrChanged (relies on the parser to determine what the "type" of query was, whether or not it will provide a result set, etc.)
Majeh
the dreaded phpmyadmin >.<
TML
*shrug* You can at least look to it for "What kind of problems am I going to face to write a completely abstract SQL execution engine"
which it seems pfifo is wont to do
pfifo
TML: perhaps ill really look into a robust design in the future, the script I pasted is my handy work and I do want to provide it as a piece of public code. Atthis moment in time now, I need it to just work enough.
aspire
how can i do "every N minutes execute some block of code"?
TML
aspire: man cron
         

Majeh
event loop / cron
aspire
oh the cron job stuff?
Majeh
cron is probably the easiest approach
aspire
i want to monitor the status of my java application and restart it automatically when it is offline
monitor the status of my java application via a website*
Majeh
use supervisord?
ah i forgot.. you use linux? :)
aspire
or i guess a web application
nope i don't - windows
Majeh
ouch
aspire
first i need to figure out how i can determine if my java application is running from my web application
Majeh
i'm no help there
aspire
could i just use a database and change the status there?
Majeh
you could have your java app respond to a "ping" of some sort
aspire
my java app is a client
if that is relevant at all
Majeh
i've no clue what that means really :)
aspire
what do you mean by a ping?
the java application is being hosted on the same server as the web application so
Majeh
you deliver a message to the application and it responds
aspire
does that mean i can start a server on my java application on localhost?
Majeh
the "usual" way is that you "ping" an app and it "pongs" back
that's how we determine if something is still alive
aspire
right so i will ping my java application from php code?
Majeh
i'm just saying you can. as you see, there's a bit of a gap between me and java, and you and general concept. is your goal to ensure your application is still running?
TML
aspire: Why use PHP for this? Your OS already has stuff for it.
Majeh
if yes, i am sure there are monitoring tools for windows, you probably don't have to reinvent the wheel
aspire
yes, kind of like a remote monitoring system where you can restart the java application
Majeh
and yes, you can use a database to write down the status of your app (or the latest check of your app) which you can then read with php
aspire
TML it needs to be an application
web application*
TML
aspire: Why, though?
aspire
or website, either or really
TML so the status of the java application could be checked via http?
TML
aspire: Why do you need to check the status if the OS can make sure it continues to run FOR you?
My point is that you're proposing to build an HTTP service to do something your OS already does natively.
aspire
'OS can make sure it continues to run for you' does this include if the application crashes it'll restart it?
TML
yes
aspire
o.. how can i do it
TML
that's what "make sure it continues to run" means
Alphos
aspire : start-stop-daemon for instance
TML
sc create MyJavaService binpath="C:\path\to\the\application"
Majeh
on linux, program that ensures an app runs and restarts it is called supervisor
let's see what google says about that for windows
Alphos
ah, windows...
TML
aspire: https://support.microsoft.com/en-us/kb/251192
aspire
windows, yeah
TML
That's the Windows XP documentation, but the tool is still valid
Alphos
good luck with that then
aspire
TML i see - does it matter if i say the java application is being hosted on a VPS?
Majeh
Alphos
cron + s-s-d makes it all easy
Majeh
it tells you how to restart an app on windows when it dies
apparently it's easy
TML
Majeh: Well, first he has to register it as a service, which is what sc.exe does
« prev 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 next »