mysql_connect() causing 500 error - php

I am a bit new to web development. So there might be a trivial thing that I might have missed and am not able to figure out by searching online for some time. Here is the problem
In my PHP script I am connecting to the data as shown below
$con = mysql_connect('localhost','root','');
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
This function works fine when I run it from shell prompt on the server using "php -f" command
But when I try to execute this script using a browser session, it gives an error.
"HTTP Error 500 (Internal Server Error): An unexpected condition was encountered while the server was attempting to fulfill the request"
The server php version is 5.3.3 and it is on Cent OS.

My problem was that selinux was activated on centOS. I had to set the
allow_user_mysql_connect bool using the command
setsebool -P allow_user_mysql_connect on

Related

sasql_connect(): SQLAnywhere: [-100] Database server not found

it's about more than one full day that i started sqlanywhere and i'm so interested to use it,
i worked before with sqlsrv for ms sql server and connection via php ,
but i have problem for connecting php to sqlanywhere
here is the warning message when i try to run test.php
Installation successful Using php-5.6.0_sqlanywhere.dll
Warning: sasql_connect(): SQLAnywhere: [-100] Database server not found in C:\xampp\htdocs\test.php on line 44
Connection failed
$conn = sasql_connect( "UID=DBA;PWD=sql" );
if( $conn ) {
echo "Connected successfully\n";
sasql_disconnect( $conn );
} else {
echo "Connection failed\n";
}
I'm using xampp server php 5.6 and sqlanywhere 17 developer edition.
already i downloaded the php extension and copied on ext and also added the line in php.ini (extension=php-5.6.0_sqlanywhere.dll)
demo database i ran it with cmd : dbeng17 "%SQLANYSAMP17%\demo.db".
via cmd i tried this also :
C:>dbping -d -c "uid=dba;
SQL Anywhere Server Ping U
Connected to SQL Anywhere
Ping database successful.
but when i try via php it says: Warning: sasql_connect(): SQLAnywhere: [-100] Database server not found in C:\xampp\htdocs\test.php on line 44
Connection failed
please someone tell me what is the problem ?
thank you very much.
Your PHP installation may have multiple files similar to php.ini. Make sure you are modifying the php.ini file listed in phpinfo().
- A web server such as Apache, IIS, or any web server that supports
PHP.
- PHP installed on the same computer as the web server.
- SQL Anywhere installed on the same computer as the web server.
- The client software can be used as well. SQL Anywhere PHP extension
Refrance : https://wiki.scn.sap.com/wiki/display/SQLANY/Getting+Started+with+SAP+SQL+Anywhere+and+PHP
It solved for me when I installed and used it on another system , I don't know I tried first on a system that MSSQL server was install and I couldn't run it and tried on another system that mssql server was not installed and solved :)
sorry for being late to answer and thank you very much for those who took time to help me.

500 Internal Server Error when access the phpmyadmin using with command in Bitnami Apache

I get the error like "Internal Server Error" when I access http://localhost:8888/phpmyadmin/ url for open the database in bitnami apache. I have try to resolve the issue using command still do get the solution.
So, Please help me for same.

MySQL No Route to Host, mysqli_connect(): (HY000/2002)

I am trying to install BugZilla on Mac OS X 10.9 (Mavericks).
I'm hitting a snag with my MySQL configuration.
I have installed MySQL from the DMG Image mysql-5.6.14-osx10.7-x86_64
MySQL seems to be installed and running ok.
I have created a user called bugs, and a database called bugs.
I confirm that I can login to MySql from the terminal command line, using the bugs username and password, and access the bugs database.
However the installation of BugZilla fails with an error connecting to MySQL. I tried a simple test and wrote this php file:
<?php
// Create connection
$con=mysqli_connect(“localhost”,”bugs”,”********”,”bugs”);
// Check connection
if (mysqli_connect_errno($con))
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
?>
But it fails at line 3 with:
Warning: mysqli_connect(): (HY000/2002): No route to host in /Users/bugzilla/Sites/test_my.php on line 11
Failed to connect to MySQL: No route to host
Why is it that I can connect from the command line, but not from php?
We experienced this error because the ip subnet used by our vagrant environment was the same as the subnet of the database server. We needed to recreate the database server on a different subnet.
I just experienced a similar problem but through which it looks like there was a different problem case. I was getting the same error:
Failed to connect to the database, please check your credentials: No route to host
And we were able to figure out the problem was actually that the disk space of our database was full (our server administrator was out sick for a while, and we automatically make snapshots, but only manually delete them on a regular basis. After a few days, the snapshots took up the space of the entire server and rendered it unresponsive).
I don't know if this will be the answer to anyone with this issue, but if someone does stumble upon this same error, hopefully this might help.

