PHP ODBC Extension - Data Source Name Too Long - php

I've been trying to install the ODBC extension for PHP onto one of our servers (Redhat), and i think it got it installed correctly but now when i try to test the connection i get the error message about the data source name being too long... It sounds like a simple thing to fix, but i can't work out..how..or where.
Basically these are the settings i've got at the moment:
# odbcinst -j
DRIVERS............: /etc/odbcinst.ini
SYSTEM DATA SOURCES: /etc/odbc.ini
FILE DATA SOURCES..: /etc/ODBCDataSources
USER DATA SOURCES..: /root/.odbc.ini
SQLULEN SIze.......: 4
SQLSETPOSIROW......: 2
I've got my MySQL driver defined in the odbcinst.ini as such:
[MySQL]
Description = ODBC for MySQL
Driver = /usr/lib/libmyodbc5.so
Setup = /usr/lib/libodbcmyS.so
FileUsage = 1
I've double checked and the Driver & Setup paths are correct and pointing to the correct files.
So now I'm trying to add a System Data Source by editing the odbc.ini file. I've tried it in various different formats, following examples from different sites, e.g.
http://developer.mindtouch.com/en/kb/Using_the_ODBC_extension_on_Linux#Install_unixODBC
http://dev.mysql.com/doc/refman/5.0/en/connector-odbc-configuration-dsn-unix.html
As you can see i've commented some of them out and tried different ones:
;[mytest]
;driver = MySQL
;Database = moodle
;Server = localhost
;Socket = /var/lib/mysql/mysql.sock
;[mynew]
;Description = MySQL
;Driver = MySQL
;SERVER = localhost
;USER = root
;PASSWORD =
;PORT = 3306
;DATABASE = moodle
[Default]
Driver = /usr/lib/libmyodbc5.so
Description = Connector/ODBC 5 Driver DSN
SERVER = localhost
PORT =
USER = root
Password =
Database = moodle
SOCKET =
However, whenever i run
isql -v
to see if there are any problems, i always get:
[IM010][unixODBC][Driver Manager]Data source name too long
[ISQL]ERROR: Could not SQLConnect
My googling around the error only ever seems to turn up results for people having a connection string within something like ASP, nothing about how to get it working on the server in this way...
Could anyone offer me any advice/help?
If you need more information, let me know.
Thank you!

When launching isql you have to specify the data source name as defined in the man page.
SYNOPSIS
isql DSN [UID [PWD]] [options]
OPTIONS
DSN Name of the data source you want to connect to.
Given your configuration in /etc/odbc.ini, you would launch isql -v Default to test your connection. In the configuration file, the data source name is the one you've defined between brackets.

Related

phpmyadmin import & overwrite table

this has been annoying me for weeks and i cant find a proper solution.
im running a VPS
centos 7 (and aapanel which has no relevance)
php 7.4
mysql 5.7
phpmyadmin 5.0
ive gone into phpmyadmin, exported a table, updated 5000 rows, and i want to import and overwrite the old data into the same table.
the 'browse' and import is not an option(as vps error 503/low ram to load) and so ive tried to add it by SQL tab:
LOAD DATA LOCAL INFILE '/database/links.csv'
INTO TABLE links
FIELDS TERMINATED BY ','
LINES TERMINATED BY '\n';
with permission denied
*yes, ive added
[MySQLi]
mysqli.allow_local_infile = On
to my.conf and even tried to add to php.ini
and restarted apache and even tried removing LOCAL(Saw that on stack too) with no avail*
does anyone have an updated version, or know of a solid solution to this annoying, but should be easy solution?
EDIT
root user = fixes issue for permission denied... but...
LOAD DATA INFILE
error
#1290 - The MySQL server is running with the --secure-file-priv option so it cannot execute this statement
--secure-file-priv has been removed from my.conf and apache restarted and error still appears
LOAD DATA LOCAL INFILE
error
#2000 - LOAD DATA LOCAL INFILE is forbidden, check mysqli.allow_local_infile
mysqli.allow_local_infile = On is still in my.conf
file has full permissions(777) and tried changing owner (www/root/mysql)
Carefully read difference between LOCAL and non-LOCAL versions of LOAD DATA command: https://dev.mysql.com/doc/refman/5.7/en/load-data.html#load-data-local
You need to check state of secure_file_priv config variable for non-LOCAL version of command:
mysql> select ##secure_file_priv;
+-----------------------+
| ##secure_file_priv |
+-----------------------+
| /var/lib/mysql-files/ |
+-----------------------+
File must be located here.
For LOCAL version of the command you must check permission of client to read such file. In case of phpmyadmin it will be php as client.
In both cases double check that mysql server or php both have enough permissions to enter directory and read file. The easiest way is to login under system user for mysql or php and just try to read file:
sudo -u mysql_or_php_user /bin/bash
or
su -s /bin/bash mysql_or_php_user
then
head /database/links.csv

