View SQL queries - php

I am on WAMP configuration. Is there a way within WAMP or a package which will allow me to see SQL queries fired from PHP to MySQL server.
I am familiar with overriding DB adapters in JAVA to see the fired SQL requests. Is there something similar in PHP
OR is there a way to view the fired SQL from mysql functions itself?

Click the WAMP tray icon, and click 'my.ini' in the MySQL menu.
Then, add the following in the [mysqld] section:
general-log=1
general-log-file = "C:\wamp\logs\mysql_general.log"
Finally, restart all services and your queries should be logged. This enables MySQL's General Query Log.

There are few things you can do.
First if you are using function wrappers (for example query() as a wrapper for mysqli_query()) then you can echo the query from inside it (or save it to log file).
Second, you could enable General Query Log in MySQL (not recommended on live servers, since it can take a lot of space very fast!). There you may find everything that mysqld has done. More at http://dev.mysql.com/doc/refman/5.1/en/query-log.html
Third, you could install mysql proxy, which would run between your scripts and mysql, and it could output everything sent to your database. More at http://dev.mysql.com/downloads/mysql-proxy/
It all depends on what you prefer, and what is suitable for your situation.
Let me know what you think.

Related

selecting data from IBM database while using wampserver

Good day,
I am using wampserver, and I would like to get data from a remote IBM database (AS400) using db2_connect. I've tried searching on some ways but I couldn't get the idea of doing it. I have successfully included ibm_db2.dll extension on my php. However, I don't know what to do next.
As you seem to be using "DB2 Connect" (and not a separate DB2 client) product you can either configure DB2-Connect with a node/alias/dsn and then mention that alias with the db2_connect() action, or use PDO_IBM longer connection string with all the details as mentioned here.
You need to know the tcpip-address (or hostname) of the i-Series DB2-server, and the Port-number it listens on.
Check this technote for the actions required to make a node/alias (I believe the same general configuration pattern applies to DB2-connect as Data server client).
The advantage of configuring like this is that you can verify the database-connect in your workstation command line shell , before making it work in PHP/pdo.

Find a script that uses MySQL database

I am editing a system which was built by another programmer at my company.
System is made using PHP and uses Send Grid for mail delivery. I just add email addresess for sending mails and all works well, but I can't find the script that writes incoming mails to database, so I can't retrieve new incoming e-mails.
Is there a way to determine which script writes to the database?
First you need to know which database engine is used, for a MySQL database search your code, for example with netbeans "Find in project", with the keywords: mysql_ or mysqli.
Other classes used for database access are PDO and ODBC, for that you should search after PDO or odbc_.
PDO Manual
ODBC Manual
There's possibly no "standard" way to do this. I would suggest the following: Open the whole thing in an IDE (like Netbeans for PHP) if you haven't already and then do a file search for e. g. the name of the table that is concerned. Or for commands starting with mysql / mysqli, if you don't know.
If the project is running in Linux, you could also try
cd /path/to/project/sources
find | xargs grep mysql
(Replace mysql with mysqli or the table name.)
Another approch would be to force an error: Cut the database connection or rename the table(s) or something like this. PHP will throw an error that would hopefully occur in your logfiles, stating where it occured (PHP script and line).
Turn on the mysql general log and figure out which queries are coming from the input script, then you can determine the incoming IP for those queries. Watch the processlist for the incoming queries and then do a netstat -anp on the remote IP to track down which process is generating those queries.

How to properly access de BIND DNS to write in some of the files?

My Environment:
I'm using: OpenSuse 11.4 kernel 2.6.x.x; Apache 2.2; PHP 5.3; MySQL 5.5 Community; Pearl 5 version 12 and Bash.
I have been used BIND DNS, the whole process until now is manually (Add, Update, Get, etc..) hosts.
Now I need to develop some automation for this kind of task as I mentioned above. The problem is I do not want to use Cpanel, WHM or whatever software in the market to do this.. I'm looking to develop some script in perl or php or whatever language it need to be.. I really want something very simple that I just need to query the database to get all the information I need and execute the operation in the BIND.
I intend to use cronjob to fire the "script" to query the information of new hosts added in my table and then execute BIND.
I do not know if I was clear enough, if not please ask me.
I do not have anything yet. I'm just grabbing some ideas for a while.
Cheers.
[EDITED]
I need to Add, Delete, Update, Get and Set information in my DNS Zone. Create the files every time the script query the database and after export to BIND.
Bind has a nice tool included called nsupdate which allows you to edit the zone from the command line. You should use that if you're writing a script.
Bind can run backed by a database; when you do this, updating the database updates the zone. There are no zone files at all!

Trouble in PDO and sqlsrv land

I set up a site on my local system using PDO and a MySQL Database. I used PDO because when the site goes on the live server I have to user SQL Server and I was hoping PDO would take care of all my query conflicts.
Now that I'm up on the live server I get an error whenever the application uses the "LIMIT" function. I realize this is a MySQL specific function but shouldn't PDO take care of the conflict? How do I fix it so that site will work on MySQL and SQLSRV?
Thanks in advance.
Never develop in one technology expecting to use a different technology in prod.
It fails because there is no SQL Server equivalent for LIMIT so it can't convert.
If you expect different backends to be possible, use ANSII standard SQL not database specific things. If you expect to use only SQL Server in prod, develop in SQL Server (there is a free version).

PHP & MySQL on Mac OS X: Access denied for GUI user

I have just installed and configured Apache, MySQL, PHP and phpMyAdmin on my Macbook in order to have a local development environment. But after I moved one of my projects over to the local server I get a weird MySQL error from one of my calls to mysql_query():
Access denied for user
'_securityagent'#'localhost' (using
password: NO)
First of all, the query I'm sending to MySQL is all valid, and I've even testet it through phpMyAdmin with perfect result. Secondly, the error message only happens here while I have at least 4 other mysql connections and queries per page. This call to mysql_query() happens at the end of a really long function that handles data for newly created or modified articles. This basically what it does:
Collect all the data from article form (title, content, dates, etc..)
Validate collected data
Connect to database
Dynamically build SQL query based on validated article data
Send query to database before closing the connection
Pretty basic, I know. I did not recognize the username "_securityagent" so after a quick search I came across this from an article at Apple's Developer Connection talking about some random bug:
Mac OS X's security infrastructure gets around this problem by running its GUI
code as a special user, "_securityagent".
So as suggested by Frank in the comments I put a var_dump() on all variables used in the mysql_connect() call, and every time it returns the correct values (where username is not "_securityagent" of course). Thus I'm wondering if anyone has any idea why 'securityagent' is trying to connect to my database - and how I can keep this error from occurring when I call mysql_query().
If username is not specified explicitly, MySQL tries to guess it by using name of current system user.
You don't have to accept that, you just need to specify desired username explicitly.
How – that depends how you're connecting. In case of phpMyAdmin it's config.inc.php, add line like:
$cfg['Servers'][0]['user'] = 'Eirik';
(see manual)
Did you set up your local AMP server using a pre-made package, or did you install MySQL, PHP, etc. through the respective OS-specific download packages? Setting up Apache, MySQL, and PHP4/5 can be a real PITA.
If you're having problems with your setup I'd recommend MAMP. It's a nifty all-in-one package that really does the trick. You can still access all the config files you want, and everything is contained in the MAMP folder instead of spread all over the system. If Apple upgrades the pre-installed version of Apache/PHP, your machine-specific config wouldn't be overridden as it would in the case of using pre-installed Apache/PHP.

Categories