odbc_connect problem with mdbtools and unixodbc - php

I would like to acccess a mdb file in a windows machine (windows server 2003) from a linux machine (centos 6.10)
Im using mdbtools and unixodbc
so far what i did
odbc.ini
[mydatabase]
Driver = MDBTools
Description = Microsoft Access Try DB
Servername = localhost
Database =/mnt/example.mdb
UserName =Admin
Password =
port = 5432
odbcinst.ini
[MDBTools]
Description = MDBTools Driver
Driver64 = /usr/lib64/libmdbodbc.so.0
Setup64 = /usr/lib64/libmdbodbc.so.0
FileUsage = 1
UsageCount = 1
i check the connection using isql in terminal
isql -v mydatabase
and it returns connected
i can query the database successfully
by using query like this
select * from units
right now i want to connect the access database using php
test4.php
<?php
error_reporting(E_ALL); ini_set('display_errors', 1);
$myDB = odbc_connect("mydatabase","Admin","");
$query = "select * from units";
$result = odbc_exec($myDB, $query);
$report = odbc_fetch_row($result);
echo odbc_result($result, 1);
odbc_close($myDB);
?>
i received this error
Warning: odbc_connect(): SQL error: Failed to fetch error message, SQL state HY000 in SQLConnect in /var/www/test/test4.php on line 6
Warning: odbc_exec() expects parameter 1 to be resource, boolean given in /var/www/test/test4.php on line 11
Warning: odbc_fetch_row() expects parameter 1 to be resource, null given in /var/www/test/test4.php on line 12
Warning: odbc_result() expects parameter 1 to be resource, null given in /var/www/test/test4.php on line 13
Warning: odbc_close() expects parameter 1 to be resource, boolean given in /var/www/test/test4.php on line 15
im currently using
PHP Version 7.2.28
mySQL Version 5.7.29

Related

Returning warning error

http://go.wlg.co.nz/login.php
I had a page working fine and I swear I didn't change anything. Now its returning this:
Warning: mysql_connect() [function.mysql-connect]: Can't connect to
local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) in
/home/content/93/10501493/html/go/connect.php on line 15
Warning: mysql_select_db() expects parameter 2 to be resource, boolean
given in /home/content/93/10501493/html/go/connect.php on line 16
Warning: mysql_real_escape_string() expects parameter 2 to be
resource, boolean given in /home/content/93/10501493/html/go/login.php
on line 16
Warning: mysql_real_escape_string() expects parameter 2 to be
resource, boolean given in /home/content/93/10501493/html/go/login.php
on line 17
Warning: mysql_close() expects parameter 1 to be resource, boolean
given in /home/content/93/10501493/html/go/connect.php on line 18
Anything obvious jumps out?
Make sure mysql service is running
service mysqld start
Or
Are you connecting to "localhost" or "127.0.0.1" ? when you connect to "localhost" the socket connector is used, but when you connect to "127.0.0.1" the TCP/IP connector is used. You could
try using "127.0.0.1" if the socket connector is not enabled/working.

unixodbc with php command works but apache2 fail

I've installed unixodbc, freetds, php on Ubuntu 12.04.4 LTS (GNU/Linux 3.8.0-44-generic i686) and I get my query works fine with:
php /var/www/connect.php
but when access to localhost/connect.php I get:
Warning: odbc_connect(): SQL error: [unixODBC][Driver Manager]Data source name not found, and no default driver specified, SQL state IM002 in SQLConnect in /var/www/connect.php on line 8 Warning: odbc_exec() expects parameter 1 to be resource, boolean given in /var/www/connect.php on line 10 Warning: odbc_fetch_row() expects parameter 1 to be resource, null given in /var/www/connect.php on line 11 Warning: odbc_close() expects parameter 1 to be resource, boolean given in /var/www/connect.php on line 15
I think is about permissions.

Connecting to database with ODBC results in warnings and nothing printed

