PHP odbc_connect - failed to connect to firebird - php

I'm trying to connect to database by ODBC Setup
Firebird ODBC setup
<?php
$user = "SYSDBA";
$password = "masterkey";
$dsn= "DRIVER={Devart ODBC Driver for Firebird};Database=bazatestowa;Server=localhost;Port=3050";
$con=odbc_connect($dsn,$user,$password);
if($con){
echo "Connected";
}else{
echo "Failed"; }
?>
This is error I get:
Warning: odbc_connect(): SQL error: [Microsoft][driver manager
ODBC] Could not find data source name and no default driver specified
, SQL state IM002 in SQLConnect in
C:\Integracja-skrypty\index.php on line 5
I have no idea what to input in $dsn to make it work.
I translated the error message.
<?php
$user = "SYSDBA";
$password = "masterkey";
$dsn= "DRIVER={bazatestowa}";
$con=odbc_connect($dsn,$user,$password);
if($con){
echo "Connected";
}else{
echo "Failed";
}
?>
With this code the error is the same.
<?php
$user = "SYSDBA";
$password = "masterkey";
$dsn= "bazatestowa";
$con=odbc_connect($dsn,$user,$password);
if($con){
echo "Connected"; }else{ echo "Failed"; }
?>
With this code I have this error
PHP Warning: odbc_connect (): SQL error: [Microsoft] [ODBC driver
manager] Given DSN contains architecture mismatch between driver and
application, SQL state IM014 in SQLConnect in C: \ Integration-scripts
\ index.php on line 5

Related

SQLSTATE[28000]: [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Login failed for user

I'm using the following PHP connection file to connect to my SQL Server database.
<?php
$servername = "...";
$username = "...";
$password = "";
$dbname = "...";
try {
$conn = new PDO("sqlsrv:Server=$servername;Database=$dbname", $username, $password);
echo "Connected to $dbname at $servername successfully.";
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $pe) {
die ("Could not connect to the database $dbname :" . $pe->getMessage());
}
?>
I keep getting this error that says:
"SQLSTATE[28000]: [Microsoft][ODBC Driver 17 for SQL Server][SQL
Server]Login failed for user $username".
I have downloaded latest version of ODBC 17 and 18 and I expected this to resolve this issue, but it hasn't. My SQL Server authentication is set to SQL Server and Windows Authentication also.
if using laravel, in your .env file:
DB_CONNECTION=sqlsrv
DB_HOST=DESKTOP-91MB9QU\TESTSQLSERVER
DB_PORT=
DB_DATABASE=laravel_test
DB_USERNAME=sa
DB_PASSWORD='mypassword'
and you can use it. pay attention to DB_CONNECTION=sqlsrv and DB_HOST must has format of "PC-name\SQL-server-name" and DB_PORT has null value.
you can use similar way to pure php code.

Connect to local SQL Server(IP address) via browser PHP

I'm developing an website in HTML,PHP,etc... on shared hosting.
I have a local machine that has SQL Server and SSMS 2014 with information that i need to get on that website.
On my shared host i have this php settings:
Drivers of ODBC:
I have already connected via ip address to db in other local machine but when i try connect on browser i get the same error over and over.
I tried with sqlsrv_connect: (im not showing the ip for security reasons)
$serverName = "127.0.0.1";
$uid = "admin";
$pwd = "admin***";
$databaseName = "mydb";
$connectionInfo = array( "UID"=>$uid,
"PWD"=>$pwd,
"Database"=>$databaseName);
// Connect using SQL Server Authentication.
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if( ($errors = sqlsrv_errors() ) != null) {
foreach( $errors as $error ) {
echo "SQLSTATE: ".$error[ 'SQLSTATE']."<br />";
echo "code: ".$error[ 'code']."<br />";
echo "message: ".$error[ 'message']."<br />";
}
}
$tsql = "SELECT mor1_emp,mor2_emp,mor3_emp FROM rh_company";
sqlsrv_close( $conn);
I tried with PDO odbc:
try {
$dsn = "mysql:dbname=testdb;host={$db_host1}";
$connection = new PDO("odbc:Driver={SQL Server};Server=127.0.0.1;Database=mydb; Uid=admin;Pwd=admin***;");
} catch (PDOException $e) {
print "Error!: " . $e->getMessage() . "<br/>";
}
I tried with PDO mssql:
try {
$hostname = "127.0.0.1"; //host
$dbname = "mydb"; //db name
$username = "admin"; // username like 'sa'
$pw = "admin***"; // password for the user
$dbh = new PDO ("mssql:host=$hostname;dbname=$dbname","$username","$pw");
} catch (PDOException $e) {
echo "Failed to get DB handle: " . $e->getMessage() . "\n";
}
$stmt = $dbh->prepare("SELECT * FROM table");
$stmt->execute();
while ($row = $stmt->fetch()) {
print_r($row);
}
The error that i'm always getting with sqlsrv_connect:
SQLSTATE: IMSSP
code: -49
message: This extension requires the Microsoft ODBC Driver 11 or 13 for SQL
Server. Access the following URL to download the ODBC Driver 11 or 13 for SQL Server for x64: http://go.microsoft.com/fwlink/?LinkId=163712
SQLSTATE: IM002
code: 0
message: [unixODBC][Driver Manager]Data source name not found, and no default driver specified
With PDO(ODBC):
SQLSTATE[IM002] SQLDriverConnect: 0 [unixODBC][Driver Manager]Data source name not found, and no default driver specified
With PDO(mssql): could not find driver
With PDO the right syntax is :
$dbh = new PDO ("**sqlsrv**:Server=$hostname,$port;Database=$dbname","$username","$pw");

