I have an ODBC Connection that works:
$cqmconn = odbc_connect("Driver={SQL Server Native Client 10.0};
Server=JOHN-HP;
Database=cqmla;", "sa", "sa") or die ("Unable to connect to CQM site.");
However, I have an existing ODBC Driver called "cqm2" that connects to cqmla, but the line beow does NOT make a connection:
$cqmconn = odbc_connect("cqm2","sa","sa") or die ("Unable to connect to CQM site.");
I can, however, use that ODBC connection (and credentials) with other software and it works fine. What am I missing?
I ask this because while I certainly can use the first method here, I have ANOTHER proprietary system that I cannot get to work, although it does have an ODBC connection I can access via other software using the: $cqmconn = odbc_connect("cqm2","sa","sa") format. If I can get my existing connection to work here, I figure I should then be able to call the other one.
What am I missing?
PS: I've tried adding SQL_CUR_USE_ODBC to the end of the call, but it changed nothing.
Answering my own question:
It seems that odbc_connect() for PHP does NOT recognize User DSNs, only System DSNs. As a result, when I changed the DSN I was trying to use for a connection to a System DSN, I was able to use the: $cqmconn = odbc_connect("cqm2","sa","sa") paradigm.
Related
I am trying to make connection to remote MongoDb host through PHP. The server has authentication enabled on it with a user name and password.
I am trying to connect it through php MongoDB\Driver\Manager class. But Its not giving me any kind of response.
I am trying to do it using following connection uri format:
mongodb://[username:password#]host[:port][/[database][?options]]
according to
https://www.php.net/manual/en/mongodb-driver-manager.construct.php
But there is no response in connection variable where I am receiving it.
<?php
$conn = new MongoDB\Driver\Manager("mongodb://USER:PASSWORD#HOST:PORT/admin")
var_dump($conn);
?>
In the password, there are no special characters except #. Also when I hit this url directly in command line then it gives:
No such file or directory
I think according to the documentation, this connection uri format is correct and it should make the connection. But I am kind of stuck here and don't know what to do further.
I'm trying to connect to a MSSQL database with odbc in php.
My issue is similar to this issue, I can connect with tsql, but not with php.
The answer to the problem not work because I think I don't have SELinux installed (I don't know what it is, but pacman not found this package (or with a similar name) on my computer)
I don't understand why it doesn't work, odbc is installed and detected by php
print_r(PDO::getAvailableDrivers());
Array ( [0] => odbc )
I'm connecting by doing that:
$dsn = 'odbc:Driver=FreeTDS;Server=127.0.0.1;Port:1433;Database=[my base name]';
$pdo = new PDO($dsn, $user, $password);
My base is not in local, I use a ssh tunel because the base in accessible only at my school, and we need an ssh tunnel. And it work, I can connect myself to the base with tsql.
When I was connecting PHP to our MS SQL server, I could never get a connection established using ODBC drivers.
Instead, I downloaded the official PHP > SQL SERVER drivers direct from Microsoft. You can find them here.
Once installed, you must configure your php.ini file to include the new drivers, restart your web server and then use the following to open a new connection:
$conn = new PDO("sqlsrv:Server=SERVER_IP,1433;Database=DATABASE_TO_OPEN;");
I'm creating a web application in PHP and I need to connect to a database and retrieve information from it. The database in question is being hosted on phpMyAdmin. I'm currently using the following PHP code to connect to it.
//Attempt to connect to the database
$conn = mysql_connect('localhost', 'my_username', 'my_password') or die (mysql_error());
//Tell the user if they were successful
echo "Connection successful!";
//Close the connection
mysql_close();
When I run the website, it produces the following SQL error:
"No connection could be made because the target machine actively refused it."
I'm sure that my username and password are spelled correctly and I believe that 'localhost' is the server name that I need to use. Is there a different mysql_connect command that I need to use for phpMyAdmin? If not, how can I solve this problem?
Edit:
Upon publishing the website to Microsoft Azure (where I need to host it), I've found that it produces a different error:
"An attempt was made to access a socket in a way forbidden by its access permissions."
How will I be able to fix this error? Or will fixing the original error also solve this one?
Do not use mysql_* functions. They are deprecated. For more information, see this question: Why shouldn't I use mysql_* functions in PHP?
phpMyAdmin hosts nothing; it is simply a PHP application that connects to your database just like your own app is attempting to do.
Take a look at the phpMyAdmin config file and ensure you are using the same host. Also try the same username/password. If this succeeds, it's advisable to set up a dedicated username/password for your application. This can be done within phpMyAdmin on the privileges page.
Try use IP instead of localhost.
User has permissions? Check them
Trying to figure out how to connect to a local SQL Server with an online PHP file. However I am getting connection errors.
Warning: mysql_connect() [function.mysql-connect]: [2002] No
connection could be made because the target machine actively refused
it. (trying to connect via tcp://localhost:xxxx) in
E:\web\example.com\uploads\readDB.php on line 8
In particular I am having trouble trying to specify if, and where, I do the connection to the PC and then to the database with any associated passwords.
My current connection looks like this
mysql_connect("localhost","the_sql_server_name\SQLEXPRESS","mysql");
mysql_select_db("ACME") or die(mysql_error());
$data = mysql_query("SELECT * FROM TradingAccount")
or die(mysql_error());
My server is run locally (sql server studio management 2012), and I am trying to connect to its specific DB called ACME, from the table TradingAccount.
Can someone show me how to connect to this local table successfully with PHP? I use Windows Authentication at the moment when I run the server as well, in case that matters.
I haven't been able to find any useful resources, and I have only ever used PHP to connect to online DB's as well, nothing locally before.
Your Problem is in this line:
mysql_connect("localhost","the_sql_server_name\SQLEXPRESS","mysql");
You wrote the_sql_server_name\SQLEXPRESS there. I don't understand why. The syntax of the method is:
mysql_connect("hostname", "username", "password");
For more information, visit the PHP manual entry for mysql_connect.
How do I connect to a FMP database using an ODBC connection?
The name of the server is fmserver, and there is no Username or Password.
This is what I try:
$name = 'fmserver';
$conn = odbc_connect($name, '', '');
But for some reason, when I try it out, it brings me to a page that says (on chrome):
Server error
The website encountered an error while retrieving [URL]. It may be
down for maintenance or configured incorrectly.
Is there some method that I'm implementing wrong? I have the IP address too, and have tried that, but I can't seem to get that to work either.
Do you have the FileMaker ODBC driver installed and configured with "fmserver" as the DSN?
I would highly recommend you take a look at the FileMaker PHP API vs. ODBC.
http://www.filemaker.com/support/technologies/php.html