I'm connecting to DB2 DB
$sql = 'CALL procedures.name(1,1,'text',1,1,'2017-08-30','2017-08-31',?,?)';
try {
$con = new PDO("idb:all_the_connections_stuu",'user','pass',
[
PDO::ATTR_PERSISTENT => FALSE,
PDO::ATTR_ERRMODE => PDO:ERRMODE_EXCEPTION,
PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL,
PDO::ATTR_AUTOCOMMIT => 0
]
);
$stmt = $con->prepare($sql);
$stmt->bindParam(1, $errorNumber, PDO::PARAM_INT); //also trying without PDO::params
$stmt->bindParam(2, $errorCode, PDO::PARAM_STR, 800); //and with |PDO::PARAM_INPUT_OUTPUT
$stmt->execute(); //return *TRUE*
var_dump($errorNumber); //return NULL
var_dump($errorCode); //return NULL
var_dump($stmt->fetchAll(PDO::FETCH_ASSOC)); //returns Error
$stmt->closeCursor();
$stmt = null;
} catch (PDOException $e) {
echo ($e->getMessage());
}
and got this error:
Fatal error: Uncaught PDOException: SQLSTATE[57017]: <<Unknown error>>: -332
[IBM][CLI Driver][DB2] SQL0332N
Character conversion from the source code page "" to the target code page "" is not supported.
SQLSTATE=57017
(SQLFetchScroll[-332] at /home/user/shared/PDO_IBM-1.3.4/ibm_statement.c:1306) in /var/www/html/server/testsIBM/index.php:80
Stack trace:
#0 /var/www/html/server/testsIBM/index.php(80): PDOStatement->fetchAll(7, 0)
#1 {main}
thrown in /var/www/html/server/testsIBM/index.php on line 80
If I connect with db2_connect
$con = db2_connect("DATABASE=DB2D;HOSTNAME=10.243.13.65;PORT=5000;PROTOCOL=TCPIP;USERNAME=asdf23;PASSWORD=asdfasf1","", "")
and output db2_client_info($con) and db2_server_info($con) I see that CONN_CODEPAGE from client = 819 and DB_CODEPAGE from server = 1208.
How can I set CONN_CODEPAGE in my client? I already set LANG in CentOs locale, but still got error of character conversion.
______upd:
Current $LANG = en_US.utf8 (also in locale -a I have en_US, en_US.iso88591, en_US.iso885915, en_US.utf8)
No matter what $LANG is set output from db2_client_info($con) still the same:
["APPL_CODEPAGE"]=>
int(819)
["CONN_CODEPAGE"]=>
int(819)
And same error about Character conversion from the source code page
I'm using PHP+Apache. Apache httpd.conf defaultCharset setting different locales didnt't change anything.
In php code setlocale don't changing anything either.
I think this setting store somewhere else, and ibm_db2 or pdo_ibm drivers use it. =|
____upd2
The only way I found out - change DB2CODEPAGE from installed db2 client. But I don't have installed client. I'm using inly libraries.
Now i installed v11.1.2fp2_linuxx64_client.tar.gz (1.03 GB). But i can't laucn db2 client. Think I need another new question =\
____upd3
After all manipulations with CentOs, apache locales - I still get -322 exception. No matter what I changed - db2_client_info($con) still shows me 819 CodePage. And all work nice, until fetch()/fetchAll()
CentOs 7.3, PHP 7.1.8 with PDO_IBM 1.3.4-patched, and ibm_db2. BUT I make this modules from PECL sources (cause server doesn't have internet connection).
And I also don't have any DB2 products installed on mine application server (thats why I decide that CodePage getting from CentOs locale). It seems from your test, that DB2 data server client is required?
If you are using the "IBM DB2 Data server driver for ODBC and CLI" specifically for your Centos client, you can try ensuring that the environment for the account that runs PDO and connects to DB2 has DB2CODEPAGE=1208. You can export this variable (only for this specific client type) via:
export DB2CODEPAGE=1208
and restart whatever process(es) are involved in your solution.
Also for the account(s) you are using to connect to DB2, their client LANG setting should be an UTF-8 locale (and that locale needs to be installed on your Centos). Use the command locale -a to show which locales are installed, and choose one which has an utf-8 for your territory. For example if your $LANG was en_us then change it to en_us.utf-8, if that locale is installed. Export that $LANG in the shell startup of the relevant accounts and restart your apps.
If you are using a full-DB2 client (or the local DB2-client on a DB2-server on unix) you also need to correctly set the LANG variable to a value compatible with the encoding of your DB2 database. Otherwise you will either get codepage conversion at run time, which may have unexpected results, including exceptions if no suitable conversion exists.
For information:
Tested PHP 7.0.20 with PDO_IBM 1.3.4-patched, and ibm_db2 , with DB2 V11.1.2.2 , on ubuntu 16.04 LTS - appl_codepage = conn_codepage = db_codepage.
Also tested PHP 5.3.3 with PDO_IBM 1.3.4-patched, and ibm_db2, with DB2 V10.5.0.7, on RHEL 6.9: appl_codepage = conn_codepage = db_codepage.
Also tested PHP 5.4.16 with PDO_IBM 1.3.4-patched and ibm_db2, with DB2 V11.1.2.2 data server client , on CENTOS 7.3: appl_codepage = conn_codepage = db_codepage.
Note: Ubuntu , RHEL, Centos had default locale set for utf-8, before building pdo_ibm from github, or installing ibm_db2 with pecl. All local and remote databases had utf-8 encoding.
You may find, trying the tips described here (with more explanations) very useful, notably :
Make the source and target code pages compatible with each other.
Search the DB2 information Center
using the phrase
"Code set Territory code" for compatibility of the supported DB2 code
pages. To set the client's code page compatible with the database code
page:
On Unix platforms, set the LANG, LC_CTYPE or LC_ALL environment
variable to a locale whose code page is compatible with the database
code page. Consult the platform documentation to see the valid locale
names and the code page associated with each of them.
On Windows
platforms, set the DB2CODEPAGE registry variable to override the
client's code page with a value compatible with the database code
page.
For database manager code page support, search the
DB2 information Center
using the phrase
"Code set Territory code". For federated system users, see the
Federated Systems Guide for data source code page. If the source and
target code pages are compatible, then DB2 currently does not support
this particular code page conversion. Contact your technical service
representative to determine if such support can be added.
Related
I have developed a website using PhalconPHP. the website works perfectly fine on my local computer with the following specifications:
PHP Version 7.0.22
Apache/2.4.18
PhalconPHP 3.3.1
and also on my previous Server (with DirectAdmin):
PHP Version 5.6.26
Apache 2
PhalconPHP 3.0.1
But recently I have migrated to a new VPS. with cPanel:
CENTOS 7.4 vmware [server]
cPanel v68.0.30
PHP Version 5.6.34 (multiple versions available, this one selected by myself)
PhalconPHP 3.2.2
On the new VPS my website always gives me Error 500.
in my Apache Error logs file: [cgi:error] End of script output before headers: ea-php70, referer: http://mywebsitedomain.net
What I suspect is the new database System. the new one is not mySql. it is MariaDB 10.1. I tried to downgrade to MySQL 5.6 but the WHM says there is no way I could downgrade to lower versions.
this is my config file:
[database]
adapter = Mysql
host = localhost
username = root
password = XXXXXXXXXXXX
dbname = XXXXXXXXXXXX
charset = utf8
and my Services.php:
protected function initDb()
{
$config = $this->get('config')->get('database')->toArray();
$dbClass = 'Phalcon\Db\Adapter\Pdo\\' . $config['adapter'];
unset($config['adapter']);
return new $dbClass($config);
}
And in my controllers...
for example this code throws Error 500:
$this->view->files = Patients::query()->orderBy("id ASC")->execute();
but changing id to fname fixes the problem:
$this->view->files = Patients::query()->orderBy("fname ASC")->execute();
or even the following code throws error 500:
$user = Users::findFirst(array(
"conditions" => "id = :id:",
"bind" => array("id" => $this->session->get("userID"))
));
is there a problem with the compatibility of PhalconPHP and MariaDB?
MariaDB was built to be mostly compatible with MySQL clients, it's unlikely to be the reason for your problems. If you're still concerned, you can switch from MariaDB to MySQL (and vice versa) by dumping (exporting) your tables, switching over, and importing them again.
More likely, the error line you're showing indicates that your new server is actually running PHP7 (ea-php70) and not PHP5.6 as you thought you selected.
The error End of script output before headers means the CGI script (in this case PHP7 itself) did not produce any HTTP headers before terminating. I suspect that your version of PhalconPHP is incompatible with PHP7 and therefore just crashes immediately.
If cPanel doesn't let you properly configure your infrastructure you likely have no other option but to drop it and set up your stack manually. But since you probably paid for cPanel, you could try opening a support ticket with them first: https://cpanel.com/support/
Most probably old phalconPHP version it does not support latest php 7.x version i guess. as i remember I have read similiar problem in another blog question.
We are currently switching our applications to run on a Linux box and connect to the IBMi via DB2 Connect.
So far we've installed db2 connect, have been successful in setting up the 'dummy' database on linux, creating the connection and running SQLs from Linux into the IBMi (both via the command line and from our Zend Applications) - but only when we define the libraries for files in our SQLs.
We are currently running Zend Server 7, Ibm db2 V1.9.7, and DB2 Connect 10.5 on our linux box, along with php version 5.5.
It has been noted that with the new version of Db2 connect 10.5 and ibm_db2 1.9.7 there is support for system naming on LUW. http://yips.idevcloud.com/wiki/index.php/PHP/DB2Connection see the first line.
We have not been successful however in getting the DB2_I5_NAMING_ON to work on our Linux box so that we can avoid specifying the libraries.
Here is an example of an what we are attempting to run from Zend.
$driverOptions = array('i5_libl' => 'library1 library2','i5_naming' => DB2_I5_NAMING_ON, 'i5_lib'=>'library1');
$config = array(
'adapter' => 'Db2',
'params' => array(
'username' => $user,
'password' => $password,
'dbname' => $database,
'driver_options'=> $driverOptions
)
);
$config = new Zend_Config($config);
$db = Zend_Db::factory($config);
$select = $db->select()->from("FILENAMEHERE");
$result = $select->query();
However we continue to receive this message
Message: [IBM][CLI Driver][AS] SQL0204N "USERSNAMEHERE.FILENAMEHERE" is an undefined name. SQLSTATE=42704 SQLCODE=-204
It has added the users name in for the library and will not use the specified library list (the '.' in between suggesting it is still using sql naming instead of system).
We have also included ibm_db2.i5_sys_naming=1 in our ibm_db2.ini file.
Does anyone know of any other configuration changes that would need to take place in order for system naming to work or know or any reason why we could be having such problems?
Any help would be greatly appreciated.
I'm familiar with DB2 on IBM i, but not PHP.
I would try removing the
'i5_lib'=>'library1'
That may be setting your CURRENT SCHEMA, which would activate SQL naming mode, rather than system naming.
Once connected, if you are trying to define a default library for objects to be created in, then consider using the CHGCURLIB CL command. This will put that library in front of the user portion of your library list.
CALL QCMDEXC ('CHGCURLIB somelib');
This problem was due to the fact that the IBMi machine we were connecting to was working with os 6.1. IBMi V7R1 have been enhanced to provide naming mode control. We are currently working to access a box running V7.1 which should solve our issues.
I am unable to connect Joomla to MSSQL
I keep getting
Could not connect to the database. Connector returned number: Database
sqlsrv_connect failed
Whether I use the MySQLi driver or the drivers I installed (Microsoft SQL Server)
Seems like driver installation issue ,
I am able to connect to the same box with Mssql Client fine...
Can someone post an explanation on how to install MSSQL drivers for Joomla on PHP from scratch?
Or send an up to date reference on how to do this?
Joomla 3.4
PHP 5.6
IIS 7.5
MSSQL 2008 R2
If I switch the driver to: php_sqlsrv_54_ts.dll - it will disperser from the "database type" in joomla installer..
Thank you
The joomla error that is displayed is misleading and not quite useful.
So first step would be to modify the joomla code to find out the exact error.
Modify the following code in connect() function in your application's root directory
libraries\joomla\database\driver\sqlsrv.php
From
// Attempt to connect to the server.
if (!($this->connection = # sqlsrv_connect($this->options['host'], $config)))
{
throw new RuntimeException('Database sqlsrv_connect failed');
}
To
// Attempt to connect to the server.
if (!($this->connection = # sqlsrv_connect($this->options['host'], $config)))
{
throw new RuntimeException("Database sqlsrv_connect failed - Error : ".print_r( sqlsrv_errors(), true));
}
This will give you the exact error and guide you with the next steps needed.
Another thing to consider during SQL server installation is to enable the SQL server authentication as Joomla uses SQL server authentication by default.
You can confirm that Joomla uses SQL server authentication by checking in the same function in the same file as mentioned above
$config = array(
'Database' => $this->options['database'],
'uid' => $this->options['user'],
'pwd' => $this->options['password'],
'CharacterSet' => 'UTF-8',
'ReturnDatesAsStrings' => true);
Here is the PHP manual that confirms the same.
http://php.net/manual/en/function.sqlsrv-connect.php
You can enable SQL server authentication either during installation or post installation from the manamgement studio.
Hope this helps.
Download SQLServer 2008 Express, SQLServer 2008 Standard/Enterprise
editions (R2 or later)
Download PHP Drivers
Download SQLSRV20.EXE to a temporary directory
Run SQLSRV20.EXE
When prompted, enter the path to the PHP extensions directory
If you are using some sort of LAMP stack like XAMPP
Copy php_sqlsrv_52_ts_vc6.dll to php/ext folder
Make an entry in php.ini as follows
Extension=php_sqlsrv_52_ts_vc6.dll
Note:
If you need PDO or vc9 versions - please copy the "ts" version
appropriate for your needs.
If you are using IIS with PHP engine installed via FAST-CGI - please
make the appropriate changes in c:\Program Files\php\php.ini and
copy the dll to c:\Program Files\php\ext folder
Now - You can install Joomla 2.5 by selecting the SQLServer 2008 from the dropdown list in the step 4 of the installation.
After installation is complete - continue navigation around the administrator/site
It seems nobody had this problem yet.... With db2_connect I found docs that decrible how to load a default library list (*LIBL) on connection but with PDO nothing!
I'd like to perform statements without specifing always the library name in front of file name. I already created a JOB DESCRIPTION to load the libraries, and when I log in with the PC5250 emulator those library are online.
But if I run a query with PDO without specifying the library name following is returned:
Error executing sth in testGet for AS400 SQLSTATE[42S02]:
Base table or view not found: 0
[IBM][System i Access ODBC Driver][DB2 for i5/OS]SQL0204 -
TESTFILE in WEB type *FILE not found.
(SQLPrepare[0] at ext\pdo_odbc\odbc_driver.c:206)
To use the library list, you will need to make sure your connection attributes specify system naming, and I would avoid setting a current schema.
Without much knowledge of PHP + PDO, the stackoveflow tag wiki gives a good introduction. Check that PDO is configured for proper settings for DB2 for i, not LUW or z. Likewise check db2_connect settings. (Why are you using that, instead of straight ODBC?)
I know it's been awhile since you posted but I came across some info on how to do library lists using the PDO driver... see http://yips.idevcloud.com/wiki/index.php/XMLSERVICE/PHPPDOChangeLog.
So for example you could do something like this:
$options = [
PDO::ATTR_PERSISTENT => true,
PDO::ATTR_AUTOCOMMIT => true,
PDO::I5_ATTR_DBC_SYS_NAMING => true,
PDO::I5_ATTR_DBC_LIBL => "LIB1 LIB2 LIB3",
];
$db = new PDO("ibm:SYSTEM", "user", "password", $options);
Keep in mind this will probably require a recent Zend Server (since Dec 2014). I know the latest stuff is in the new ZS 8.5 but I'm not sure about older releases.
You might also be able to leave off the library list option - in my limited testing this appears to let it use the library list from the job description. I'm not sure about the current library and YMMV but I'd be curious to hear back if it works for you or not.
Also for what it's worth an email address for the official maintainer is listed on http://pecl.php.net/package/PDO_IBM. Questions could also be sent to the WEB400 mailing list (http://lists.midrange.com/mailman/listinfo/web400), I think people who are involved in the development of the pdo_ibm driver are on there as well.
If you're talking about these docs, then that is if you're using PDO_IBM on IBM i. I don't think those settings are supported on any other platform. From your error message, it seems that you are using the IBM i Access ODBC driver through PDO_ODBC. The IBM i Access ODBC driver connects to a QZDASOINIT prestart job running in QUSRSYS subsystem. If you want those jobs to use a different job description, you need to use CHGPJE to change it: CHGPJE SBSD(QUSRSYS) PGM(QSYS/QZDASOINIT) JOBD(MYLIB/MYJOBD). If you're using SSL connections, also change QZDASSINIT jobs. You'll need to end any existing QZDASOINIT/QZDASSINIT jobs and the new pre-start jobs will pick up the new settings. Note that this will affect all ODBC, JDBC, OLEDB, .NET connections for IBM i Access drivers.
You can configure the library list through the DSN as well, by setting the DBQ connection string or DefaultLibraries ODBC.INI setting or setting the "Library List" value under the Server tab from the DSN configuration GUI on Windows.
I am developing an application that needs to get data from an outside MSSQL database. I spent a lot of time trying to get various methods of connection to MSSQL with PHP, but there were several routes which were depreciated.
On my production environment running Debian, I was able to make a connection with PDO_DLIB and FreeTDS with something like this:
$this->db = new \PDO('dblib:host='.$thedb_host_prod.';dbname='.$thedb_database_name_prod, $thedb_database_user, $thedb_database_pass);
On Windows, MSSQL is depreciated. I believe I'm using the Microsoft SQL Server Driver and was only able to get it to work with ODBC, which looks something like this:
$dsn = "Driver={SQL Server};Server=".$thedb_host_dev.";Database=".$thedb_database_name_dev;
$this->odbc = odbc_connect($dsn, $thedb_database_user, $thedb_database_pass);
Then, the problem becomes, in each method I need to do something differently for ODBC than I do for DLIB.
public function exampleMethod(){
// logic and create the query in $query
if($this->dev == false){
// PRODUCTION
try {
$stmt = $this->db->prepare($query);
$stmt->execute();
$result = $stmt->fetchAll(PDO::FETCH_OBJ);
} catch (PDOException $e) {
echo 'Connection failed: ' . $e->getMessage();
}
} else {
// DEVELOPMENT
$query = $query;
$stmt = odbc_exec($this->odbc, ($query));
$result = array();
while($currentRow = odbc_fetch_object( $stmt )){
$jobNumber = $currentRow->Code; // Set object key to jobNumber
array_push($result, $currentRow);
}
}
}
This actually works, but the problem is, with how the query for ODBC needs to be prepared vs how the DBLIB query should be prepared, means that if I don't want to write the query twice in each method, I have to create it before each action. This is really bad because it means I'm not putting my variables into the query with PDO's bindValue.
So, has anyone been able to get PDO work with PHP 5.4 and MSSQL in a Windows environment? Does anyone see a way of securing the query in a way that doesn't make me duplicate the query in each method, once for ODBC and once for DBLIB?
My plan currently is to develop the application out and then remove all of the ODBC stuff which will allow me to put the query in the $stmt properly, avoiding this problem. But until then, it's making development a huge pain.
Oooook, so I finally got it working !
Here are the libraries / drivers for Sql-server connection via C/C++/java/PHP/etc.
Precisely, here are the Windows drivers for PHP.
Check out this page to know which version you need to get
They all exist in have 32 and x64, as well as "Thread safe" (ts) and "non-thread-safe" (nts) versions.
From what I read, nts versions are to be used if you work with IIS.
Usage :
Download and extract the package you need.
in my case, package 3.2, for php 5.6
Take necessary drivers
in my case, php_sqlsrv_56_ts.dll and php_pdo_sqlsrv_56_ts.dll
Put them in your php extensions directory
in my case, [...]\php5630vc11x86x170623162800\ext
If you wonder where this dir is inside your PHP, it should be quite easy to find, since you have plenty of other dlls here.
Likely, php_pdo_mysql.dll, php_pdo_pgsql.dll, etc.
Modify your php.ini
Be careful with Wamp, it seems to have one in the php directory AND another one in the apache dir.
Add lines to load the two extensions.
You can add them at the end of your file, or with the other extensions loading.
In my case, here's what I added :
;SQL-srever extensions
extension=php_sqlsrv_56_ts.dll
extension=php_pdo_sqlsrv_56_ts.dll
This part was for the PHP/PDO side.
For the driver to actualy work, you also need your (Windows) machine to have the ODBC drivers installed.
Feel free to try your connection already, but if it whines that you need the ODBC driver, go get it here :
Microsoft® ODBC Driver 11 for SQL Server®
And last, but not least, be sure to use the right format for your PDO connection.
$conn = new PDO ("sqlsrv:Server=$srv_host;database=$srv_dbname";
For comparison, here's what I wsa using on my linux server :
$conn = new PDO ("dblib:host=$srv_host:$srv_port;dbname=$srv_dbname", "$srv_username", "$srv_password");
I thought this syntax was common to all PDO drivers, but it appears I was wrong.
Here is the PHP PDO driver documentation.
I just actually had to do some work in php connecting to a MSSQL server. I did have to downgrade to php 5.4 due to the fact that the php_pdo_sqlsrv.dll is not updated for 5.5. For the dll files check here. But now down to the code I used to connect once you have the .dll files in the right place.
try {
$db = new PDO("sqlsrv:Server={$host};Database={$database}", $userName, $password);
}catch(PDOException $e){
die("failed to connect");
}
Just a standard PDO connection. Just in order to get it to work you must make sure that the .dll files are in the php directory.
I hope that answers at least part of the question.
I have worked with PHP 5.4 and SQL Server with PDO on Windows.
I strongly recommend using Microsoft's Web Platform Installer to set everything up. You can use it to install PHP, a local version of SQL Server Express to develop on, the official PHP driver for SQL Server, and IIS, all set up to work together.
One note of caution: The last release of the SQL Server PDO driver was in April, 2012. I reported a bug against it last year and was told that it's in "limited support", which apparently translates to "you're on your own". In any case, it worked reasonably well.