I'm using remote MSSQL base via php + linux ODBC. All was fine, but today i wrote query with SET + PIVOT and got error:
[unixODBC][FreeTDS][SQL Server]SELECT failed because the following SET options have
incorrect settings: 'ANSI_NULLS, QUOTED_IDENTIFIER, CONCAT_NULL_YIELDS_NULL,
ANSI_WARNINGS, ANSI_PADDING'. Verify that SET options are correct for use with indexed views
and/or indexes on computed columns and/or filtered indexes and/or query notifications and/or
XML data type methods and/or spatial index operations.
I tried to write SET ANSI_NULLS ON etc but it wont works, there is 0 fields in result.
The same query executed directly on server via MSSQL studio works perfectly.
Any idea where can be a problem?
Thanks.
UPDATE:
freetds.conf
[syserver]
host =192.168.1.200
port = 1433
tds version = 7.0
AnsiNPW=YES
QuotedID=YES
odbc.ini
[sy_odbc]
Driver = FreeTDS
Description = ODBC connection via FreeTDS
Trace = No
Servername = syserver
Database = Insy
odbcinst.ini
[FreeTDS]
Description = TDS driver (Sybase/MS SQL)
Driver = /usr/lib/odbc/libtdsodbc.so
Setup = /usr/lib/odbc/libtdsS.so
CPTimeout =
CPReuse =
FileUsage = 1
Before I got tds version=6.0, and after changing it up to 7.0 all errors such ANSI_NULLS gone, but I still have 0 rows in result. AnsiNPW=YES and QuotedID=YES do nothing for me. If try to change version to 8.0 in result of simple query i have ??????????. TDS_version=7.0 in odbc.ini also do nothing.
My query here.
And my connection string is: $conn=odbc_connect('sy_odbc','t','t');
Update 2:
Some of my php pages stop working when i had changed TDS_version to 7.0 or 7.2, so i return it back to 6.0.
Connection string as you proposed don't work for me. At all. (I'm using mine more than year, and it was fine, before that issue)
Here is errorlog for problem query with 6.0 version (here we have ANSI_NULLS etc warnings)
Here is errorlog for problem query with 7.0 version (There is no warnings, but 0 rows in result)
There are two more things I can think of Sergii:
1) Your connection string. The manual says your connection string should look like this:
$conn = odbc_connect('Driver={sy_odbc};Server=192.168.1.200;Database=Insy', $username, $password);
So I'd give that a try first and see if it helps.
2) Any time you are having problems with ODBC connections you should turn on logging so you can capture error messages. To do this add the following lines to your /etc/odbcinst.ini file:
[ODBC]
Trace = yes
TraceFile = /tmp/odbc.log
If your query still doesn't work, edit your question and add the output from the odbc.log file (assuming there are error messages in it).
Related
My Ubuntu vagrant Laravel Homestead set up has been configured to connect to MSSQL. Randomly it's starting throwing the following error on every query going to the MSSQL database (on a Windows server).
Any ideas? I can't find much info re:this available on Google.
I restarted PHP and confirmed SQLSRV modules are loaded.
SQLSTATE[IMSSP]: An unsupported attribute was designated on the PDO object. (SQL: select top 10 * from [orders] where [ordertype] = SO order by [orderdate] desc)
Check this issue report PDO::ATTR_PERSISTENT is not supported. Also they are reporting problems with PDO::ATTR_ERRMODE so check your connection for these two parameters.
My Ubuntu vagrant Laravel Homestead set up has been configured to connect to MSSQL. Randomly it's starting throwing the following error on every query going to the MSSQL database (on a Windows server).
Any ideas? I can't find much info re:this available on Google.
I restarted PHP and confirmed SQLSRV modules are loaded.
SQLSTATE[IMSSP]: An unsupported attribute was designated on the PDO object. (SQL: select top 10 * from [orders] where [ordertype] = SO order by [orderdate] desc)
Check this issue report PDO::ATTR_PERSISTENT is not supported. Also they are reporting problems with PDO::ATTR_ERRMODE so check your connection for these two parameters.
I've recently moved web servers, and the new web server has a different version of PHP.
New Server: PHP 5.5.3-1ubuntu2 (cli)
Old Server: PHP 5.3.10 (cli)
On the database server, my.cnf is set to allow local-infile.
I can use load data local infile from:
- HeidiSQL
- The command line client running on the new web server using --local-infile=1
- PHP, using PDO, from the old web server
However, when I try to connect from the new web server, using PHP with PDO, I get:
A database problem has occurred: SQLSTATE[42000]: Syntax error or access violation: 1148 The used command is not allowed with this MySQL version
php.ini:
[MySQL]
; Allow accessing, from PHP's perspective, local files with LOAD DATA statements
; http://php.net/mysql.allow_local_infile
mysql.allow_local_infile = On
PDO constructor:
$this->db_conn = new PDO("mysql:host=$host;dbname=$dbname;port=$port", $user, $pass, array(PDO::MYSQL_ATTR_LOCAL_INFILE => 1));
I've also tried ini_set('mysql.allow_local_infile', 1) and ini_set('mysql.allow_local_infile', true) in the PHP script.
The LOCAL keyword is needed because the files are hosted on the web server, not the database server.
What else does PHP 5.5 want from me?
You need to configure both the client and the server to allow this command:
Make sure the server allows LOAD DATA LOCAL INFILE. Edit /etc/my.cnf on the MySQL server:
[server]
local-infile=1
Set the PDO attribute in your PHP script:
<?php
$dsn = "mysql:host=localhost;dbname=test";
$user = "root";
$password = "root";
$pdo = new PDO($dsn, $user, $password, array(PDO::MYSQL_ATTR_LOCAL_INFILE=>1));
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$pdo->exec("LOAD DATA LOCAL INFILE 'foo.csv' INTO TABLE foo FIELDS TERMINATED BY ','");
This needs to be set in the driver options argument to the constructor, not in a subsequent call to setAttribute().
I just tested the above code example successfully with PHP 5.5.8 and Percona Server 5.6.15 on CentOS Linux 6.5.
If you still have trouble, you may have a build of the MySQL client or PDO that does not permit local-infile. The requirements are described in http://dev.mysql.com/doc/refman/5.6/en/load-data-local.html
The mysql.allow_local_infile option in your php.ini is not relevant to PDO.
Your code is absolutelty correct no need to change as the error lies in your database file.
error cause
The reason of your error caused as you have created the database backup through commandline and trying to upload data through custom php script.
solution
There are 2 solutions available to resolved the issue are:-
Try to load database through commandline and if you dont have access to commandline then you can ask your service provider to do upload for you. As he has to just run simple command.
Open the databse file in text editor and check the headers which encoding is used. Then read the data and de-encode it then run the insert command.
If the problem doesnt resolve then let me know..
I'm trying to use the LOAD DATA LOCAL INFILE command in MySQL, but I keep getting an error in PHP/Joomla stating: The used command is not allowed with this MySQL version
I've spent quite a while Googling around, but the only suggestions I've seen involve adding local-infile = 1 to my my.cnf file (which I've already done, in [client], [mysql], and [mysqld]).
Additionally, if I connect from my Apache server to the MySQL server from the command line (so not using PHP), I can run LOAD DATA LOCAL without issue (so it can't be a permissions thing).
I've also checked php.ini, and sure enough, mysqli.allow_local_infile is set to 'On'.
Am I missing something here?
Do you have to do something special in Joomla to make this work correctly?
I just answered a similar question here, maybe it can help:
After going from MySQL 5.0 to 5.5 I found out that I suddenly have to enable LOCAL INFILE specifically when creating the connection in PHP.
Using mysql:
mysql_connect(server,user,code,false,128); // 128 enables LOCAL INFILE
mysql_select_db(database);
Using mysqli:
$conn = mysqli_init();
mysqli_options($conn, MYSQLI_OPT_LOCAL_INFILE, true);
mysqli_real_connect($conn,server,user,code,database);
I ran into the same problem, in my case it was the Joomla user lacking privileges that root has; giving the full privileges to the J user solved it, but then my component is for distribution so I changed to using standard .sql file and parsing / creating them manually. Hope this helps.
This is driving me nuts! I am getting the classic "Can't connect to local MySQL server through socket '/var/run/mysql4d/mysql4d.sock' (13)".
Everything I've dug up so far tells me my setup should be OK (eg, defining the sockets in php.ini and my.cnf, etc). Worse... phpmyadmin works with the same un/pw I am using in my own php. So obviously it's possible to connect, but I am screwing it up
I tried reverse-engineering the connection from phpmyadmin, but gave up it as too convoluted after a couple hours.
Can anyone offer some advice?
My configuration: Ubuntu 9.10 (Karmic), Apache 2.2, PHP 5.2.6, MySQL 4.1.22 (for legacy app reasons).
my.cnf (/var/lib/mysql4/my.cnf):
[client]
port = 3306
socket = /var/run/mysql4d/mysql4d.sock
[mysqld]
port = 3306
socket = /var/run/mysql4d/mysql4d.sock
php.ini (/etc/php5/apache2/php.ini):
[MySQL]
mysql.default_socket = /var/run/mysql4d/mysql4d.sock
[MySQLi]
mysql.default_socket = /var/run/mysql4d/mysql4d.sock
Same problem using mysql instead of mysqli, btw.
EDIT:
I should mention that I have installed mysql4 alongside the ubuntu default install of php & mysql for use with a legacy application and it is this installation that I am having trouble connecting with. I tried this:
ini_set('mysql.default_socket', '/var/run/mysql4d/mysql4d.sock');
and now the connection goes thru, but all queries return empty sets. (cries in frustration)
This sounds like a permission problem in /var/run/mysql4d/mysql4d.sock. What user are you running this as? Are the permissions o.k. on file system level?
If you Google for the error messages, you'll find a lot of people who had this and it was always a permission issue, sometimes due to an activated SELinux. Check this thread for a few possible solutions.