myyis
asked on
I need an app based (session independent) counter that gives me the order of the queries that are done to server.
I need an app based (session independent) counter that gives me the order of the queries that are done to server.
Does PDO (or MySQL) has an internal counter for that? If it does not have how a can I get the order of the queries without writing to db or using the file system.
What I do right now is
1. construct my PDO object :
$dbpdo = new PDO("mysql:host=$db_host;d bname=$db_ name", $db_username, $db_password, array(PDO::ATTR_PERSISTENT => true));
$dbpdo->setAttribute(PDO:: ATTR_ERRMO DE, PDO::ERRMODE_EXCEPTION);
$dbpdo->setAttribute(PDO:: ATTR_TIMEO UT, 30);
$dbpdo->query("SET NAMES utf8");
2. Do the query:
$q = $dbpdo->prepare($sql);
$q-> execute($arr);
I need the order number of the query (app based)
Thank you
Does PDO (or MySQL) has an internal counter for that? If it does not have how a can I get the order of the queries without writing to db or using the file system.
What I do right now is
1. construct my PDO object :
$dbpdo = new PDO("mysql:host=$db_host;d
$dbpdo->setAttribute(PDO::
$dbpdo->setAttribute(PDO::
$dbpdo->query("SET NAMES utf8");
2. Do the query:
$q = $dbpdo->prepare($sql);
$q-> execute($arr);
I need the order number of the query (app based)
Thank you
ASKER
Order number ise like 1,2,3,4....
I need the order of queries processsed by MySQL (SESSION INDEPENDENT)
Thank you.
I need the order of queries processsed by MySQL (SESSION INDEPENDENT)
Thank you.
So you want to record the queries that were ran - in order, regardless.
In that case, you will need to log them - either at the app level or the server level. Not entirely sure how you think you'd record these without using a DB or FileSystem though. A logger can technically send the information to a remote logging server, but they'd still need to be recorded somewhere.
In that case, you will need to log them - either at the app level or the server level. Not entirely sure how you think you'd record these without using a DB or FileSystem though. A logger can technically send the information to a remote logging server, but they'd still need to be recorded somewhere.
ASKER
Sure I will record them like this, but I need the $orderno
query[$orderno]=$sql;
query[$orderno]=$sql;
Hmmm. I'm a little confused as to what you're trying to do here, or why you're trying to do it.
Am i right in thinking that you want to create an array containing all the queries your application runs, in order, regardless of SESSION, and you don't want to store this info in the database or by using the filesystem ??
Sorry for all the questions ... but what you're asking just doesn't make any sense to me.
What are you trying to acheive here?
Am i right in thinking that you want to create an array containing all the queries your application runs, in order, regardless of SESSION, and you don't want to store this info in the database or by using the filesystem ??
Sorry for all the questions ... but what you're asking just doesn't make any sense to me.
What are you trying to acheive here?
ASKER
No I will not store this info, I need that for another purpose.
I only need to fill the array.
query[$orderno]=$sql;
I only need to fill the array.
query[$orderno]=$sql;
OK. At the start of your script, create your array:
$queries = array();
And then add to that array whenever you run a query:
$q = $dbpdo->prepare($sql);
$q-> execute($arr);
$queries[] = $sql;
By the time you get to the end of your script, your $queries array will contain all the SQL that was ran - in order. You can view it with:
var_dump($queries);
$queries = array();
And then add to that array whenever you run a query:
$q = $dbpdo->prepare($sql);
$q-> execute($arr);
$queries[] = $sql;
By the time you get to the end of your script, your $queries array will contain all the SQL that was ran - in order. You can view it with:
var_dump($queries);
ASKER
Your array is session dependent (session based). i need an app based variable with unique keys regardless of sessions.
OK .. So we're now back to logging again !!
In your app, write the SQL out to a log file each time you run a query. Then when you need to see what queries were run and in what order, you just need to look at the log file. It will look something like:
SELECT * FROM someTable WHERE id = ?
UPDATE someTable SET somecolumn = ? WHERE id = ?
SELECT * FROM someTable WHERE id = ?
SELECT * FROM someTable WHERE id = ?
INSERT INTO someTable (column1, column2) VALUES (?, ?)
If you want that data back in your app, then just load it:
$queries = file('database.log');
You'll then have an array containing all the queries that you logged in your App, and in the order they were logged.
In your app, write the SQL out to a log file each time you run a query. Then when you need to see what queries were run and in what order, you just need to look at the log file. It will look something like:
SELECT * FROM someTable WHERE id = ?
UPDATE someTable SET somecolumn = ? WHERE id = ?
SELECT * FROM someTable WHERE id = ?
SELECT * FROM someTable WHERE id = ?
INSERT INTO someTable (column1, column2) VALUES (?, ?)
If you want that data back in your app, then just load it:
$queries = file('database.log');
You'll then have an array containing all the queries that you logged in your App, and in the order they were logged.
ASKER
Thank you. i need a solution without using file system. Does MySQL or pdo has an internal counter ?
Nope!
As I said before, you can enable server logging, but that will write to the file system, and log pretty much everything.
I'm really not sure where you want store this information - not in the DB, not in the FileSystem, not in a SESSION. You're kinda limiting yourself there.
I still don't know what you need this for, so I'm out of ideas.
Good luck with it.
As I said before, you can enable server logging, but that will write to the file system, and log pretty much everything.
I'm really not sure where you want store this information - not in the DB, not in the FileSystem, not in a SESSION. You're kinda limiting yourself there.
I still don't know what you need this for, so I'm out of ideas.
Good luck with it.
ASKER
i do not want to over complicate the question by detailing why i need this and how i will use it. Please note that i have already mentioned my restrictions in the original question. Thank you for your feedback tough.
ASKER
If there isn't an internal counter may be I can try app based variables to create a counter? Anybody can help about that?
And where do you intend to store those variables ?
ASKER
I will not store the variables (or array). They will be a part of a MySQL performance monitoring system. Will be deleted when they are not necessary.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Checking for tmpfs
You're basically looking at logging. Now you can do this at the SQL Server level by enabling logging, or you can do it at your application level. The advantage of doing it at the server level means that you don't have to change any code. However - it will log all activitiy against the server, regardless of app or database accessed, and the log file can grow pretty bug, pretty quicky.
By doing it at the the app level, you would have full control and would need to add in a logging call anytime you wanted to record something. If you alreay have logging in your app, then it's pretty easy.
Open in new window
If you don't have logging, take a look at Monolog - a really good PHP logging framework.I don't really understand the part of your question where you say 'without using the DB or the FileSystem'. I'm also not sure what you mean by 'order number' of the query. You may want to clarify that.