I've decided to switch from MySQL to PostgreSQL recently, mostly just to learn a new DB. It's been pretty painful, but I think I'm close.
I'm using php and PDO, my PDO driver has been successfully install and configured.
Opening my site, I get the error:
Connection failed: SQLSTATE[08006] [7] FATAL: Ident authentication failed for user "postgres"
I'm using the following connection calls (I've tried a few variations of calling user/pw in the $dsn variable, and in separate $user/$pass variables, and including port=5432):
$dsn = 'pgsql:dbname=db1;host=localhost;user=postgres;password=pass';
$db = new PDO($dsn);
Also, I'm able to log into my db from the command line:
$ su postgres
(pass)
$ psql db1
output:
could not change directory to "/home/ec2-user" psql (8.4.9) Type
"help" for help.
db1=#
Any ideas? I'd love to provide more info if needed.
Is your pg_hba.conf file all right? It's a known source of pain at the beginning w/ PostgreSQL. And, the situation you mention, is a good candidate for such kind of a problem. :-)
Related
I have a LAMP stack, and I thought it might be nice to use the MySQL configuration file to allow PDO to connect to the MySQL database without the need to place DB credentials within our code structure
So I created a group in /etc/my.cnf.d/gggg.cnf
[clientGggg]
user=uuuu
password=pppp
database=dddd
and can now connect to the DB through the command line with mysql --defaults-group-suffix=gggg
I then tried to create a test DB connection in PHP with
$db = new PDO("mysql", null, null, [PDO::MYSQL_ATTR_READ_DEFAULT_GROUP => 'gggg']);
but I received the error
Undefined constant PDO::MYSQL_ATTR_READ_DEFAULT_GROUP
Checking the PDO docs for this attribute reveals the following:
PDO::MYSQL_ATTR_READ_DEFAULT_GROUP (int)
Read options from the named group from my.cnf or the file specified with MYSQL_READ_DEFAULT_FILE. This option is not available if mysqlnd is used, because mysqlnd does not read the mysql configuration files.
and checking my phpinfo(); reveals I am indeed using mysqlnd
Why is this limitation in place? Is there a workaround? Or am I doomed to write/load my credentials into PHP?
I've been given access to an Oracle Server via ODBC and tested the connection using Oracle SQL Developer. These are the connection constants I've set in PHP:
define('APP_DB_HOST', '192.168.1.1');
define('APP_DB_PORT', '1521');
define('APP_DB_USER', 'MyUser');
define('APP_DB_PASS', 'MyPass');
define('APP_DB_SID', 'MyDatabaseSID');
define('APP_DB_SCHEMA', 'MyDatabaseSchema');
With ADOdb/ODBC, I should be able to use the below, so that I don't need to involve a tnsnames.ora entry:enter link description here
$dsn = '(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST='.APP_DB_HOST.')(PORT='.APP_DB_PORT.'))(CONNECT_DATA=(SERVICE_NAME='.APP_DB_SID.')));User Id='.APP_DB_USER.';Password='.APP_DB_PASS.';';
$db->PConnect($dsn, APP_DB_USER, APP_DB_PASS, APP_DB_SCHEMA);
I get the ADOdb Warning:
Warning: odbc_connect(): SQL error: [unixODBC][Driver Manager]Data source name not found, and no default driver specified, SQL state IM002 in SQLConnect in [..]/adodb/drivers/adodb-odbc_oracle.inc.php on line 87
Have others done this before, and if so, how so?
Beyond ADOdb, if anybody has a less complicated method of connecting by ODBC to Oracle with PHP7.4+, please do share.
I would also suggest you to move to the OCI8 native driver if you have a bit of time and not too much refactoring to do.
Your server should already have an Oracle client installed (to make the current TNS and ODBC work), so the only thing to do is to install the OCI8 Oracle DDL PHP extension. Just copy it to php/ext/ and load it in your php.ini
In the meantime, you can test if the following code works:
require_once("include/adodb5/adodb.inc.php"); //depends on your adodb folder
$conn = NewADOConnection("oci8");
$conn->connect(APP_DB_HOST, APP_DB_USER, APP_DB_PASS, APP_DB_SID);
For info, you can check if your system admin has already installed the OCI8 extension by looking for the OCI8 section in the PHPINFO :
If that is an option for you, I would strongly recommend to connect using the native oci8 driver, instead of relying on ODBC. Refer to ADOdb documentation for connection examples.
If you're stuck with ODBC, then I believe you need to adjust your DSN to specify the name of the driver you want to use in the connection string, e.g. Oracle in instantclient_19_6
Driver={OdbcDriverName};Server=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=xxx)(PORT=xxx))(CONNECT_DATA=(SERVICE_NAME=xxx)))
In my opinion it's better to specify the user id and password in the function call, i.e. $db->connect($dsn, $username, $password), but if you must have it in the connection string, you may want to try it with uid=xxx;pwd=xxx instead of User Id=xxx;Password=xxx
As an alternative, you could also create a System DSN in your ODBC configuration, and just refer to it by name, instead of hardcoding the TNS connection string directly in your code.
See also Create a DSN for the function odbc_connect for Oracle.
Trying to get it to connect in this environment:
Windows 7 Pro - 64bit
MS Access 2010 - 32bit (Tried both ACCDB and MDB versions)
ADODB abstraction package, Version 5.20.9
This is the test code:
include("C:\php\adodb5\adodb.inc.php"); // includes the adodb library
$db = NewADOConnection("access"); // A new connection
$db->Connect("", "", "", "D:\...\PhpPlay.accdb");
I've tried all kinds of variations for host, user and password params in the $db-> connect line, but no success. (The first two lines execute without error.) Here's the error message for line 3:
PHP Warning: odbc_connect(): SQL error: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified, SQL state IM002 in SQLConnect in C:\php\adodb5\drivers\adodb-odbc.inc.php on line 66
So I'm grasping at straws now. I'm concerned about the mixed 32/64 bit settings, but don't want to do something drastic unless someone can confirm that this is a problem.
Thank you for any ideas you might be able to provide!
Third party modules are not needed. Simply use PHP's PDO class and the already installed MS Access ODBC driver:
DSN Version
$database="D:\...\PhpPlay.accdb";
$db = new PDO("odbc:DSN=MS Access Database;DBq=$database;");
Driver Version
$database="D:\...\PhpPlay.accdb";
$db = new PDO("odbc:Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBq=$database;");
I try to use Jasper to generate report in Laravel. It's work perfect if I didn't use database, if I add database to get data from mysql database he gives me an error "Unable to load driver: com.mysql.jdbc.Driver". I install JDBC Connector and Setup ODBC connection to local mysql server:
Also I setup CLASSPATH to MySQL connector:
Because laravel print me that have some error to generate pdf with database connection I change it to print output command and ran it in terminal and he gives me an error that "Unable to load driver: com.mysql.jdbc.Driver", see next picture:
If you have ANY idea I will be grateful!
A lot of Java applications do not use the CLASSPATH environment variable, and it looks like jasperstarter is one of them.
Looking at http://jasperstarter.cenote.de/usage.html you need to use the command line option --jdbc-dir <directory with driver jar(s)>:
--jdbc-dir <dir> directory where jdbc driver jars are located. Defaults to ./jdbc
Alternatively, as you indicated in the comments, you can put the driver in the JasperStarter/jdbc folder, as that is the default location.
I have an EC2 instance running a WordPress site. The WordPress db is on a RDS instance. I want to connect to the db over SSL.
From what I've read, the MySQL extension that WordPress uses out of the box doesn't support SSL. So, I've installed a WordPress db script that uses MySQLi, which does support SSL.
The problem I encountered is that Amazon only supplies one key file (more info), and all the examples I can find using MySQLi over SSL include at least 3 files:
$db = mysqli_init();
$db->ssl_set('server-key.pem','server-cert.pem','cacert.pem',NULL,NULL);
I'm able to connect to my db over SSL from the mysql command line app. Can anyone tell me what I need to do to get PHP's MySQLi extension to work, given that I only have the 1 file?
Turns out this was less complicated than I thought. Turning up the error reporting level uncovered an error in my code that I hadn't caught. Using ssl_set this way works:
$db = mysqli_init();
$db->ssl_set(NULL,NULL,'/path/to/mysql-ssl-ca-cert.pem',NULL,NULL);
$db->real_connect($dbhost,$dbuser,$dbpassword,$dbname);
Try this:
$db = mysqli_init();
$db->ssl_set(null, 'https://rds.amazonaws.com/doc/mysql-ssl-ca-cert.pem', null, null, null);