PhalconPHP Database transactions fail on server - php

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.

Related

Connecting Laravel with SQL Server database always shows error "could not find driver"

I want to connect Laravel (version 8), with a SQL Server database (SQL Server 2008 R2).
I've done the installation and followed some tutorials with steps like the following, where the version I installed adapts to SQL Server 2008 R2, like this guide :
Installed Microsoft® ODBC Driver 17 for SQL Server (I chose version 17 because of this)
Installed PHP Driver version 5.6 by taking 2 files, namely php_pdo_sqlsrv_73_ts.dll and php_sqlsrv_73_ts.dll which I got from here (I chose version 5.6 based on this)
I put the above 2 files in C:\larragon\bin\php\php-7.3.9-Win32-VC15-x64\ext
I enabled the extension in php.ini, like this: extension=pdo_sqlsrv_73_ts,
extension=sqlsrv_73_ts. It succeed, When I checked in php.info, it says pdo_sqlsrv
Then I configured the database connection on Laravel's .env like this (I've created a database with that name):
DB_CONNECTION=sqlsrv
DB_HOST=192.168.101.103:86
DB_PORT=1433
DB_DATABASE=testlaravel
DB_USERNAME=faisallocal
DB_PASSWORD=faisallocal
Then I run php artisan migrate on terminal.
But I always get an error like this:
[Illuminate\Database\QueryException
could not find driver (SQL: select * from sys.sysobjects where id =
object_id(migrations) and xtype in ('U', 'V'))
at
C:\larragon\www\redeempointappapi\vendor\laravel\framework\src\Illuminate\Database\Connection.php:712
708▕ // If an exception occurs when trying to run a query, we'll format the error
709▕ // message to include the bindings with SQL, which will make this exception a
710▕ // lot more helpful to the developer instead of just the database's errors.
711▕ catch (Exception $e) { 712▕ throw new QueryException(
713▕ $query, $this->prepareBindings($bindings), $e 714▕ );
715▕ }
716▕ }
1
C:\larragon\www\redeempointappapi\vendor\laravel\framework\src\Illuminate\Database\Connectors\Connector.php:70
PDOException::("could not find driver")
2
C:\larragon\www\redeempointappapi\vendor\laravel\framework\src\Illuminate\Database\Connectors\Connector.php:70
PDO::__construct("dblib:host=192.168.101.103:86:1433;dbname=testlaravel;charset=utf8",
"faisallocal", "faisallocal", [])]
What did I miss?
I did this test locally, and I have XAMPP as well as Laragon with different versions, but wouldn't it be okay if I had a different port?
Please help anyone who has experience and has advice on this, I've been stuck at this point for weeks..
Thank you
php_pdo_sqlsrv_73_ts.dll It depends of your version of php
for example: php_pdo_sqlsrv_73_ts.dll is for php 7.3
in the next link you can see this information.
https://learn.microsoft.com/en-us/sql/connect/php/system-requirements-for-the-php-sql-driver?view=sql-server-ver15
So this all happened because of the detected different versions of PHP and SQL Server drivers.
For information, I have 3 local servers, namely:
XAMPP 1.7.3,
3,, (I forgot the version details),
and Laragon.
The problem that occurs is, when I want to develop apps using the Laragon server AND I use the local Terminal/Command Prompt (Shortcut: Windows + CMD), the PHP versions from other local servers will collide with each other.
When I run a Laravel command, check the PHP version, or whatever, the local Command Prompt directs me to the version of XAMPP above that I have installed, so any .dll or plugins you install in Laragon won't be detected!
Finally I was able to finish my installation and do a lot of CMD commands according to the version I want, is how to use the built-in CMD/Terminal from Laragon (Click on Terminal under Laragon application)
From this Terminal, all the .dll plugins that you install, and all the cmd commands that you enter, will match the Laragon version you are using, they won't be strayed to another local server! :D

Quickest way to get Expression Engine v 2.5.5 working with PHP7

A client’s host has recently updated their server to run PHP 7, which has broken their EE 2.5.5. site (“Call to undefined function mysql_connect()”).
I tried upgrading EE to version 2.11.9 but get errors:
Frontend: can’t find safecracker_lib
Control Panel: PATH_MOD not defined in mod_structure.php, fixing this leads down a rabbit hole starting with an error related to not being able to instantiate the pagination class somewhere.
I just need to get the site running until I build a new site, what is the quickest way I can get the site running with PHP 7?
In your config folder there is a file named database.php
change the line:
$db['expressionengine']['dbdriver'] = 'mysql';
to
$db['expressionengine']['dbdriver'] = 'mysqli';
mysql_connect() has been deprecated since PHP 5 and removed in PHP 7 so you cannot use this function or any of the old mysql functions.
You need to upgrade your codebase, or downgrade your PHP version (highly discouraged).
In regards to your missing pagination class, you may not have implemented core classes that were required when upgrading.
Try running on your command line:
php system/ee/eecms upgrade
You can also read the documentation on how to upgrade the codebase for Expression Engine here.

