Here is the exception that I am getting:
ErrorException in DocketController.php line 65: odbc_connect(): SQL
error: [Microsoft][ODBC Driver Manager] The specified DSN contains an
architecture mismatch between the Driver and Application,
And here is the Docketcontroller.php line number 65:
// Localhost
$dsn = "test2";
$conn=odbc_connect($dsn, "QA", "QA");
if (!$conn) {
exit("Connection Failed: " . $conn);
}
$rs=odbc_exec($conn,$query);
//odbc_result_all($rs);exit;
$res=array();
$fields=array();
$i=0;
while($myRow = odbc_fetch_row( $rs ))
{
//echo"<pre>";print_r(odbc_result($rs,1));echo"</pre>";
$columns= odbc_num_fields ( $rs );
Related
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
I have some code that connects to a localhost MySQL server and displays if that database contains any matches of the search box. But I am now trying to connect to a SQL Server database and I just can't get it to work. Am I doing something wrong?
try {
$pdo = new PDO("sqlsrv:Server=xxx.xx.xx.xx,1433;Database=Live", $username, $password);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
// $pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
echo "Connected successfully";
} catch(PDOException $e) {
echo "Connection failed: " . $e->getMessage();
}
$stmt = $pdo->prepare("
SELECT *
FROM `dbo.Home`
WHERE `item_number` LIKE ? OR `stock_available` LIKE ?
");
$stmt->execute(["%" . $_POST['search'] . "%", "%" . $_POST['search'] . "%"]); <---LINE 54
$results = $stmt->fetchAll();
if (isset($_POST['ajax'])) { echo json_encode($results); }
I get the following error:
Connected successfully Fatal error: Uncaught PDOException:
SQLSTATE[42000]: [Microsoft][ODBC Driver 17 for SQL Server][SQL
Server]Incorrect syntax near 'dbo.Home'. in
/usr/local/var/www/2-search.php:54 Stack trace: #0
/usr/local/var/www/2-search.php(54): PDOStatement->execute(Array) #1
/usr/local/var/www/1-form.php(14): require('/usr/local/var/...') #2
{main} thrown in /usr/local/var/www/2-search.php on line 54
Any help would be greatly appreciated.
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");
I am getting following fatal error while accessing data from SQL Server 2014 through PHP Script.
Fatal error: Uncaught PDOException: SQLSTATE[42000]: [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]The SELECT permission was denied on the object 'test_table', database 'test_db', schema 'dbo'.
My PHP Script is
$server = 'KESAVATDL\SQLEXPRESS'; //KESAVATDL\SQLEXPRESS
$dbname = "acharya_db";
$usname="";
$passwd="";
try
{
$con=new PDO("sqlsrv:Server=$server;Database=$dbname",$usname,$passwd);
$con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
echo "Connected Successfully.";
}
catch(PDOException $e)
{
echo "Connection failed: " . $e->getMessage();
}
$sql = "SELECT * FROM test";
foreach ($con->query($sql) as $row) {
print_r($row);
}
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 );