Getting Data from Vertica with PHP with wrong Encoding - php

I'm trying to get data from Vertica DB using php odbc_connect, I have a problem with Russsian text, so for example instead of getting this text Уютная I got an \x1A\x1A\x1A\x1A\x1A\x1A
This is my DNS connection string:
$dsn = "Driver=Vertica;Server={$host};Port={$port};Database={$database};";
$this->connection = odbc_connect($dsn, $username, $password);
And this my /etc/vertica.ini file (app runs in debian Jessie):
[Driver]
DriverManagerEncoding=UTF-16
ODBCInstLib = /usr/lib/x86_64-linux-gnu/libodbcinst.so.1
ErrorMessagesPath=/opt/vertica
LogLevel=4
LogPath=/tmp
I'm using Vertica ODBC driver 7.2.2-0
Any idea how I can fix it?
Thank you !

Temporary solution I found is to wrap the field with URI_PERCENT_ENCODE function (vertica sql function) and in php you do a urldecode.
stackoverflow

Related

How to fix fatal error in PHP?

I found a system that can generate a report I would like to study this system but when I try to generate the system the login was OK but when I put the password and username this error comes out:
Fatal error: Call to undefined function mysql_select_db() in
C:\xampp\htdocs\inventory\inventory\db.php on line 8
Can anyone else tell me what is the problem in this system?
image
I'm currently using XAMPP V3.2.2
If you are using PHP 7 within your XAMPP then it wont work because that code is too old. mysql_select_db was removed in PHP 7.
http://php.net/manual/en/function.mysql-select-db.php
You will need to install PHP 5 to use that software.
Edit: Pratik Solanki is correct also. The database is being connected using mysqli so depending on the other code in the system you can either change the database connect statement to mysql_connect and use PHP 5 (old mysql connector not recommended) or change all the database statements to use mysqli instead in which case no PHP changes are needed (recommended)
You forgot to include the database while connecting using mysqli_connect function.
In your code, you declared a $mysql_database but you didn't use that.
Code:
<php
$mysql_hostname = "localhost";
$mysql_user = "root";
$mysql_password = "";
$mysql_database = "liveedit";
$bd = mysqli_connect ($mysql_hostname, $mysql_user, $mysql_password, $mysql_database) or die ("Opps something went wrong ");
?>
You connected to database via mysqli module of php and you are trying to select your database via mysql module of php.
Correct way to use it would be like this :
mysqli_connect(dbhostname,dbusername,dbpassword,dbname)
mysqli can be used with the mysql native drivers and mysql can be used via the default libraries provided.
Both are different and the only small mistake you made was making connection with mysqli and selecting db with mysql.
Solution to this is making the whole connection along with selection of db via mysqli function

Connecting to Peachtree database using php?

Iam developing an application in php which can fetch transaction,invoices.etc from peachtree database. So for database access I selected ODBC method by connecting using Pervasive SQL.
I used connection string like this:-
$connection = odbc_connect("DRIVER={Pervasive ODBC Engine Interface};Dbq=C:\Sagepro\Peachtree\Company\Sample\PAW\BCS","Peachtree","password");
But it is giving error
( ! ) Warning: odbc_connect() [function.odbc-connect]: SQL error: [Pervasive][ODBC Client Interface][LNA][Pervasive][ODBC Engine Interface][Data Record Manager]Cannot locate the named database you specified(Btrieve Error 2301), SQL state S1000 in SQLConnect in C:\wamp\www\peachtreeapi\index.php on line 2
How to rectify this??
Use this connection string.. it will work
$connect=odbc_connect("Driver={Pervasive ODBC Engine Interface};ServerName=localhost;ServerDSN=DSNname;","Username","Password",SQL_CUR_USE_ODBC);
I think this connection string will work:-
$dbhandle = odbc_connect("DSN=YOURDSN;DRIVER={Pervasive ODBC Engine Interface};DATAPATH=c:\peachw\YOURCOMPANY;DDFPATH=c:\peachw\YOURCOMPANY","username","password");
username & password is the details you provided in peachtree -> maintain->users->setupsecurity->data access/crystalreport ->All option in your peachtree app.
You'll need to create a Pervasive Database Name pointing to your data location. You can't specify a path in the connection string. Pervasive removed that functionality. Once you create the Database Name through the Pervasive Control Center, you would specify that name in your connection string:
$connection = odbc_connect("DRIVER={Pervasive ODBC Engine Interface};Dbq=XXXXXXXX","Peachtree","password");
where "XXXXXXXX" is the name of the database you created in the PErvasive Control Center.

Why is PDO working without dbname?

