Connecting to mysql within Glassfish - php

My goal is to run php on glassfish server. I installed Quercus and deployed it as an application within glassfish under (C:\glassfish4\glassfish\domains\domain1\applications\Quercus).
Now I try to connect to mysql. The mysql server is running and connection is verified through command (mysql -u root -p).
next test.php is created:
<?php
$servername="localhost";
$username="root";
$password="whatever";
$conn = new mysqli($servername, $username, $password);
if (!$conn) {
die("Failed : " . mysqli.connect_error());
}
echo "Connection Successful!";
?>
Running test.php gives the following message:
Warning: A link to the server could not be established.
url=jdbc:mysql://localhost/?
jdbcCompliantTruncation=false&characterSetResults=ISO885_1&characterEncoding=ISO8859_1&userServerPrepStmts=true
driver=com.mysql.jdbc.Driver com.caucho.quercus.QuercusModuleException:java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
Connection Successful!
From the message, it is probable that the mysql jdbc driver is not installed.
I added the driver to C:\glassfish4\glassfish\domains\domain1\lib\mysql-connector-java-8.0.11\mysql-connectior-java-8.0.11.jar. I am not sure how to add it from glassfish admin console. It is not shown under jdbc>connection pool.
2nd EDIT (based on comments):
The jar files are moved into ...\domain1\lib and ...\glassfish\lib as well. A full system restart was done.
To add a connection pool, I Followed the instructions on the following link:
https://dev.mysql.com/doc/connector-j/5.1/en/connector-j-usagenotes-glassfish-config.html
Then I get the following error message:
HTTP Status 500 - Internal Server Error:
type Exception report
message Internal Server Error
description The server encountered an internal error that prevented it from fulfilling this request.
exception java.lang.IllegalStateException: getoutputStream() has already been called for this response.
...

Related

Warning: oci_connect(): ORA-12637: Packet receive failed, trying to connect php to oracle 19c

Trying to connect php to oracle 19c, using php 8.1, apache lounge, this is the code i am trying to run
// Create connection
$conn = oci_connect($username, $password, $servername);
// Check connection
if (!$conn) {
$e = oci_error();
echo htmlentities($e["message"]);
}
error message: Warning: oci_connect(): ORA-12637: Packet receive failed
I have download and set the enviroment variable of both the latest oracle instant client and the version 19_15. But still getting the same error message have also uncommented the dll files oci8_19 and pdo_oci.

Warning: mysqli::mysqli(): (HY000/2002): Connection timed out in /opt/lampp/htdocs/

I use ubuntu 18 server by google cloud instance
I installed xammp, status is:
sudo /opt/lampp/lampp status
Version: XAMPP for Linux 5.6.15-1
Apache is running.
MySQL is running.
ProFTPD is running.
I send request http post by my angular application from localhost to this server.
It's not working.
this server application is PHP and mySql
when i browser the url server, i get error:
Warning: mysqli::mysqli(): (HY000/2002): Connection timed out in
/opt/lampp/htdocs/dashboard/models/sql.php on line 12 Connection
failed: Connection timed out
sql.php (line 12):
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
when I run those from localhost by xammp. it's working.
Thank!

MySQL Error mysqli::__construct(): (HY000/2002): Connection refused

I'm trying to run a PHP Script that contains a MySQL connection, when I run the command I get the following error in the terminal:
'Warning: mysqli::__construct(): (HY000/2002): Connection refused'
Even with PDO, I get the error:
'Fatal error: Uncaught PDOException: SQLSTATE[HY000] [2002] No such file or directory in ...'
I'm running the script on Mac OS X, and I have MAMP as APACHE/MySQL local server.
The command that I use for running the script is:
'php main.php'
and the content of the 'main.php' file with PDO is:
$db = new PDO('mysql:host=localhost;dbname=test',root,root);
with mysqli connector:
$db = new mysqli("localhost", "test", "root", "root");
I tried with '127.0.0.1' instead of 'localhost' and I get the same errors in both cases.
First of all, using localhost as a domain name is not supported in PHP. It will not be resolved as 127.0.0.1.
Second, even using 127.0.0.1 might not work in servers with multiple interfaces or with special routing rules. Run mysqlcheck --help and take the IP address shown at the bottom in the "host" field. For example:
port 3306
host 192.168.1.23
Use the IP and port that MySQL recognizes:
$db = new mysqli("192.168.1.23:3306", "test", "root", "root");

