Compiled PHP 7 missing mysql extension in WordPress - php

I have built PHP 7 with a configuration that worked for a previous version of PHP.
Now my WordPress websites get the message:
Your PHP installation appears to be missing the MySQL extension which is required by WordPress.
Other websites using mysqli do work. What am I missing?
I've also included all .so files with mysql in the name:
extension=dba.so
extension=mysql.so
extension=mysqli.so
extension=mysqlnd_mysql.so
extension=mysqlnd_mysqli.so
extension=mysqlnd.so
extension=pdo.so
extension=pdo_mysql.so
extension=pdo_odbc.so
extension=odbc.so

PHP 7 has removed mysql_* completely.
You need to use PDO or mysqli. Wordpress seems not to support this.

mysql_* functions got deleted in PHP 7.0 update your code to mysqli or PDO
Also take a look at prepared statements if you are handling user input. To reduce the chance of SQL injections
An example of mysqli connection string:
<?php
$mysqli = new mysqli("localhost", "user", "password", "database");
if ($mysqli->connect_errno) {
echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
}
?>
An example of pdo connection string:
<?php
$dbh = new PDO('mysql:host=localhost;dbname=test', $user, $pass);
?>
Note:
That mysqli example handles a connection error

As has been mentioned elsewhere, the ext/mysql functions have been removed. We've been talking about this for some time.
ext/mysql was built for MySQL 3.23 and only got very few additions since then while mostly keeping compatibility with this old version which makes the code a bit harder to maintain.
If you're hell-bent on putting them back in, you can add them back to PHP 7 by using the ext/mysql PECL Library
It's important to note that Wordpress 3.9 or later supports mysqli
In WordPress 3.9, we added an extra layer to WPDB, causing it to switch to using the mysqli PHP library, when using PHP 5.5 or higher.

Check if the Wordpress still using the Mysql extension that was removed in PHP7.
http://php.net/manual/en/migration70.removed-exts-sapis.php
The Mysqli and PDO extensions were kept. This is the reason your other websites are working.

This issue is caused by php 7.1.0-dev.
I built another one with the same configuration version 7.0.0 and the issue was resolved.
This has nothing to do with WordPress since it will automatically try to use MySQLi when MySQL is not found. At least in WP 4.4.

On Ubuntu, I fixed this error by running
sudo apt-get install php-mysql
And then restarting my server (caddy, but you might be using apache or nginx).
source

Related

opencart Error Found in my website

I have already transformed my Website from one server to another. Everything is working fine. When I try to open my side I found this error message
Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /home/haratistore/public_html/system/database/mysql.php on line 6
My Domain is http://haratistore.com/
Please advise me ...haw can I fix this type of a error
UPDATE
Open opencart/config.php and opencart/admin/config.php.
Change mysql to mysqli
e.g.
//define('DB_DRIVER', 'mysql');
define('DB_DRIVER', 'mysqli');
I think your Opencart version is older 1.5.X so there is two options here:
1) you should upgrade your OpenCart to 2.x.x
2) I have developed for older version OpenCart PDO class which you have to upload in your opencart > system > database
Opencart-PDO

Laravel: Connecting to sqlite database throws "PDOException: Could not find driver"

I am deploying a Laravel project to a shared hosting and added a php.ini with:
extension=pdo.so
extension=pdo_sqlite.so
extension=sqlite.so
In phpinfo, I could also see that the sqlite extensions are loaded. Testing to connect to the database with the following code snippets also worked:
<?php
try {
$dbh = new PDO("sqlite:app/database/production.sqlite");
echo "Connected to database!";
}
catch(PDOException $e)
{
echo $e->getMessage();
}
However, when trying to connect to the databse using Laravel, the application throws me the PDOException error.
Appreciate any help on this. Thanks in advance!
The exception you get:
PDOException: Could not find driver
is given by PHP's PDO whenever the driver to your database could not be found. PDO needs a driver to operate with different databases (e.g. Sqlite, Mysql, ...). And PDO looks for the driver based on the DSN. In your case the DSN is:
sqlite:app/database/production.sqlite
And for the driver is looked only in the part before the first colon (":"):
sqlite
The string sqlite is used to find the sqlite3 driver (see PDO_SQLITE DSN in the PHP manual).
There is only a single place in all PDO where this exception is thrown (php 5.4 lxr) and it only gets thrown in case for the text before the colon in the DSN no driver could be found. This is also what you can expect from the error message.
As you've already done the checks outlined in the best answer to "How to determine if PDO is enabled in PHP" you are already certain that the PDO sqlite extension has been loaded.
Just to make this clear: The PHP extension which contains the PDO driver for sqlite is named pdo_sqlite which you have checked to be loaded.
The only explanation I have is that you did load the extension but PHP was not able to load the driver. According to PHP sources (php 5.4 lxr) this can have exactly two reasons:
The PDO driver requires a different PDO API version
PDO must be loaded before loading any PDO drivers
(technically there is a third reason but it should be ignored: adding the driver to the hashtable of PDO drivers failed, this is pretty internal and has nothing to do specifically with PDO)
As the extension is loaded, but the driver is not found, I suspect there was a problem registering the PDO driver. You should checkout the PHP error log for startup errors. As you say you have this problem on a shared hoster you need to contact the support where you find the PHP error log. You're looking for startup errors. Sometimes these error are also shown in the error log of the webserver depending on which PHP SAPI interface is used.
Please also provide the information from phpinfo() so that additional guidance can be given. With the information you've provided you can rest assured that the sqlite driver for PDO has not been loaded. This is a configuration issue.

