We have developed a web-application that runs on various server environments (> PHP 5.3), which currently uses the "deprecated" mysql extension to connect to mysql. Since PHP 7 however, it seems mysql is not installed by default, only the newer mysqli extension.
So we would like to convert our scripts to use mysqli, but we are concerned if the mysqli extension is not installed on "older" servers. So the question basically goes: Is mysqli generally ubiquitous since PHP version 5.3? Does anyone know from what version of PHP mysqli comes installed as default?
If some of our users are on hosts without mysqli, we would need to create a wrapper script, that detects if mysqli is available, and fall back to mysql if not.
Anyone with knowledge care to shine some light on this? Thanks
MySQLi was added with PHP 5.0
You can check if mysqli is installed by doing this:
if ( function_exists('mysqli_connect') )
// mysqli is installed
Related
I'm installing a template on Php 7.0 / MySQL 5.5 that needs the Mysql extension installed.
This is on Ubuntu 14.04, MySql version 5.5, PHP Version 7.0.7-4+deb.sury.org~trusty+1
Currently, despite having installed mysql-server and mysql-client and php7.0-mysql -- this pre-requisite installation code is still returning false:
if(!extension_loaded('mysql')){$error = TRUE; echo " Mysql PHP extension missing!";}else{echo " Mysql PHP extension loaded!";}
mysqli is installed successfully, but for some reason Php is not seeing the mysql extension and therefore I cannot proceed with my installation.
The same thing is true on a phpinfo() check -- no MySQL module to be found, instead there is pdo_mysql, mysqlnd, and mysqi.. When I check the active php ini file (in fpm folder) I don't see anything obvious in there either.
What do I need to install or enable to get the Mysql extension showing up??
The mysql extension is deprecated. See http://php.net/manual/en/mysql.php
Your options are:
1) Switch to mysqli or PDO. Ideally PDO, since it supports prepared queries and is becoming the extension of choice for the PHP community.
2) If you have a lot of legacy code, then you're better off remaining with PHP 5.
Sorry, but mysql extension is not under the development. It deprecated since PHP 5.5 and was removed in PHP 7.0.
The fathers of mysql could just improve mysql to the new state but they decided to create MySQL Improved or mysqli.
The new things in mysqli that mysql didn't have:
Support for asynchronous queries.
Stored procedures
Parameterized queries
Transactions
Better security model.
Probable few more, but I cannot recall all now.
I am starting a new project in PHP that need to access MS Sql Server.
I know that PHP's manual lacks of warns about old or even deprecated set of functions.
MySQL extension do not refer to MySQLi extension at any point.
SQLite extension do not refer to SQLite3 extension at any point.
So my question is: Am I OK using PHP's SQLSRV Functions? or they are not the state of the art? I did choose them because aparently they have MS support.
Please notice that I am not asking for a recomendation, just if what I choose is OK
As I understand it the SQLSRV functions aren't actually PHP's per se since they are part of a package maintained by Microsoft outside the main PHP project. They are however one of the two best bets for working with MS SQL Server (PDO_SQLSRV being the other) since they are currently maintained.
They are both currently Windows only.
I have a old php script (very long,over a year worth of coding) running on a old pc on the lan with a old xxamp setup. The php script is so old that it contains the <?php formatting! This PC will now be replaced but the php script still needs to work. I will switch pc, update xampp to the latest version and migrate everything. I am aware that I'll have to update the old php coding but I am wondering if the whole mysql part MUST be ported to mysqli or if mysql will still exist for the next lets say 10 years. I couldnt find any information on the web.
Thanks
As stated in the comments and on the mysql_connect() page on php.net.
This extension is deprecated as of PHP 5.5.0, and will be removed in
the future. Instead, the MySQLi or PDO_MySQL extension should be used.
It's deprecated and will be removed from php in the future. There is no set date, but I can guarantee you that the use of this should stop as soon as possible. Save yourself some heartache and get cracking into PDO or MySQLi. It'll do your script the world of good!
Mysql is already deprecated. You can either use mysqli or PDO in order to handle PHP with MySql.
I'm already using PHP 5.6 on a local server, and had to rewrite parts of the class I use to connect to the DB: on 5.6, mysql extension has already been removed.
I suggest you to use PDO instead of mysqli (it's a bit more powerful, but of course, it's a personal opinion).
My company uses the sqlserv extension to connect to a MSSQL database. This extension was chosen over the mssql extension because it is actively being maintained by Microsoft and the mssql driver is no longer maintained at all. My colleague has always worked in a windows enviroment so he could just download the proper DLL file and voila, sqlserv is available. Since i am running on Mac OSX 10.8.1 i don't share this luxery.
So basically the question is: does anyone know of a sqlserv php extension in the form of a .so file?
You cannot run the SQLSRV extension on anything other than Windows as stated here:
http://php.net/manual/en/sqlsrv.installation.php
However, even if you could, I would strongly urge you to stay away from the SQLSRV extension as it is extremely buggy and underdeveloped. You would be much better off using PDO!
I spent days trying to work out which extension to use, and after much research and questions on stackoverflow, it was clear that PDO was the only realistic solution for connecting to an MSSQL database. Not to mention the additional functionality that you have!
Try and execute stored procedures, return multiple recordsets along with output parameters using the SQLSERV extension!! Just one of the many features that can be done in a few lines with PDO but cannot be done with SQLSERV.
Furthermore, PDO is faster!
I am trying to use the new development server in PHP 5.4. It runs phpinfo() just fine but on my site code and also phpMyAdmin.php they are throwing the following error:
Call to undefined function mysql_connect()
They are running through localhost:8000
php -m is showing that mysqlnd is loaded but that maybe not enough.
The OS is Windows 7
Any thoughts?
mysqlnd is the library that can be used since PHP 5.3, instead of libmysql, by 3 PHP extensions :
mysql, which provides the mysql_* functions,
mysqli, which provides the mysqli_* functons,
and pdo_mysql, which allows one to use PDO with a MySQL database.
mysqlnd by itself doesn't export any function you can use from your PHP scripts : it only provides MySQL connectivity to those 3 extensions -- which are the ones that export functions you can use.
If you want to use the mysql_* functions, you have to make sure that the mysql extension is enabled, with something that whould look like this in one of the .ini files parsed by PHP :
extension=mysql.dll
As a sidenote : the mysql_* functions should not be used anymore, especially for new projects : the mysql extension is old, and doesn't allow one to use recent (well, not that recent anymore, actually) features of MySQL.
Instead, you should be using mysqli or PDO.
It's because register_globals is no longer included as of PHP5.4, in earlier versions it was deprecated and you could force it on. The reason is because it would leave huge security gaps for hackers to exploit.
try install missing mysql module
sudo apt install php-mysqli
check if extension=mysql.so is set in php.ini after installation