Mongodb:Failed to connect

I am new to MongoDB.I installed mongodb and used with Laravel framework.Its had been worked for a long time without any issues.But currently while i try to acess my website it shows:
Failed to connect to: localhost:27017: Connection refused
when i try to acces mongodb via command line,it shows:
warning: Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused
Error: couldn't connect to server 127.0.0.1:27017 (127.0.0.1), connection attempt failed at src/mongo/shell/mongo.js:146 exception: connect failed
when i try to access it via rock tool,it shows:
Unable to connect MongoDB, please check your configurations. MongoDB said:Failed to connect to: 127.0.0.1:27017: Connection refused.
what i will do? I can't figure what's wrong from my part since its working after the past months.I do nothing since the last days.Thanks in advance..
After a short break, I can find out the solution.
The origin of that issue is the unexpected shutdown of the system.So i run the below code in command prompt:
sudo rm /var/lib/mongodb/mongod.lock
mongod --repair
sudo service mongodb start
then after the above code run, its working fine :)

Mysql connection over SSL with PHP mysqli

I'm trying to setup PHP mysqli connection to MariaDB database for two VPS servers and need to encrypt the communications due to it being over public network.
Currently I can connect from the client server to database server via commandline mysql client normally and I have checked via tcpdump that the connection is encrypted. However for some reason I can't figure out the PHP part. It's relatively basic nginx + php5-fpm + mariadb setup but mysql is working on non default port.
Debian Jessie, Php5 5.6.7, Mariadb 10.0.16, nginx 1.6.2
Here's the test script:
<?php
$DB_NAME = '';
$DB_HOST = '111.111.111.111';
$DB_USER = 'username';
$DB_PASS = 'password';
$mysqli = mysqli_init();
if (!$mysqli) {
die('mysqli_init failed');
}
//have tried witha and without the following with multiple variations
$mysqli->ssl_set(NULL, NULL, NULL,'/etc/mysql/ssl/',NULL);
if (!$mysqli->real_connect($DB_HOST, $DB_USER, $DB_PASS, $DB_NAME, 11111, NULL,MYSQLI_CLIENT_SSL )) {
die('Connect Error (' . mysqli_connect_errno() . ') '
. mysqli_connect_error());
}
$query = "SHOW STATUS LIKE 'ssl_cipher'";
$result = $mysqli->query($query) or die($mysqli->error.__LINE__);
if($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
print_r($row);
}
}
else {
echo 'NO RESULTS';
}
mysqli_close($mysqli);
?>
Main error I'm getting without the ssl_set:
2015/07/11 15:58:34 [error] 2857#0: *374 FastCGI sent in stderr: "PHP message: PHP Warning: mysqli::real_connect(): SSL operation failed with code 1. OpenSSL Error messages:
error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed in /srv/www/test.php on line 15
PHP message: PHP Warning: mysqli::real_connect(): Cannot connect to MySQL by using SSL in /srv/www/test.php on line 15
PHP message: PHP Warning: mysqli::real_connect(): [2002] (trying to connect via tcp://192.168.130.123:42139) in /srv/www/test.php on line 15
PHP message: PHP Warning: mysqli::real_connect(): (HY000/2002): in /srv/www/test.php on line 15".....
Any ideas would be appreciated. This is really killing me.
Maybe this problem occurs due to the changes made in PHP 5.6. I guess you are using self-signed certificates? If your DB enables peer_name validation by DEFAULT, there is no way to disable this in PHP. So when generating you certificates you have to use the right "Common Name" for each one:
CA: hostname
Server: FQND, e.g. hostname.example.com
Client: somename
The important part is the server certificate where the Common Name has to be the same as the host you are connecting to.
What it looks like is this
SSL3_GET_SERVER_CERTIFICATE:certificate verify failed
My guess is that you don't have the correct CA set up. Some DB systems (like Amazon Web Services RDS) have their own CA file. You're using the capath argument so make sure the PEM files are in that path. If they are, the next thing I would do is switch to the third argument of ssl_set and specify the PEM file directly
$mysqli->ssl_set(NULL, NULL, '/path/to/ca.pem', NULL, NULL);

Categories