php pdo connected to DB2 different CODEPAGE

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.

Call to undefined method mysqli_stmt::get_result() AND mysqlnd installed

As the title suggests, I have mysqlnd available on my shared hosting server running PHP version 5.4. When I attempt to call the mysqli get_result() function, I get this error.
I have spoken several times with the hosting provider, and most recently they told me to try running
# /opt/ntphp/php54/bin/php -i | grep -i mysqlnd
I hopped on ssh and ran this command which gave this:
mysqlnd
mysqlnd => enabled
Version => mysqlnd 5.0.10 - 20111026 - $Id: c85105d7c6f7d70d609bb4c000257868a40840ab $
Loaded plugins => mysqlnd,example,debug_trace,auth_plugin_mysql_native_password,auth_plugin_mysql_clear_password
mysqlnd statistics =>
Client API version => mysqlnd 5.0.10 - 20111026 - $Id: c85105d7c6f7d70d609bb4c000257868a40840ab $
So, that appears to me as I would expect.
I found another piece of PHP code on another forum post that suggests running:
$hasMySQL = false; $hasMySQLi = false; $withMySQLnd = false; $sentence = '';
if (function_exists('mysql_connect')) {
$hasMySQL = true;
$sentence.= "(Deprecated) MySQL <b>is installed</b> "; } else
$sentence.= "(Deprecated) MySQL <b>is not</b> installed ";
if (function_exists('mysqli_connect')) {
$hasMySQLi = true;
$sentence.= "and the new (improved) MySQL <b>is installed</b>. "; } else
$sentence.= "and the new (improved) MySQL <b>is not installed</b>. ";
if (function_exists('mysqli_get_client_stats')) {
$withMySQLnd = true;
$sentence.= "This server is using MySQLnd as the driver."; } else
$sentence.= "This server is using libmysqlclient as the driver.";
echo $sentence;
I did this and got the result:
(Deprecated) MySQL is installed and the new (improved) MySQL is installed. This server is using libmysqlclient as the driver.
I'm running my hosting with Arvixe, and they had a blog post that basically said "Run PHP 5.4 and this will work". It's clear to me that they think this function should run, but it's giving me a fatal error instead.
Side note - the code runs perfectly on my local machine, and I only get an error with the call to get_result().
EDITED:
Here is how the PHP is set up:
$stmt = $con->prepare("SELECT * FROM User_Details WHERE LCASE(username) = LCASE(?) LIMIT 1");
$stmt->bind_param("s", $username);
$stmt->execute();
$result = $stmt->get_result(); // This line throws the ugly error
For anybody wondering what's going on with this, and using Arvixe. Here is the response I received from the staff.
This is some confusion around MySQLND which was caused by an old
platform and its something I'll be communicating to my staff.
We used to run a system which allowed us to have individual PHP
installs and at that point 5.4 and 5.5 both had MysqlND running. The
new PHP system we have in place runs all PHP installs on a consistent
config and therefore with our PHP 5.3 install (the base install) not
using MySQLND nor does our 5.4 or 5.5 install.
This will be reviewed in future as PHP 5.6 is going to have MySQLND as
a default.
Currently the only way we can support MySQLND is via a VPS / dedicated
server.
So, if you're on Arvixe and not a VPS, you're out of luck for using a super common and recommended convention for retrieving data from your database. There are workarounds for this using a ton of different methods. They either aren't feasible for my project or I couldn't get them to work, but for smaller queries it seems that using $stmt->bind_result() is one of the more popular methods.
http://php.net/manual/en/mysqli-stmt.bind-result.php
For me, I'm taking my business back to GoDaddy. I spent over 10 hours trying to get a solution for this with no resolution offered except "We have a 60 day money back guarantee if you're not satisfied."
Thanks everyone for helping out with this. Frustrating as it's been, I learned a lot in the process and from these boards... As is usually the case.
When you ran the code that inspected the PHP environment was that through the webserver? I ask this because it sounds like you haven't configured your webserver to use PHP 5.4 (which allegedly has the version of mysqli you're after).
You might want to refer to this article from Arvixe.
Interestingly, it seems the function that's causing trouble is available since PHP 5.3.
You might also try a simple script to view the environment from the web
<?php
phpinfo();
Hit that from the web and check for a couple things
PHP version 5.4
mysqlnd
Personally, I'm not sure mysqlnd is required to provide the get_results function (but would need to dig deeper to determine that).
Another test you can do to see if in fact Arvixe's PHP 5.4 environment provides the function of interest is test the CLI environment which you know has mysqlnd
/opt/ntphp/php54/bin/php -r 'echo method_exists("mysqli_stmt", "get_result") . PHP_EOL;'
If that spits out a 1, you almost certainly just need to follow that guide I linked to earlier to get your webserver environment running PHP 5.4.
Remove the existing php version and install the new version of php 5.5 or later
and verify by doing on root terminal $ php -v

Could not connect to the database. Connector returned number: Database sqlsrv_connect failed

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

Categories