I am wondering when I instantiate a new PDO object it still uses the local IP of the server.
<?php
$dsn = 'mysql:host=10.0.0.4;charset=utf8';
$username = 'user';
$password = 'pass';
$pdo = new PDO($dsn, $username, $password);
?>
It gives me this weird error.
Fatal error: Uncaught exception 'PDOException' with message
'SQLSTATE[28000] [1045] Access denied for user 'user'#'10.0.0.5'
(using password: YES)' in /var/www/html/mysql_test.php:7
Stack trace:
#0 /var/www/html/mysql_test.php(7): PDO->__construct('mysql:host=10.0...', 'user', 'pass')
#1 {main}
thrown in /var/www/html/mysql_test.php on line 7
I noticed that it is connecting to 10.0.0.5 which is the IP address of the local server. The remote server (10.0.0.4) enables remote access.
Is there an internal config file for PDO that I should configure? The current PHP and PDO versions are 5.5.15RC1 and 5.5.38 respectively.
Related
I think I got it working again. By forcing the port being used to 80 for apache, and 3306 for mysql. I killed the processes that occupies those port.
This is the exact error showing
<br />
<b>Fatal error</b>: Uncaught mysqli_sql_exception: Access denied for user 'root'#'localhost' (using password: NO) in C:\xampp\htdocs\pcss\public\config\endpoints\db.php:16 Stack trace: #0 C:\xampp\htdocs\pcss\public\config\endpoints\db.php(16): mysqli->__construct('localhost', 'root', Object(SensitiveParameterValue), 'pcss') #1 C:\xampp\htdocs\pcss\public\components\medical-records.php(2): include('C:\\xampp\\htdocs...') #2 C:\xampp\htdocs\pcss\public\index.php(28): include('C:\\xampp\\htdocs...') #3 {main} thrown in C:\xampp\htdocs\pcss\public\config\endpoints\db.php on line 16
and these are the relevant codes
//C:\xampp\htdocs\pcss\public\config\endpoints\db.php
<?php
$servername = "localhost";
switch($_SERVER['HTTP_HOST']){
//this case part is modified, shouldnt matter i think
case "my website's link in 000webhost":
$username = "lorem";
$password = "lorem";
$database = "lorem";
break;
//this default part is not modified
default:
$username = "root";
$password = "";
$database = "pcss";
}
// Create connection
$conn = new mysqli($servername, $username, $password, $database);
?>
C:\xampp\htdocs\pcss\public\components\medical-records.php(2)
include("config/endpoints/db.php");
It used to work just fine until I reformatted my laptop. I even have a website running on 000webhost able to connect w/ MySQL there right now, and all other test files I've done have the same local credentials of
$servername = "localhost";
$username = "root";
$password = "";
and I can login with the shell command 'mysql -u root -p -h localhost' and pressing enter again when prompted for a password,
and I can control the users, databases, and etc... in phpMyAdmin.
Tried these:
"Connect failed: Access denied for user 'root'#'localhost' (using password: YES)" from php function
MySQL said: Documentation #1045 - Access denied for user 'root'#'localhost' (using password: NO)
MySQL Error: : 'Access denied for user 'root'#'localhost'
I've tried the alter thing, basically changes the password of the user you are pointing at. Still don't work.
I supposed you should do these stuffs if you can't access phpMyAdmin/MySQL to begin with.
I made a new user account with these credentials just to test:
User name: 'restapi'
Password: 'restapi'
I can login with it in shell's cmd w/ 'mysql -u restapi -p -h localhost', and typing 'restapi' again when prompted for a password. Still can't connect with mysql tho. This is the error:
Fatal error: Uncaught mysqli_sql_exception: Access denied for user 'restapi'#'localhost' (using password: YES) in C:\xampp\htdocs\pcss\public\config\endpoints\db.php:16 Stack trace: #0 C:\xampp\htdocs\pcss\public\config\endpoints\db.php(16): mysqli->__construct('localhost', 'restapi', Object(SensitiveParameterValue), 'pcss') #1 C:\xampp\htdocs\pcss\public\components\medical-records.php(2): include('C:\\xampp\\htdocs...') #2 C:\xampp\htdocs\pcss\public\index.php(28): include('C:\\xampp\\htdocs...') #3 {main} thrown in C:\xampp\htdocs\pcss\public\config\endpoints\db.php on line 16
and this is the code with that new user account:
//C:\xampp\htdocs\pcss\public\config\endpoints\db.php
<?php
$servername = "localhost";
switch($_SERVER['HTTP_HOST']){
//this case part is modified, shouldnt matter i think
case "my website's link in 000webhost":
$username = "lorem";
$password = "lorem";
$database = "lorem";
break;
//this default part is not modified
default:
$username = "restapi";
$password = "restapi";
$database = "pcss";
}
// Create connection
$conn = new mysqli($servername, $username, $password, $database);
?>
I also saw this one:
Access denied for user 'root#localhost' (using password:NO)
And tried changing the root's password, and I think this is the same thing with the alter thing. Just made me changed my configs (config.inc.php) again to access phpMyAdmin but still couldn't connect using PHP, still throwing the same access denied error.
I am trying to connect to my Google Cloud SQL instance with PHP (I am using PDO). When running my PHP file (from in the Google Cloud terminal), I receive the following error:
Uncaught PDOException: SQLSTATE[HY000] [2002] No such file or directory in /home/bob_brown_the_dev/index.php:17
Stack trace:
#0 /home/bob_brown_the_dev/index.php(17): PDO->__construct('mysql:dbname=ma...', 'root', '', NULL)
#1 {main}
thrown in /home/bob_brown_the_dev/index.php on line 17
This is what my PHP file looks like:
<?php
$username = 'root';
$password = getenv("MYSQL_PASS");
$dbName = 'main';
$connectionName = getenv("INSTANCE_CONNECTION_NAME");
$socketDir = getenv('DB_SOCKET_DIR') ?: '/cloudsql';
$dsn = sprintf(
'mysql:dbname=%s;unix_socket=%s/%s',
$dbName,
$socketDir,
$connectionName
);
// Connect to the database.
$conn = new PDO($dsn, $username, $password, $conn_config);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
?>
And this is what my app.yaml file looks like:
runtime: php73
entrypoint:
serve index.php
env_variables:
APP_DEBUG: true
LOG_CHANNEL: stderr
APP_STORAGE: /tmp
INSTANCE_CONNECTION_NAME: "<instance-id>:us-west2:<name>"
DB_SOCKET_DIR: "/cloudsql/<instance-id>:us-west2:<name>"
MYSQL_PASS: <password>
DB_CONNECTION: mysql
beta_settings:
cloud_sql_instances: "<instance-id>:us-west2:<name>"
Thanks in advance for any help!
EDIT:
It appears there was a problem when I fetched the environmental variables. Once I fixed that problem, the error changed to:
Uncaught PDOException: SQLSTATE[HY000] [2002] Not a directory in /home/bob_brown_the_dev/index.php:17
Stack trace:
#0 /home/bob_brown_the_dev/index.php(17): PDO->__construct('mysql:host=loca...', '...', '...')
#1 {main}
thrown in /home/bob_brown_the_dev/index.php on line 17
This is what the DSN looks like when I return it:
mysql:dbname=main;unix_socket=/cloudsql/<name>:us-west2:<other name>/<name>:us-west2:<other name>
If you're running your app in Cloud Shell, then you'll need to start the Cloud SQL Auth Proxy to mimic what App Engine does for you.
Start the proxy like this:
$ cloud_sql_proxy -instances=<project-id>:us-west2:<instance-name> -dir /cloudsql
Note if /cloudsql doesn't exist, you'll have to manually create it.
So I just finally installed the PDO drivers, and now I have another issue. When I try to use
<?php
$username = "root";
$password = "allen123";
$conn = new PDO('mysql:host=localhost;dbname=test', $username, $password);
?>
Just to connect to the DB, I get the following error
Fatal error: Uncaught exception 'PDOException' with message
'SQLSTATE[HY000] [2002] No such file or directory' in
/Users/idrisk/Colourity/site/index.php:4 Stack trace: #0
/Users/idrisk/Colourity/site/index.php(4):
PDO->__construct('mysql:host=loca...', 'root', 'allen123') #1 {main}
thrown in /Users/idrisk/Colourity/site/index.php on line 4
I've looked at other posts on SO about this issue, but they all seem different. Any ideas?
EDIT
So I installed the drivers via Macports and this is what I get once It was installed
To use mysqlnd with a local MySQL server, edit /opt/local/etc/php55/php.ini and set mysql.default_socket, mysqli.default_socket and pdo_mysql.default_socket to the path
to your MySQL server's socket file.
For mysql51, use /opt/local/var/run/mysql51/mysqld.sock
For mysql55, use /opt/local/var/run/mysql55/mysqld.sock
For mysql56, use /opt/local/var/run/mysql56/mysqld.sock
For mariadb, use /opt/local/var/run/mariadb/mysqld.sock
For percona, use /opt/local/var/run/percona/mysqld.sock`
The other answers say to use something else.
I've recently setup a load balancer, it has 3 public servers serving users.
Here's where I have my problem... the site uses PDO to connect to database, the MySQL server is on one single remote server for all them to connect to and it doesn't seem to work.
Here's the error I get:
"Fatal error: Uncaught exception 'PDOException' with message 'could not find driver' in /var/www/pingrglobe.com/backend/database.php:8 Stack trace: #0 /var/www/pingrglobe.com/backend/database.php(8): PDO->__construct('mysql:host=162....', 'root', 'nope') #1 /var/www/pingrglobe.com/structure/header.php(4): require('/var/www/pingrg...') #2 /var/www/pingrglobe.com/index.php(2): require('/var/www/pingrg...') #3 {main} thrown in /var/www/pingrglobe.com/backend/database.php on line 8"
Here's my code:
$host = "162.243.135.167";
$user = "root";
$pass = "nope;)";
$dbname = "pingrglobe";
$db = new PDO("mysql:host=".$host.";port=3306;dbname=".$dbname, $user, $pass);
I have a problem while trying to connect to my SQL Server 2000 database using pdo_mssql with this line:
$connection = new PDO ('mssql:host=localhost;dbname=DNAME', 'user', 'password');
The exception is the following:
PHP Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000] General SQL Server error: Check messages from the SQL Server. (severity 5)' in C:\Inetpub\wwwroot\public\test.php:2 Stack trace: #0 C:\Inetpub\wwwroot\public\test.php(2): PDO->__construct('mssql:host=loca...', 'user', 'password') #1 {main} thrown in C:\Inetpub\wwwroot\public\test.php on line 2
If I make the connection using the function mssql_connect() as follows, I obtain no error and my connection is correctly made:
$link = mssql_connect ('localhost', 'user', 'password');
Any idea? Where can I read the detailed error message? Thanks
My database name had the character "-", removing it solved the problem!