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
Related
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
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.
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.
I have been trying to get MsSQL recognised on my linux based web server which currently has Ubuntu installed on it. I have followed the steps shown on this post but i have not managed to get it to work:
Connect PHP to MSSQL via PDO ODBC
Everytime i run the following command in PHP i simply ohly get mysql as though it only picks up the mysql.so file:
foreach (PDO::getAvailableDrivers() as $driver)
{
echo $driver . '<br />';
}
Does anybody know how i can get it to output the odbc driver also? The reason i ask is because the PHP application i am trying to run has the following code in it which i am trying to get around as it's written for Microsoft Server by the looks of it:
if (extension_loaded('pdo_sqlsrv')) $this->extension = 'pdo_sqlsrv';
else if (extension_loaded('pdo_odbc')) $this->extension = 'pdo_odbc';
If i comment the above code out the pdo statement doesn't connect for the reason i mentioned above due to no odbc driver
I tried to install freetds and configure it but i couldn't get it working as odbc doesn't show in the drivers list;
Reading package lists... Done
Building dependency tree
Reading state information... Done
tdsodbc is already the newest version.
unixodbc is already the newest version.
0 to upgrade, 0 to newly install, 0 to remove and 171 not to upgrade.
anybody got any suggestions on reading from MsSQL with PHP 5.4 on linux (Ubtuntu)?
Ok so i managed to get a stage further. I got the ODBC linux driver working and now i have hit another problem: SQLSTATE[08001] SQLDriverConnect: 0 [unixODBC][FreeTDS][SQL Server]Unable to connect to data source <---does this mean that the port needs to be forwarded or that the username and password i have is incorrect? I assume this means that the driver is ok? when i try a tsql it just seems to time out after 60 seconds
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.