Cacti on pgsql in Laravel

Description
I have a laravel app, that I am trying to integrate that with Cacti : is a complete network graphing solution designed to harness the power of RRDTool's data storage and graphing functionality.
Steps
I've downloaded it, and place it in my public/ directory.
Now, when I go to my http://localhost:8888/cacti/
I got
First Try
FATAL: Cannot connect to MySQL server on 'localhost'. Please make sure you have specified a valid MySQL database name in 'include/config.php'
Then, I opened up 'include/config.php'. Since my goal is to try to connect it to pgsql instead of mysql, so I here is my current settings
$database_type = "pgsql";
$database_default = 'cacti';
$database_hostname = 'localhost';
$database_username = 'postgres';
$database_password = '';
$database_port = '5432';
$database_ssl = false;
As soon as I hit saved, and refresh the page http://localhost:8888/cacti/
Second Try
Now, I got : The localhost page isn’t working :(
Database
I've already created a cacti database on my localhost running on port 5432.
As given in this site, cacti is designed to work with only MySQL.
Cacti is written in PHP and supports MySQL only for storing the
RRDTool data.
Though, there is this link to setup the cacti with pgsql .
PostgreSQL Host Template

How to see full mysql query that my script send to xammp local server?

I have an error in my script and want to see full mysql query but mysql error log don't show any queryies that my script send.
I changed my.ini file and add
general_log = 1
slow_query_log = 1
slow_query_log_file = "C:/xampp/mysql/data/mysql-slow.log"
I found this in slow-query.log file
c:\xampp\mysql\bin\mysqld.exe, Version: 5.6.21-log (MySQL Community Server (GPL)). started with:
TCP Port: 3306, Named Pipe: C:/xampp/mysql/mysql.sock
Time Id Command Argument
But how to see full query of my script? Thanx in advance!
To see all queries, not only the slow ones, you have to specify also general_log_file:
general_log=1
general_log_file="C:/xampp/mysql/data/query.log"
And then restart mysql server.

LOAD DATA LOCAL INFILE fails - from php, to mysql (on Amazon rds)

We're moving our database from being on the webserver to a separate server (from an Amazon EC2 webserver to an RDS instance.)
We have a LOAD DATA INFILE that worked before that is going to need the LOCAL keyword added now that the database will be on a different machine to the webserver.
Testing on my dev server, it turns out that it doesn't work:
I can still LOAD DATA INFILE from php as I have been
I can LOAD DATA LOCAL INFILE from mysql commandline (with --local_infile=1)
I can't LOAD DATA LOCAL INFILE from php.
Between those 2 things that do work, it rules out:
problems with the sql or php code
problems with the upload file, including syntax and file permissions
mysql server settings problems
The error I get is:
ERROR 1148 (42000): The used command is not allowed with this MySQL version
(I get that error from the mysql commandline if I don't use --local_infile=1)
A few other bits of relevant info:
Ubuntu 12.04, mysql 5.5.24, php 5.3.10
I'm using php's mysql_connect (instead of mysqli, because we're planning on using facebook's hiphop compiler which doesn't support mysqli.)
Because of that, the connect command needs an extra flag set:
mysql_connect($dbHost, $dbUser, $dbPass, false, 128);
I've used phpinfo() to confirm that mysql.allow_local_infile = On
I've tried it on Amazon RDS (in case it was a problem in my dev server) and it doesn't work there either. (With the local_infile param turned on.)
The only thing I've read about that I haven't tried is to compile mysql server on my dev server with the flag turned on to allow local infile... but even if I get that working on my dev server it's not going to help me with Amazon RDS. (Besides which, LOAD DATA LOCAL INFILE does work from the mysql commandline.)
It seems like it's specifically a problem with php's mysql_connect()
Anybody using LOAD DATA LOCAL INFILE (maybe from Amazon RDS) that knows the trick to getting this to work?
I've given up on this, as I think it's a bug in php - in particular the mysql_connect code, which is now deprecated. It could probably be solved by compiling php yourself with changes to the source using steps similar to those mentioned in the bug report that #eggyal mentioned: https://bugs.php.net/bug.php?id=54158
Instead, I'm going to work around it by doing a system() call and using the mysql command line:
$sql = "LOAD DATA LOCAL INFILE '$csvPathAndFile' INTO TABLE $tableName FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '\\\"' ESCAPED BY '\\\\\\\\' LINES TERMINATED BY '\\\\r\\\\n';";
system("mysql -u $dbUser -h $dbHost --password=$dbPass --local_infile=1 -e \"$sql\" $dbName");
That's working for me.
Here's a check list to rule out this nasty bug:
1- Grant the user FILE privileges in MySQL, phpMyAdmin generaly does not cover this privilege:
GRANT FILE ON *.* TO 'db_user'#'localhost';
2- Edit my.cnf in /etc/mysql/ or your mysql path:
[mysql]
local-infile=1
[mysqld]
local-infile=1
3- In php.ini at /etc/php5/cli/ or similar:
mysql.allow_local_infile = On
Optionally you can run ini_set in your script:
ini_set('mysql.allow_local_infile', 1);
4- The database handler library must use the correct options.
PDO:
new PDO('mysql:host='.$db_host.'.;dbname='.$db_name, $db_user, $db_pass,
array(PDO::MYSQL_ATTR_LOCAL_INFILE => 1));
mysqli:
$conn = mysqli_init();
mysqli_options($conn, MYSQLI_OPT_LOCAL_INFILE, true);
mysqli_real_connect($conn,server,user,code,database);
5- Make sure that the INFILE command uses the absolute path to the file and that it exists:
$sql = "LOAD DATA INFILE '".realpath(is_file($file))."'";
6- Check that the target file and parent directory are readable by PHP and by MySQL.
$ sudo chmod 777 file.csv
7- If you are working locally you can remove the LOCAL from your SQL:
LOAD DATA INFILE
Instead of:
LOAD DATA LOCAL INFILE
Note: Remember to restart the MySQL and PHP services if you edit their configuration files.
Hope this helps someone.
As referred in this post, adding 3rd and 4th parameter to mysql_connect are required to get LOAD LOCAL DATA INFILE working. It helped me. Any other suggestions (apparmor, local-infile=1 in my.cnf widely discussed in internet) did not help. Following PHP code worked for me!
mysql_connect(HOST,USER,PASS,false,128);
True, this is in manual, too.
use the following line that client activates with infile true
mysql --local-infile=1 -u root -p
If you're doing this in 2020, a tip for you is to check your phpinfo.php or php --ini for the location of the configuratin file. For me I was using virtualmin and changing the php ini file but my site had it's own specific ini file. Once I located it's location and changed it everything went back to normal.

Why does the connection to ASE fail when password encryption is required?

How can I password encrypt the database server connections from PHP to Sybase ASE?
The PHP connection to ASE fails when net password encryption reqd = 1.
How can we make a PHP DB connection to ASE with password encryption? Is there a PHP keyword or parameter that we need to set on the client side connection?
Below is a solution to this problem in term of able to connect from a Linux 64 bit base machine with PHP version 5.3.6 and Sybase driver from Sybase CTISQL Utility/15.7/P-EBF19975 ESD #3/DRV.15.7.0.3. While we got this to work, we need to have Apache to work in addition to this, I am hoping Sybase support is able to help us with that as well as they have with solution below to our question. I am posting this here for everyone benefit. Note: AFAICT, this is not a supported solution by Sybase. Please use it as your own risk.
Few things need to happen for this to work:
I've use the latest Debian Stable 6.05 squeeze 64 bit
I've install ebf19977(developer kit with open client, yes the number is off, that's not a mistake, you will see when you install it) downloaded from Sybase
Download PHP 5.3.6 from php.net website to be compile from source.
Step 1) I am assume one should easily set this up. Make sure you have sudo access
Step 2) To install the developer kit you need to type the whole path to where the setup.bin file is locate like so type in sudo /home/btran/ebf19977/setup.bin , this will start the setup, pretty much follow instructions there to to install OpenClient and its associate tools. Make sure that Open Client, and PHP library are install.
Once you done the install there are a few other steps to do:
Set all Sybase environments variables by executing the SYBASE.sh in the root directory at /opt/sybase
sudo cat /opt/sybase/SYBASE.sh >> /etc/profile , if necessary source /etc/profile
This will set most of the variables, but you need to add a couple variable that is not there:
PHPRC=/opt/sybase/OCS-15_0/config
LD_LIBRARY_PATH=/opt/sybase/OCS-15_0/php/php536_64/lib:/opt/sybase/OCS-15_0/lib
Your /ect/profile should look something like this:
# ------------------------------------
# Sybase Product Environment variables
# ------------------------------------
SYBASE="/opt/sybase"
export SYBASE
SYBASE_OCS="OCS-15_0"
export SYBASE_OCS
INCLUDE="/opt/sybase/OCS-15_0/include":$INCLUDE
export INCLUDE
LIB="/opt/sybase/OCS-15_0/lib":$LIB
export LIB
PATH="/opt/sybase/OCS-15_0/bin":$PATH
export PATH
LD_LIBRARY_PATH="/opt/sybase/OCS-15_0/php/php536_64/lib:/opt/sybase/OCS-15_0/lib:/opt/sybase/OCS-15_0/lib3p64:/opt/sybase/OCS-15_0/lib3p":$LD_LIBRARY_PATH
export LD_LIBRARY_PATH
PHPRC="/opt/sybase/OCS-15_0/config"
export PHPRC
JAVA_HOME="/opt/sybase/jre32"
export JAVA_HOME
RIBO_HOME="/opt/sybase/jutils-3_0/ribo"
export RIBO_HOME
# ------------------------------------
Then, you will also need to made modification to the interfaces file located at root directory /opt/sybase to look something like this, please do not use this, use your info:
dev
master tcp ether dev.company.com 4425
query tcp ether dev.company.com 4425
prod
master tcp ether prod.company.com 4425
query tcp ether prod.company.com 4425
ribo
master tcp ether testhost.company.com 5005
query tcp ether testhost.company.com 5005
You will also need to made modification to the ocs.cfg to get PHP to initiated correctly, this located in the folder /opt/sybase/OCS-15_0/config to look like this:
;;;;;;;;;;;
; This is the default external configuration definition file. Feel free
; to add your own customizations.
;
[DEFAULT]
; This is the default section loaded by applications that use
CS_SEC_ENCRYPTION = CS_TRUE
[ANSI_ESQL]
; This section defines configuration which an ANSI conforming
CS_CAP_RESPONSE = CS_RES_NOSTRIPBLANKS
CS_EXTRA_INF = CS_TRUE
CS_ANSI_BINDS = CS_TRUE
CS_OPT_ANSINULL = CS_TRUE
CS_OPT_ANSIPERM = CS_TRUE
CS_OPT_STR_RTRUNC = CS_TRUE
CS_OPT_ARITHABORT = CS_FALSE
CS_OPT_TRUNCIGNORE = CS_TRUE
CS_OPT_ARITHIGNORE = CS_FALSE
CS_OPT_ISOLATION = CS_OPT_LEVEL3
CS_OPT_CHAINXACTS = CS_TRUE
CS_OPT_CURCLOSEONXACT = CS_TRUE
CS_OPT_QUOTED_IDENT = CS_TRUE
; End of default sections
[isql]
CS_SEC_ENCRYPTION = CS_TRUE
[PHP]
CS_SEC_ENCRYPTION = CS_TRUE
; This is a sample section showing how you might alter configuration
; properties for you Embedded SQL application.
[SAMPLE_ESQL]
; use most of the ANSI properties defined above
include = ANSI_ESQL
; but override some default properties
CS_OPT_CHAINXACTS = CS_FALSE ; run in autocommit mode
;;;;;;;;;
Note: Very Critical to check for the existence of the php.ini file in the same directory as well /opt/sybase/OCS-15_0/config (this pointing the exention file, look at the environment variable LD_LIBRARY_PATH="/opt/sybase/OCS-15_0/php/php536_64/lib)
you php.ini should read like this:
extension=/opt/sybase/OCS-15_0/php/php536_64/lib/sybaseasephp.so
Step 3) compile PHP from source, again Sybase call for 64 bit.
I down load the source to /opt/php-5.3.6 for persistent with where most app install for Linux.
cd to /opt/php-5.3.6
./configure
VERY IMPORTANT to note, this is where we ran into a snag, if I choose any other configure option and not default ./configure, PHP will fail to load with error below:
btran#sls-baonix:/opt/php-5.3.6$ php ~/test-dev.php
PHP Warning: PHP Startup: Unable to load dynamic library
'/opt/sybase/OCS-15_0/php/php536_64/lib/sybaseasephp.so' -
/opt/sybase/OCS-15_0/php/php536_64/lib/sybaseasephp.so: undefined
symbol: executor_globals in Unknown on line 0
Fatal error: Call to undefined function sybase_connect() in
/home/btran/test-dev.php on line 10
]
Reason we need other options is we need it also to work with Apache. We got it now to work with PHP, but we need to be able to initiate PHP from website so the dependencies is that PHP beside support Sybase, it also need to support Apache. If any PHP expert out there has solution to this please jump in and help us out.

Categories