I am trying to use ODBC with php and I seem to be having some problems. This is my code:
<?php
$connect = odbc_connect("digitallibrary", "root", "");
$sql = "SELECT name FROM books";
$result = odbc_exec($connect, $sql);
echo $result;
while (odbc_fetch_row($result)) {
$name = odbc_result($result, "name");
print("$name\n");
}
odbc_close($connect);
?>
I have also installed mysql odbc connector and added this system DSN:
Datasource Name : digitallibrary
TCP/IP Server: localhost Port 80
user: root
database:digitallibrary
When I run my code I get this warnings but nothing printed:
Warning: odbc_connect(): SQL error: [Microsoft][ODBC Driver Manager] The specified DSN contains an architecture mismatch between the Driver and Application, SQL state IM014 in SQLConnect in E:\Program Files\xampp\htdocs\DigitalLibrary\index.php on line 9
Warning: odbc_exec() expects parameter 1 to be resource, boolean given
in E:\Program Files\xampp\htdocs\DigitalLibrary\index.php on line 11
Warning: odbc_fetch_row() expects parameter 1 to be resource, null
given in E:\Program Files\xampp\htdocs\DigitalLibrary\index.php on
line 14
Warning: odbc_close() expects parameter 1 to be resource, boolean
given in E:\Program Files\xampp\htdocs\DigitalLibrary\index.php on
line 18
what am I doing wrong?
Now, You are attempting to use a 64 bit application with a 32 bit ODBC driver or vice versa. You should check that what are you using the PHP application 64 bit or 32 bit. After that you have to start the correct ODBC administrator. There are 2 types which are 32 bit and and 64 bit.
If you are using 64 bit ODBC administrator: It is in Adminstrative tools, control panel
If you are using 32 bit ODBC administrator: You should go into the path %windir\syswow64\odbcad32.exe.
When you have set the right ODBC administrator. You will also need to create the system DSN. If you cannot find the MS Access driver in the administrator you'll need to download one for that architecture.
EDIT : you can download the 32 bit from here
Hope this helps.

Bake Models - CakePHP - Ubuntu

I am currently trying to bake models for a project in CakePHP. I have set up my database tables and baked my skeleton project. I then execute the following via terminal:
cake bake -app /home/gary/glecto/
Which then display's me the correct menu. When I choose "M" I get the following error
PHP Warning: mysql_connect(): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) in /usr/share/php/cake/libs/model/datasources/dbo/dbo_mysql.php on line 540
Warning: mysql_connect(): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) in /usr/share/php/cake/libs/model/datasources/dbo/dbo_mysql.php on line 540
PHP Warning: mysql_select_db() expects parameter 2 to be resource, boolean given in /usr/share/php/cake/libs/model/datasources/dbo/dbo_mysql.php on line 546
Warning: mysql_select_db() expects parameter 2 to be resource, boolean given in /usr/share/php/cake/libs/model/datasources/dbo/dbo_mysql.php on line 546
PHP Warning: mysql_get_server_info() expects parameter 1 to be resource, boolean given in /usr/share/php/cake/libs/model/datasources/dbo/dbo_mysql.php on line 554
Warning: mysql_get_server_info() expects parameter 1 to be resource, boolean given in /usr/share/php/cake/libs/model/datasources/dbo/dbo_mysql.php on line 554
PHP Warning: mysql_query() expects parameter 2 to be resource, boolean given in /usr/share/php/cake/libs/model/datasources/dbo/dbo_mysql.php on line 588
Warning: mysql_query() expects parameter 2 to be resource, boolean given in /usr/share/php/cake/libs/model/datasources/dbo/dbo_mysql.php on line 588
Your database does not have any tables.
Does anyone have any ideas on how I could solve this? I've been scratching my head for hours.
EDIT
Connection code
class DATABASE_CONFIG {
var $default = array(
'driver' => 'mysql',
'persistent' => false,
'host' => 'localhost',
'port' => 3306,
'login' => 'root',
'password' => '',
'database' => 'glectoMVC',
);
}
Also - If I look at the cakePHP generated startup page it confirms that my database connection is OK.
Managed to figure it out:
Apparently CakePHP isn't too happy with localhost as a host name. Instead I changed it to 127.0.0.1
Sup dude. this does look like mysql isn't running. Mainly as it's stating a can't connect and not a credentials fail. What LAMPP Stack are you running?
If all else fails and the LAMPP app you're using states the process is running successfully, ensure you haven't two instances of mysql running asynchronously.

