Check whether PHP incompatibility or MySqli incompatibility the issue? - php

I created a site, built it and tested it on my own server. Now uploading to the client's server and every page with PHP/MySqli doesn't work. When the php/MySqli script appears in the page it just ends there, cutting out the rest of the content, footer etc.
Here is the version of the site on my server that works
http://progressivewebsolutions.ca/expmed/researchers.php
and here is the one on the clients server that doesnt work...
http://expmed.mcgill.ca/researchers.php
the client server is running php 5.2.6
mysql 5.0.45
On the dbconnect file it is supposed to throw an error if it cannot connect and does not throw the error. Regardless of login info and password.
My question is what tools exist to check this issue and solve it? I taught myself to code and am constantly learning, just need a bit of guidance.
Thank You,

I would look first in the web server's error log. Many PHP errors that are not output to the HTML are sent to the error log.
Make sure you have PHP error reporting enabled. See also How to get useful error messages in PHP?
If you want more help, I suggest you edit your question above and show the code you use to connect to the MySQL instance.
Another strategy is to log into a shell on the PHP appserver host and try using the mysql command-line client to connect to the MySQL instance, using the same host, user, password that your PHP script uses.
$ mysql -h mysqlhost -u username -p
Enter password: <enter password here>
That will test if the hosts can talk to each other, and whether the login works (keep in mind MySQL connection privileges may be restricted by host, so one login that works from one appserver may not work from other appservers).

Start to perform a phpMyInfo in order to see if Mysqli is "on".
On the other way, under PHP, in such a case, the basic way of putting some "echo" along the code is, maybe, the best way.
After a look at the phpinfo(),it seems error reporting is off. So even if you have some errors, you cant' see them.
Just add:
error_reporting(E_ALL);
ini_set('display_errors','On');
at the beginning of your page and maybe you'll see the errors.
Good luck!
Peter

Related

How to view ERROR feedback in AWS PHP application?

I am currently developing a web application using AWS services and it's written in PHP. Previously, I used XAMPP to do the work, but now I use EC2 and RDS (MySQL) of AWS. And I also hosted the web on domain using Route 53 and it is secure with Certificate Manager (HTTPS enabled).
This is how I do my job. Sublime Text to write code, then copy paste the file from local to server using WinSCP. If nothing wrong, the code will instantly reflect in my webpage. However, unlike XAMPP, the ERROR will reflect exactly which line is going wrong. The approach I am using will only show HTTP 500 (Request cannot be handled) within the webpage.
For now, I have to test code by code to find the ERROR and it's a waste of time. So, if I want to view which part is going wrong like XAMPP, how can I do so?
Thank you.
In a production environment, it is recommended to switch off detailed errors so that your implementation details are not exposed. Sounds like this is the problem you're facing with the new setup. You need to enable this in your php.ini file, and you might want to look into your .htaccess as well.
Check out the answer here for a more detailed explanation - How can I make PHP display the error instead of giving me 500 Internal Server Error
Here's a guide on implementing the changes you need - https://stackify.com/display-php-errors/
By default, the Errors logs are stored at /var/log/apache2/error.log. So you can do something like the below to see the apache logs in real-time:
tail -f /var/log/apache2/error.log

Can connect to database on server but cannot insert. Works on mamp localhost

I created a website which was fully functional on my computer's MAMP. When I placed it on the server, everything works well except for the fact that I cannot insert a new user into the DB. I'm partially concerned that the SSL cert is interrupting it, but I don't know enough about this to determine that. To troubleshoot this I did the following:
1. confirmed the connection works by returning row numbers and data that I manually placed into the database
2. confirmed openSSL is active/on
3. confirmed proper placement of my ssl certs through a separate site that confirms their presence
4. checked the error log on the server (which showed no errors) and then created a script to cause an error as proof of principle it works
5.confirmed the phpmyadmin user has full privledges
6. I have two user types and scripts that both don't work that worked on MAMP so I'm fairly confident its not poor coding
Further, all my php sql statements have built in mysqli_error($conn) which show no errors, and when I attempted a basic
"INSERT INTO users (name) VALUES ('john')"
scenario, it was unsuccessful.
My feeling that it is the ssl stems from the fact that my other (non-encrypted) sites don't have this problem. Is there something basic I'm missing?
Its not the SSL, its your configuration. See into it. If you can insert while doing it in the phpmyadmin with a raw sql, then check your config like the hostname user and db name. What server you are using?