I am connecting to my database using this command:
$resource = new PDO('odbc:driver=FreeTDS;Server=127.0.0.1;Port=8090;UID=Reporting;PWD=readonly;');
There is no dbname specified, and yet, it still connects to a database. The problem is, it is connecting to the wrong database. I tried including a section dbname=DATABASENAME;, but this was entirely ignored. How do I tell PDO to connect to a different database?
Use DATABASE instead of DBNAME, i think this is the problem:
$resource = new PDO('odbc:driver=FreeTDS;Server=127.0.0.1;Port=8090;DATABASE=DATABASENAME;UID=Reporting;PWD=readonly;');
did you try to do the Standard operation? like....
new PDO("odbc:Driver={SQL Server};Server=127.0.0.1;Database=test;",'sa','password');
and which database you are using? ms sql server or some else?

correct mssql connection string in php

Perhaps this is the connection string to connect to an sql server
<?php
$myServer = "localhost";
$myUser = "your_name";
$myPass = "your_password";
$myDB = "examples";
?>
//connection to the database
$dbhandle = mssql_connect($myServer, $myUser, $myPass)
or die("Couldn't connect to SQL Server on $myServer");
but i do not know what to input in the $myServer, $myUser and $myPass
if I wanna use windows authentication
This is my Server details kindly help me please
Microsoft SQL Enterprise Manager
Microsoft Corporation
Version: 8.0
If you have PHP 5.3 or later, you can no longer use the ms_sql extension, according to the PHP documentation page. I'm not sure of the extent of that, but you may want to consider using PDO instead. It allows for a generic way to access various database types, including MSSQL. To connect to a MSSQL database using PDO, you first need SQLSRV, the driver, which you can download from Microsoft here. To connect, you would use the following:
$handle = new PDO("sqlsrv:Server=$server;Database=$database", $username, $password);
Above, and to answer the main part of your question, $server is probably localhost, and your username and password can be accessed and changed from within the Microsoft SQL Server access panel. I believe you can use "sa" for $username and "" for $password. For $database, just put in the name of the database you want to connect to.
To query:
$queryRef = $handle->query($query);
To read results, declaring $results as a two-dimensional associative array, the first being the result number, the second being the column name:
$results = $queryRef->fetchAll(PDO::FETCH_ASSOC);
So $results[3]['id'] would be the value of the column 'id' of the third result.
You can find more examples on the PHP documentation page for PDO here. Much of this was taken from my previous answer here.
Your server is usually localhost, and your username and password could be changed and viewed by following this tutorial:
http://blog.sqlauthority.com/2007/12/29/sql-server-change-password-of-sa-login-using-management-studio/

sqlite correct path/URI for php pdo on windows

[ante-scriptum : this is a self answered question, you don't need to bother answering]
I ran into a weird configuration problem, not documented anywhere on the specific PHP.net page or at StackOverflow.
The problem
When opening an existing sqlite database on Windows, the same error kept showing :
SQLSTATE[HY000] [14] Unable To Open Database File
Although the code executed was copy/pasted from the manual :
<?php
/* Connect to an ODBC database using driver invocation */
$dsn = 'sqlite:/full/path/to/db';
$user = 'dbuser';
$password = 'dbpass';
try {
$dbh = new PDO($dsn, $user, $password);
} catch (PDOException $e) {
echo 'Connection failed: ' . $e->getMessage();
}
?>
I could not open this database, as I had tried all kinds of various DSN while googling :
$dsn = 'sqlite:/c:\\full\\path\\to\\db'; // --FAILED--
$dsn = 'sqlite://c:/full/path/to/db'; // --FAILED--
The solution
Notice the simple slash in the DSN sqlite:/ ? Just drop it !
write your DSN like this :
sqlite:name.db.
This works with relative and absolute paths so :
$dsn = 'sqlite:c:\full\path\to\name.db'; // --WORKS--
$dsn = 'sqlite:..\data\name.db'; // --WORKS--
$dsn = 'sqlite:name.db'; // --WORKS--
Hope it will save you some time in the future !
Just a small append to #justin answer:
You can also use the linux path style on windows:
$dsn = 'sqlite:c:/full/path/to/name.db';
Better than PDO('sqlite:...') is to use PHP sqlite3 extension and its SQLite3 class. I have tried your advices above with a database on an external (hard)drive and it didn't work (still giving the same error as mentioned in the first post by #justin-t). Then I tried with SQLite3 class and... Hurray! It worked!
(Just for those who are wondering about PDO and a lot of its weird bugs.)
Check if your PHP installation has enabled extensions for sqlite and/or sqlite3.
I've been struggling with a similar problem only to find that it rejected my DSN because sqlite was disabled.

Categories