Having Issues Connecting to Microsoft SQL Server Express (2008) from PHP

As the title says, I'm having issues connecting to MSSQL from a PHP Script.
The setup:-
PHP is running on an Apache Linux Server.
Microsoft SQL Server 2008 is on an XP Machine.
I've got Remote Connections turned on in the MSSQL Server.
The database bggs does exist.
The database is running (I can see a green arrow).
I have no firewall on the XP Machine.
If you have any debugging questions, don't hesitate to ask.
I'm using the following test script.
<?php
include('adodb5/adodb.inc.php');
$db =& ADONewConnection('odbc_mssql');
$db->debug = true;
$dsn = "Driver={SQL Server};Server=ozmodiar;Database=bggs;";
$db->Connect($dsn,'user','password');
$rs = $db->Execute('select * from admin_users');
print "<pre>";
print_r($rs->GetRows());
print "</pre>";
?>
Getting the following result.
Warning: odbc_connect() [function.odbc-connect]: SQL error: [unixODBC][Driver Manager]Data source name not found, and no default driver specified, SQL state IM002 in SQLConnect in /mnt/filestore/vhost/bggs/hr_database/Dev/includes/adodb5/drivers/adodb-odbc.inc.php on line 60
(odbc_mssql): SET CONCAT_NULL_YIELDS_NULL OFF
Warning: odbc_exec(): supplied argument is not a valid ODBC-Link resource in /mnt/filestore/vhost/bggs/hr_database/Dev/includes/adodb5/drivers/adodb-odbc.inc.php on line 530
IM002: [unixODBC][Driver Manager]Data source name not found, and no default driver specified
ADOConnection._Execute(SET CONCAT_NULL_YIELDS_NULL OFF, false) % line 1017, file: adodb.inc.php
ADOConnection.Execute(SET CONCAT_NULL_YIELDS_NULL OFF) % line 62, file: adodb-odbc.inc.php
ADODB_odbc._connect(Driver={SQL Server};Server=192.168.70.130;Database=bggs;, sa, knd121, ) % line 524, file: adodb.inc.php
ADOConnection.Connect(Driver={SQL Server};Server=192.168.70.130;Database=bggs;, sa, knd121) % line 9, file: test_db.php
Driver={SQL Server};Server=192.168.70.130;Database=bggs;: [unixODBC][Driver Manager]Data source name not found, and no default driver specified
(odbc_mssql): select * from admin_users
Warning: odbc_exec(): supplied argument is not a valid ODBC-Link resource in /mnt/filestore/vhost/bggs/hr_database/Dev/includes/adodb5/drivers/adodb-odbc.inc.php on line 530
IM002: [unixODBC][Driver Manager]Data source name not found, and no default driver specified
ADOConnection._Execute(select * from admin_users, false) % line 1017, file: adodb.inc.php
ADOConnection.Execute(select * from admin_users) % line 10, file: test_db.php
Fatal error: Call to a member function GetRows() on a non-object in /mnt/filestore/vhost/bggs/hr_database/Dev/includes/test_db.php on line 12
Disclaimer: I've only queried data from Microsoft SQL Server 2000, but through PDO_DBLIB although I believe the pre-requisite of having freetds drivers for either ADODB or PDO_DBLIB a certainty.
Judging by the initial error message, you do not have necessary drivers installed. In order for your application to access the server, you will need to install freetds, which will install the necessary drivers and allow you to set up the the ODBC connections. Check out: http://www.linuxjournal.com/article/6636
It's important to note that you need to set the "tds version = x.x" in your freetds global config or specific OBDC connection (/etc/freetds/freetds.conf by default on debian) exactly right, or the protocol freedtds uses with your server will not be correct and the script will bomb.

Categories