Connecting to Heroku Postgres database with PHP

I've got an app with Heroku that I'm trying to connect to in PHP, but I'm not having any luck with. I'm able to connect to the database in pgAdmin III, so I know I've got the right info, but PHP isn't returning anything useful to me, only false. Can anyone suggest what I might be doing wrong, or even a way to get PHP to tell me something more substantial so I can troubleshoot better?
Here's my connection string:
$conn = pg_connect("host=ec2-xx-xx-xxx-xx.compute-1.amazonaws.com port=xxxx dbname=namestring user=username password=pass sslmode=require");
I've tried it with sslmode and without, I've tried changing the order of the parameters in the string, I just get false back when I do var_dump($conn).
I am assuming you are running this locally, so check that display_errors is enabled in your local php.ini and that error_reporting is set to something reasonable. That would be the reason you're not getting error output.
You should then see that either the connection is refused for some reason (could be your network), or that e.g. your local PHP doesn't have OpenSSL enabled (globally or for Postgres).
If this is happening on Heroku, then you'll never see errors in the page because it's a production env where display_errors should never be on; run heroku logs to see what PHP says. In this case the only reason would be that your credentials are incorrect, so check them for typos.
Which brings me to some important advice: do not hard-code these credentials (or any other config) in your code. Heroku gives you a DATABASE_URL env var with the connection string; read from that dynamically by using what parse_url(getenv('DATABASE_URL')) gives you. The reason is that your credentials may change in case Heroku needs to do an automatic failover of your database, and if you hard-code these credentials, your app would go down in this case.
If this is on Heroku, you really should run this stuff locally properly, that means with a local Postgres database as well, instead of connecting remotely to production databases, or even blindly pushing up your code to Heroku all the time without trying it locally. Much easier and faster over time.

How to connect to a remote DB from my computer with PHP

I am quite new in PHP and databases. I am trying to connect to a remote Postgres database from my computer. In the past I have done this by using a localhost and a MySQL database but it is the first time that I try to connect in another host.
This is the PHP code that I have:
<?php
$conn_string = "host=hostname.com port=xxxx dbname=dbname user=root password=root";
$dbconn = pg_connect($conn_string);
?>
I read several articles in internet saying that it is enough to change the hostname from localhost to the one provided but it doesn't seem to work. I also have deactivated my firewall in case there is some problem with the communication but with no success.
As I said I am quite new with this and in the past I had used only test servers (localhost). Back then I was using software like Wamp and Mamp and I was placing the script files in the localhost.
So, my questions are:
1) where should I save the test.php file which has the above lines of code?
2) Would this solve the problem or I am missing some important concept here?
I hope what I am trying to say is clear. Please let me know if I have to be more specific in something.
Thanks
Dimtiris
First, error messages would really help. Based on the comments I will say I suspect that you are connecting to the right server. However you are using a username of "root?" It would be highly unusual for such a username to be present on Postgres.
The first one is where to put the file. This should be put in your web server's document root or cgi bin depending on how you have things configured (probably the former).
For your second question, please double check usernames and passwords, and make sure you can use those usernames and passwords via pgAdmin III to connect to the same db. Making sure you have the credentials right to start will make your code a lot easier to troubleshoot if things don't go right.

PHP call to MYSQL INSERT is HANGING

IS there any logs on the MySQL server in regards to access? I am having an insert statement hang. It could be a subnet/firewall/interface configuration problem. I have the firewall open for the MySQL traffic, but it appears to be being blocked on an irregular basis. Sometimes it works and sometimes it doesn't. Any ideas for places to start looking in my logs?
To troubleshoot your query, grab a front end like SQLyog or MySql Workbench. You can run your queries in it and more directly interact with the database to see if the query itself is throwing the error.
If you're having a connection problem of some sort, the error message in your php app should provide some hints (timeout, server not available, etc.).
Next, you can enable error messages in PHP by changing settings in your php.ini, or adding a command in the script itself, see http://www.php.net/manual/en/book.errorfunc.php.
Finally, MySQL can log errors, but where it does and whether it does depends on your particular installation. Check your MySQL configuration file to see if error logging is enabled and to what location it outputs.
Post the error message you are getting if you need additional help.

Categories