pdo_mysql unable to create mysqld.sock file

I'm adding PHP (php-fpm) to an existing Nginx Ubuntu 10.04 server and can't get pdo_mysql to work. I'm trying to connect to a MySQL server someplace else, but all the Googling answers I found are in regards to MySQL not working on the local server, so I'm not sure how to proceed.
I don't have mysqld installed, so I'm not sure if I need it, or if there's a way around this? Also I'm wondering if it can't create mysqld.sock because there is mysql user on the server?
Error:
SQLSTATE[HY000] [2002] Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) Fatal error: Call to a member function query() on a non-object
My PHP connection code:
$this->PDO = new PDO('mysql:host=' . $this->config->getValue('db_host') .
';dbname=' . $this->config->getValue('db_name'),
$this->config->getValue('db_user'),
$this->config->getValue('db_pass'));
My Query line it fails on:
$PDOStatement = $this->PDO->query($query);
Appreciate any help, thanks.
Couple of things you should check
D you have mysql-client installed? if you are connecting to remote machine. you don't need mysql running on your box but I think you will still need the client.
Make sure the host value is correct. Double & triple check
Lastly, Try connecting manually using command line, by the following command.
$ mysql -u <INSERT_USER_HERE> -p -h <INSERT_IP_OF_REMOTE_MACHINE_HERE> <INSERT_DB_NAME_HERE>
If it does not work. come back with exact error message.
Your server is attempting to connect to a local MySQL instance. If your database is on a different remote server, make sure that the the db_host value of your configuration file points to the correct hostname of the MySQL server.
You do not need mysqld installed, but you do need MySQL client libraries.
Are you sure that $this->config->getValue('db_host') is returning the correct value? The behavior you're describing sounds a lot like it's returning an empty or null value.

pg_connect crashes my php script

I'm trying to run a PHP script which has pg_connect($connection_string) and it just crashes my PHP script. I'm running it off of xampp on my computer, here are some facts:
If I put exit("test"); immediately above the pg_connect statement, it successfully displays the word "test" and terminates the script, so I know that my installation of xampp is working.
Using phpinfo() I can see that the postgresql extension is indeed loaded.
I can connect to the database server from pgadmin, so it's not a firewall issue or anything like that.
If I remove this exit statement, the pg_connect statement just hangs. There is no warning displayed or logged, and it never even gets past the function call. I even have:
$db_crm = pg_connect($connection_str);
if (!$db_crm) die("connection failed");
And "connection failed" is never even displayed. My browser just shows "this page cannot be displayed",after timing out.
What in the world could be causing this?
It's doubtful that the call is crashing PHP. More likely is that for some reason, the call is hanging for some reason and PHP's max execution time is being exceeded. You can try extending the time limit before making the pg_connect() call to see if it eventually comes back with something.
Check the Apache error logs
Check the php error logs
Make sure you have logging enabled in your Postgres config file.
In your config, set
log_min_error_statement (DEBUG5)
to grab everything possible.
Check the postgres error logs
Here it is guys:
I have no reason why, but adding sslmode=disable to the end of my connection string made it work. What reason would it have to crash? I am on a windows machine and phpinfo() says OpenSSL is enabled..
This sounds really stupid, but is your server running under SSL? I've had problems where a server will try to authenticate to ssl and hang indefinitely, trying to connect to a non-existent port.
sslmode=disable did the trick for me. To disable ssl in postgres-config ( ssl = false ) also worked.
For me, the Apache logs revealed that PHP was not finding the pg_connect() function, even though php-postgresql was installed. Restarting Apache fixed this, i.e.
sudo service httpd restart

Categories