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).
Related
We have a PHP based website that we will migrate to another web hosting (AWS). I noticed that mysql commands, e.g. mysql_query() are still used to execute queries. The latest PHP 5.x based version no longer supports mysql_query().
What is the PHP version that we need to configure on the new web host to be able to run mysql_query()?
The mysql extension was deprecated in php 5.5.0 and removed completely from php 7.0.0
http://php.net/manual/en/function.mysql-query.php
None that you should be using. Any development should be done in 7.2 or a above. 5.x is no longer supported and should be considered not to be secure.
http://php.net/supported-versions.php
You need to go in and replace the outdated mysql_query with modern methods. Upgrading may also break from regex conversions depending on how you did them. PHP developers had years of notice before the old mysql_query functions were deprecated. On a positive note php 7.x is a lot faster and more secure.
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.
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
First of all, I am a novice web developer.
My question is "A website developed with PHP 5.4 can run on PHP 5.3 configured server?"
(Detail Description)
I configure myself Apache 2.4, MySQL 5.6 and PHP 5.4.12 on Windows. Everything's ok. But the errors occur when I changed my website folder to another machine which is configured with WAMPserver. This WAMPserver is configured with Apache 2.2.11, PHP 5.3 and MySQL 5.1.36.
I install MySQL 5.6 on this machine and database is successfully connected. But the "Parse error occur to the code" such as
$country = mysql_fetch_row(queryMySQL("----"))[0];
In addition, it showed other errors such as "Table 'emp.productcateogry' doesn't exist".
Please, give me some suggestions.
The short answer is: no, you should not expect it to, especially if using the new features of PHP 5.4 within your code.
The specific error you are referring to with:
Parse error occur to the code
is because the line
$country = mysql_fetch_row(queryMySQL("----"))[0];
is using the new feature:
Function array dereferencing
Which, prior to PHP 5.4, had to use a temporary variable in order to access a specific index of the return, ie:
$country_temp = mysql_fetch_row(queryMySQL("----"));
$country = $country_temp[0];
Now, being that you are a novice developer, there are a few things you should note. The first and most important being that mysql_ functions are deprecated giving the note:
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.
In other words, use PDO if wanting to use prepared statements, or MySQLi if not. Another advantage of using PDO and obtaining only one column as you are in the example code is that once you are connected, you can use the function PDOStatement::fetchColumn() to obtain only one column like you are trying to do now.
Anyways, I hope this explanation helps you understand why you can't go back to PHP 5.3.x if using specific PHP 5.4 abilities - and also some understanding of how to improve your database connection and available functions that can help you get your desired result without using the "array dereferencing" that is provided with PHP 5.4. ^^
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