How to connect to Sybase via PHP

I'm trying to connect to a Sybase database with PHP5. I believe I've successfully compiled PHP with PDO_DBLIB, as phpinfo() lists dblib under PDO drivers, and freetds as the pdo_dblib flavour.
However, when I try to test a connection, I get an error reading:
'PDOException' with message 'could not find driver'
I'm trying to connect to a server on my LAN with this code:
$dbh = new PDO("sybase:host=192.168.1.xxx;dbname=[database-name]", '[user]', '[pass]');
Any suggestions would be greatly appreciated!
You should use dblib instead of sybase, like this:
$dbh = new PDO("dblib:host=192.168.1.xxx;dbname=[database-name]", '[user]', '[pass]');
PDO wouldn't work, or at least there is no PDO Sybase support for php. On Windows, you can use ODBC, and PDO_SQLSRV or PDO_ODBC, it might sound weird, but it should work.
Second option and I would recommend it, is to connect directly to Sybase (SqlAnywhere), but you need to install SQL Anywhere PHP Module
If you are using Ubuntu you can put the LD_LIBRARY_PATH inside envvars and it seems to read... still trying to find a way to get it to stick on RHEL based systems... Windows I am not too sure about I would hope you could set a system wide variable under
my computer -> properties -> advanced options
If are using RHEL based systems it might be better to include the:
export LD_LIBRARY_PATH=/path/to/library/ in the httpd restart script (check to see if it loads /etc/sysconfig/httpd and if so add the line in there - now restart apache and you should see some activity.

mysql_connect error

In the following code I see echo1 statement, after which I do not see anything printed on the UI.The username and password is correct. But PHP doesn't seem to connect to MySQL. Don't even see the die statement what am I doing wrong. After mysql_connect is encountered the rest of the code doesn't work:
<?php
echo "echo1==========";
$con = mysql_connect("localhost","root", "xxxx123") or die("Error connecting to database");
echo "+++++++++ echo2";
echo $con;
mysql_close($con);
?>
You should be mising an error. Add :
ini_set('display_errors', 1);
error_reporting(E_ALL);
at the beggining of your script
No output means a fatal error. The only possible fatal error is "undefined function mysql_connect (unless something's really messed up somewhere). This means the mysql library is not installed, or it might just not be enabled in the php.ini file.
Check said file, and while you're at it turn error_reporting on.
If you use your code just like this then it's vulnerable for SQL Injection. I would strongly recommend using mysql_real_escape_string as you insert data into your database to prevent SQL injections, as a quick solution or better use PDO or MySQLi.
If you are going to use mysql_* then I'd recommend reading the PHP manual chapter on the mysql_* functions,
where they point out, that this extension is not recommended for writing new code. Instead, they say, you should use either the MySQLi or PDO_MySQL extension.
I also checked mysql_connect and found a weird regularity which is - if you use " on mysql_connect arguments, then it fails to connect and in my case, when I was testing it, it happened just described way, so, please try this instead:
$con = mysql_connect('localhost','username','password');
Replace " to ' as it's shown in the PHP Manual examples and it might work!
EDITED
For those who downvote - TRY first! I tested it on my server with " and it gave me an error: Warning: mysql_connect(): Access denied for user. I use PHP version 5.4.6!
Login to your server with SSH and run php --modules - if you don't see mysql in the list - then it's the reason of your fatal error.
The issue was that the ph5-mysql driver was not installed .Installed it and got it working..Now mysql_connect() function works..Thanks for all the help
For Tomcat 7, the default dir for php.ini is actually C:\windows. So modified (enabling modules, extensions etc.) php.ini should be copied to C:\windows. Then run phpinfo();. It should work fine even on Tomcat 7 along side PHP 5.x. I had this problem and struggled a lot when I wanted the mysql statements to work.
Even after following all instructions from answers in [779246] (Run a php app using tomcat?), mysql statements didn't work (Tomcat 7, PHP 5.2.16, PECL 5.2.5, MySql 5.6 on Windows 7). So I started looking into "phpinfo();" output carefully and used solution as mentioned in earlier paragraph. Please be sure to enable mysql dll extension and also PDO extensions in php.ini if you would like to use PDO (which is future of plain mysql_* methods in PHP).

Call to undefined function sqlite_escape_string()

i am using sqlite_escape_string($str) to prepare sql statements for future use.
however, when i migrated my code to a new server, it says:
Call to undefined function sqlite_escape_string()
seems the Sqlite and everything is working in the new server, but i have error even for a sqlite_open().
Anyways, i just need to escape my $str to a sqlite safe sql statments, i dun even need to write to sqlite from PHP, so an
That sounds like the SQLite plugin is not enabled for PHP. Write <?=phpinfo()?> in a .php file, load it up on your server and see if SQLite is mentioned in the loaded plugins.
You need to uncomment the extension=php_sqlite.dll line by removing the semi colon right now your pdo_sqlite is enabled and sqlite_escape_string is a function of sqlite extension and sqlite_pdo will not work untill php_sqlite is enabled
I found the ans myself.
It is due to my server is a Centos 5.4, and sqlite support for php is not there.
The same case should exist in REL5 also.
see the 1st and 2nd latest comment in the link below:
http://www.php.net/manual/en/sqlite.installation.php
I solved it by recompiling my php and added the sqlite.ini file
For those who recently upgraded to 5.4+, note that the php docs say, this method is not available 5.4+
(PHP 5 < 5.4.0, PECL sqlite >= 1.0.0)
So you would either need to manually compile it in, or look at PECL.

Categories