WAMP php ODBC Connection 'Warning'

I have a problem with ODBC in php (WAMP Server 2.5, PHP 5.5.12).
When I try to run:
$conn = odbc_connect("odbc_dsn", "user", "pwd");
if ($conn)
{
echo "Connection established.";
}
else
{
exit("Connection could not be established.");
}
I get a Warning:
Warning: odbc_connect(): in C:\wamp\www\Concepts\index.php on line 29
Connection could not be established.
If I change the "odbc_dsn" to something else (that doesn't exist) like "fdbasdf" then I get:
Warning: odbc_connect(): SQL error: [Microsoft][ODBC Driver Manager]
Der Datenquellenname wurde nicht gefunden, und es wurde kein Standardtreiber angegeben,
SQL state IM002 in SQLConnect in C:\wamp\www\Concepts\index.php on line
Connection could not be established.
(Translated)
The Data Source could not be found, and no default driver is given.
This tells me that the first execution was able to find the db, but did not open it... Why?
Is this another config thing? Is it trying to execute Client-Side? What can I do?
You have to specify the Host and Connect protocol:
$connect_string = "Driver={SQL Anywhere 12};".
"CommLinks=tcpip(Host=$db_host);".
"ServerName=$db_server_name;".
"DatabaseName=$db_name;";
// Connect to DB
$conn = odbc_connect( $connect_string, $db_user, $db_pass );

How to connect user name password protected ms access 2000 database (.*mdb) using php

Hi guys i want to connect USERNAME,PASSWORD protected MS ACCESS 2000 (.*mdb) database using PHP, ODBC or any other database connection. But given below code show WARNING and doesn't connect to the database. please anyone help.
CODE 1
$mdbFilename = "C:\Documents and Settings\Hp\Desktop\Door\DB\IMSDB.mdb";
$user = 'test';
$password ='123';
$connection = odbc_connect("Driver={Microsoft Access Driver (*.mdb)};DBQ=$mdbFilename;",$user,$password);
if($connection)
{
echo "Success";
}
else
{
exit("Connection Failed: ".$connection);
}
WARNING MESSAGE
Warning: odbc_connect() [function.odbc-connect]: SQL error: [Microsoft][ODBC Microsoft Access Driver] You do not have the necessary permissions to use the '(unknown)' object. Have your system administrator or the person who created this object establish the appropriate permissions for you., SQL state 42000 in SQLConnect in C:\xampp\htdocs\punch\test.php on line 6
Output -> Connection Failed
CODE 2
I tried given below code also. there are no any ERRORS or WARNING MESSAGE but not connect to the access database.
$mdbFilename = "C:\Documents and Settings\Hp\Desktop\Door\DB\IMSDB.mdb";
$systemDbFilename = "C:\Documents and Settings\Hp\Desktop\Door\DB\SYSTEM.MDW";
$user = 'test';
$password ='123';
$adoCon = new COM("ADODB.Connection") or die("Cannot start ADO");
$connection= $adoCon->Open("Driver={Microsoft Access Driver (*.mdb)};DBQ=$mdbFilename; SystemDB=$systemDbFilename;Uid=$user; Pwd=$password;");
if(($connection->State) > 0)
{
echo "Success";
}
else
{
exit("Connection Failed: ".$connection);
}
Output -> Connection Failed
CORRECT ANSWER
Finally I found the answer. I tried PDO to connect ODBC.
WORKING CODE
try {
$dbh = new PDO("odbc:Driver={Microsoft Access Driver (*.mdb)};Dbq=D:\Door\DB\IMSDB.mdb;SystemDB=D:\Door\DB\SYSTEM.MDW;Uid=test;Pwd=123;");
if($dbh)
{
echo "Connection Success";
}
}
catch (PDOException $e)
{
echo $e->getMessage();
}

How to establish a connection?

I am new to DB2.
$database = 'test';
$user = 'user1';
$password = 'pswd1';
$hostname = '10.250.10.10';
$port = 556;
$conn_string = "DRIVER={IBM DB2 ODBC DRIVER};DATABASE=$database;" .
"HOSTNAME=$hostname;PORT=$port;PROTOCOL=TCPIP;UID=$user;PWD=$password;";
$conn = db2_connect($conn_string, '', '');
if ($conn) {
echo "Connection succeeded.";
db2_close($conn);
}
else {
print($conn);
echo "Connection failed.";
die(db2_conn_errormsg());
}
all the values are correct. But connection have been failed. Plz advise me. and How to check in the PHPINFO(). whether the DB2 have been installed successfully or not.
I got the following error
Connection failed.[unixODBC][Driver Manager]Data source name not found, and no default driver specified SQLCODE=0
I'm not a PHP maven, but if you're using the ODBC driver, you probably need to catalogue the database in the ODBC driver manager. On Windows, search for ODBC in "Search Programs and Files". I'm not sure the equivalent on Linux

Categories