Find a script that uses MySQL database - php

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.

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.

Update query runs on local server but no on the internet

Please I need some brain storming. I created an update query as seen below.
<?php require_once('Connections/#####.php'); ?>
<?php
$result = mysql_query("UPDATE volunteers, vcodes SET volunteers.sn = vcodes.sn WHERE volunteers.vid = vcodes.id");
?>
It runs behind a form within a web application on my local server and produce the right result but when I upload it to the internet, it does not run but just sits there.
Can any one please help ascertain why it runs only on my local server but not on the internet. I am develop my application within Dreamweaver CS6.
1) As others have pointed out, mysql_XXX functions are obsolete. For new code, you should absolutely use the new MySQL APIs: either PDO or mySqli:
The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead
2) Similarly, you should use prepared statements. Not "update..." or "select *". Especially if your server is facing the internet!
http://www.php.net/manual/en/mysqli.quickstart.prepared-statements.php
3) By default, mySql is configured to allow local connections only. This is a Good Thing. In general, your Web server will face the internet ... but all SQL queries and updates will be local, between your Web Server and MySQL. This is both more secure and more efficient.
3) If you want to use MySQL remotely, you must do two things:
a) Configure a MySQL account to allow remote access
b) Open your server's firewall to the MySQL port
Here is an article that discusses how to do this:
http://www.rackspace.com/knowledge_center/article/mysql-connect-to-your-database-remotely
One of the reason may be your table and fields names are capitalized. You might be using windows in you local where they are not case sensitive and your remote server might be linux where table and field names are case sensitive. Make sure you are using lowercase letter for your fields and table names.

View SQL queries

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.

Creating procedures, using putty.exe

I am doing an mysql php application and I need to create a procedure to make my foreign keys work fine and also to create a calendar for report purposes. However, I have been trying to create the procedures and it does not works in putty.exe which is the only software available to do my application. I researched and I did not find anything related to this. Can anyone advise if I will need extra files for putty or the way to do it?
You need to use the mysql client to run commands against mysql. In the putty command line just run:
mysql
You will most likely need to add parameters to the command, like the user and the password needed to connect. Check the MySQL manual for details.
To run the script file that contains your procedure, first you have to upload the file to the server and then run it with
mysql < script.sql

is it necessary to use php to connect to the MySQL

is it necessary to use php to connect to the MySQL
i am working the desktop application and do not have a knowledge of php either
is there any in build class or functionality that can be use to connect to the MySQL
although there are many programme present over the internet to do so but unablefind one without the use of php. is there any reference or can i have the step by step example regarding the work.
MySQL config has the default settings. like username is root and password is blank my server name is local host.
No. PHP is a programming language. MySQL is a database. Install MySQL and type mysql from the command line and you will be connecting to MySQL using mysql.
MySQL docs
If you're writing a desktop application, mysql probably isn't the database you want to use. If you want to store data locally, try something like an embedded sqllite database. If you want to store the data remotely, I STRONGLY recommend to put the database behind an API. That is where something like PHP would come into play. It doesn't have to be PHP though. It can be python, java, ruby, etc.
Whatever you do though, DO NOT talk directly to a remote mysql database from your desktop app. That's just asking to have your db hacked.
MySQL has nothing to do with PHP, except that they are often bundled together. If you need to access MySQL by itself you can download MySql workbench.
http://www.mysql.com/products/workbench/
If you need a driver for your language google 'language + MySql Driver'

Categories