How to connect to another mysql server using mysql_connect - mysql-connect

is it possible to connect to another mysql server using mysql_connect function?
this is my code
$dbHost = "192.168.1.2:3306";
$dbUser = "root";
$dbPass = "pass";
$con = mysql_connect($dbHost, $dbUser, $dbPass);
and i got this mysql error
Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'root'#'192.168.1.9' (using password: YES)

Related

mssql in nodejs not connecting

Trying to connect to my database to create a local website but having connection issues.
Running in node.js, this is my server.js file:
let sql = require('mssql');
let config = {
user: 'sa',
password: 'password',
server: '10.0.1.130\\SQLSERVER',
database: 'MY_DB',
};
function connect() {
let dbConn = new sql.ConnectionPool(config);
dbConn.connect()
}
connect();
Upon running this I get the following error:
ConnectionError: Failed to connect to 10.0.1.130:undefined - self signed certificate
code: 'ESOCKET'
Not sure why it is removing \SQLSERVER but that seems to be my issue.
I know the credentials are all correct as I connect to this on another computer (ubuntu) but its being removed and we want to move it to windows, have not been able to connect to this point.
Any suggestions are appreciated.

Unable to connect to SQL server via PowerShell using secure password

I'm trying to connect to SQL server via PowerShell using the below (I'm new to this). I always get the error "login failed" when I use secure password (from Get-Credential or password stored in file). But if I pass the password as plaintext instead of secure string, it connects successfully. Could any one please suggest a method to pass secure password, ideally stored in an external file.
The code I ran and the error is below:
$cred = Get-Credential
$pwd = $cred.Password
$uid = $cred.UserName
$SQLServer = "."
$SQLDBName = "TestDB"
#Initialize connection string
$connString = "Data Source=$SQLServer;Database=$SQLDBName;User ID=$uid;Password=$pwd"
#Create a SQL connection object
$conn = New-Object System.Data.SqlClient.SqlConnection $connString
#Attempt to open the connection
$conn.Open()
if($conn.State -eq "Open")
{
# We have a successful connection here
# Notify of successful connection
Write-Host "Test connection successful"
$conn.Close()
}
Exception calling "Open" with "0" argument(s): "Login failed for user 'TestUser'."
At line:18 char:1
+ $conn.Open()
+ ~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : SqlException
Further details of error from SQL server:
Login failed for user 'TestUser'. Reason: Password did not match that for the login provided. [CLIENT: <local machine>]
Change this
$pwd = $cred.Password
to this
$pwd = $cred.GetNetworkCredential().Password
However, I would advise against storing a plain text password in memory like this. Your method requires it to--at best--be passed as a parameter in plain text, so you need a better method.
Try using this sqlserver module which supports the -Credential parameter in the Invoke-Sqlcmd function.
I was able to pass secure string as password by adding Integrated Security = True; parameter in connection string.
Thank you.

Uncaught PDOException: SQLSTATE[HY000] [1045] Access denied for user 'dbuser'#'localhost' (using password: YES)

Most answers were that it would be a right issue. But I assume not in this case, because mysql-connection still worked.
I am trying to connect to a mariadb10, which was on a server in my network
I am trying to connect from my localhost.
If I try in my terminal:
myuser#mylocalComputer ~ $ mysql -h myserver -P 3307 -u mydbuser -pmyconfidentalpassword
everything works fine!!
But If I try to connect by php scrypt by pdo I get the error:
<?php
$dsn = 'mysql: host=myserver:3307;dbname=mydbname';
$username = 'mydbuser';
$password = 'myconfidentalpassword';
$options = array(
PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8',
);
$dbh = new PDO($dsn, $username, $password, $options);
if(! $dbh ) {
die('Could not connect: ' . mysql_error());
}
$sql = 'select * from foo;';
$retval = mysql_query( $sql, $conn );
if(! $retval ) {
die('Could not select data: ' . mysql_error());
}
echo "Synced data successfully\n";
mysql_close($conn);
?>
The Error was:
PHP Fatal error: Uncaught PDOException: SQLSTATE[HY000] [1045] Access
denied for user 'mydbuser'#'localhost' (using password: YES) in
/home/myuser/Projekte/Hibiscus_extend/Hib_Nightly_sync.php:8
Stack trace:
/home/myuser/Projekte/Hibiscus_extend/Hib_Nightly_sync.php(8):
PDO->__construct('mysql: host=myse...', 'mydbuser',
'myconfidentalpassword', Array) {main} thrown in
/home/myuser/Projekte/Hibiscus_extend/Hib_Nightly_sync.php on line 8
What did I do wrong, and where?
Oh Oh Oh!
I found the solution!
The reason for the connection problem were just the empty spaces in $dsn
Wrong:
$dsn = 'mysql: host=myserver:3307;dbname=mydbname';
works fine
$dsn = 'mysql:host=myserver:3307;dbname=mydbname';

getting login to SQL Server 2005 with invalid credentials

The purpose of script is to log into a remote SQLSERVER and execute a query.
I used the below code to to ask for credentials and when the connection is open i will check using $conn.state , when its open i have to execute queries.
Even when i give invalid credentials, the control is going into Switch --> Open block and getting the statement out Logged in.The connection is Open.
clear
$servername = "Someserver";$databasename = "someDB";$c = Get-Credential
$connectionString = [string]::Format( "server={0};database={1};uid={2};pwd= {3};Integrated Security=True;", "$servername", "$databasename",$c.username,$c.GetNetworkCredential().password)
$conn = New-Object system.Data.SqlClient.SqlConnection
$conn.connectionstring = $connectionString
$conn.open()
switch ($conn.State)
{
"Open"{ write-host "Logged in.The connection is $($conn.State)"}
Default{ Write-Host "The connection is $($conn.State).Error connecting db."; }
}
$conn.close()

CPanel : Access denied for user 'root'#'localhost' (using password: NO)

I'm getting this error over and over again. I'm using CPanel.
Connection failed: SQLSTATE[28000] [1045] Access denied for user 'root'#'localhost' (using password: NO)
My code in connection file:
$dsn = 'mysql:dbname=mydomain_xxx;host=localhost';
$user = 'mydomain_yyy';
$password = 'password';