PHP mssql_query upgrade 2500 connections advice - php

I have 3 servers, about ten years of procedural code that was developed using the mssql_query function in php which to my understanding is deprecated beyond 5.3 and I am wondering what is the best way to update all of this code.
I have created a database wrapper class and started running all of my sql statements through it instead of calling the PHP functions now but that doesn't help me for any of the older applications that would take too long to update.
I have thought about creating a php 5.5 or above server and slowly migrating applications over to it but that sounds like an absolute mess because there is a ton of classes that all applications rely upon.
Any advice would be much appreciated.

Both extensions are fairly compatible, so it should be possible to upgrade an existing application to MySQLi without too much trouble.
It is not as easy as sed -e 's/mysql_/mysqli_/g', but there are automated tools for this.
For example, there's this one: https://github.com/philip/MySQLConverterTool which is a fork of a tool originally created by MySQL/Oracle themselves.
I assume that you have some sort of VCS, but if not, you should make a copy of the old code before applying the script, and compare the source trees afterwards with diff -ur or something similar, to make sure that all modifications are correct.

Related

migrating wordpress plugin from php 5 to 7

We've been using a Wordpress plugin called abase, to create on-the-fly forms and access MySQL tables directly. It's very easy to use for both the developer (minimal pseudo coding) and to the end-user. We'd very much like to keep using it in the long run, since it solves all our problems. But there is an issue. The developer no longer supports it and is stuck in PHP 5 code. So if I bring PHP to any version of 7, it breaks completely.
My IT headquarters require all servers to be on 7.3 or higher since there are security vulnerabilities with PHP 5.
Right now I have these options:
Try to find a way to migrate the script, although I think it'll be very difficult since the original developer is not available. I'm far from a PHP expert
Look for a replacement script, although I've done that already and haven't found a suitable script yet
Since is a server that is not pointing to the outside, maybe talk with IT and ask them to let me run PHP 5 on this server
So, what would you recommend? Are you aware of a similar plugin or maybe a script that I can use to replace it?
This is the plugin source: https://github.com/wp-plugins/abase

How to check if a PHP project works well with a new PHP Version

Is there a good way to test if a PHP project works well with a new version of PHP?
Lets say we have a project developed under PHP 5.0 and want to run it now with PHP 5.4. The project have no unit tests or something like that.
Just run it with PHP 5.4 and click around to see if there are errors is not save enough.
Run your tests. If you don't have tests, write some now under PHP 5.0. Then run them under 5.4. If they break, then you've found something that needs to be fixed. Having a suite of test scripts is good practice anyway so if you haven't got any, this is a good opportunity to start writing them. Look up phpUnit, which is the most common PHP tool for writing unit tests.
For creating a test suite on an existing project, I recommend using a tool like Selenium or Sahi which can record a browser session. Turn on the recording and start testing as normal. Voila: One repeatable test. You're going to have to do this kind of testing anyway, so you may as well record them. Granted, those are functional tests, rather than unit tests, but they are tests all the same, and if you can cover enough of your functionality with them then you'll have a fairly comprehensive demonstration that the system is working.
Syntax check: Use PHP's command-line -l option in a batch job to run a syntax check on all your files. This will prove that everything parses successfully.
That will eliminate the obvious problems.
Use a decent IDE to develop your code in. IDEs like Netbeans will highlight syntax issues and warning for you and underline the relevant code. This makes finding bugs much much easier.
If you're still developing in Notepad, you're missing out on a whole world of good stuff.
If you're using ereg() or related functions, they need to change to preg_match() etc. You can get away with still using mysql_query() for DB access, since that's only deprecated in 5.5, but if you're using it you may as well consider this to be a good time to make that change too.
Look up the Migration Guides provided by PHP. These give full details of all the code-breaking changes between PHP versions. In particular, pay attention to the deprecated features.
The most significant version for this was 5.3: A lot of old code was broken by the features which were deprected in 5.3. These were features like magic_quotes and register_globals; they had been considered bad practice for a very long time before that, but it took them until 5.3 to actually deprecate them. If you're using them, this will be the biggest problem you'll have to face.
Tools like PHPMD and PHPCodeSniffer, PHP Lint may help to analyse your code. They aren't really designed for version compatiblity checking, but may help you find issues.

Can node.js be integrated with php?

is that even a good idea for scaling heavy php apps ? for example, how does node's mysql module compare to php's mysqli extension in terms of performance etc ..
I'd seriously consider wrapping your PHP app with node.js; that is, having a migration path of your existing PHP being called by your node code, eventually migrating the PHP code into Javascript. The reason being, the execution model of node.js (non-blocking) doesn't really play well with PHP's execution model. That said, the execution models can be made more compatible with a wrapping approach; that is, having node be your exposed server, and making appropriate PHP calls (re-request); you can likely use that process to "migrate" your "wrapped" PHP over to a node server, then slowly migrate your PHP code to node.
Of course, this begs the question of whether or not you really even need / want to do this, but that's for you to determine...
There are some pretty good mysql libraries available in node.js with okay performance, but I would just rewrite(because you will still have to do a lot of coding when you use mysql libraries) the slow parts in node.js using redis or mongodb and just keep the rest in PHP. Especially redis with node_redis(hiredis) is very fast. You can use NGinx to do the proxing.
Output the result or data fetch from mysql via Nodejs is better than via LAMP.

PHP-based database models that sync with database?

Django models are really cool because you define all your models/tables right in the code, and then sync it with the database. That way when you go to update your production server, you just run the migration/sync script and you can't forget to update any tables.
The project I'm working on now though isn't Django or Python-based, it's written in PHP, and all the queries are written in straight SQL (no ORM). We've got many databases that need to be updated every time we make a change. Right now we're basically copying and pasting our SQL scripts and running them where-ever they need to be ran, or if it's a big change, we might use a script. The problem though, is that sometimes we forget to include some SQL.
If, however, we had a code-based solution, then it would automatically get checked in with our pushes, and we couldn't forget to run it. So... I'm looking for a solution that will let us define all our models in PHP, but let us continue to write straight SQL without the use of an ORM (project is 10 years old, would be too much work to implement an ORM right now). Would be nice if it could convert our existing DB into PHP models too.
Are there an existing solutions for this?
I haven't used a PHP-based system with the fantastic model support offered by Django, but this project looks promising: Django-like PHP querying interface
you can use Doctrine2 I guess. There is a support for native SQL http://www.doctrine-project.org/docs/orm/2.0/en/reference/native-sql.html
This might cost you but this is what we use for old projects.
SQLYog
http://www.databasejournal.com/features/mysql/article.php/1584401/Synchronizing-Your-MySQL-Databases-Using-a-Free-MySQL-Admin-Tool---SQLyog.htm
DBDeploy - Opensource
http://dbdeploy.com/
PHING & DBDeploy - how-to
http://www.davedevelopment.co.uk/2008/04/14/how-to-simple-database-migrations-with-phing-and-dbdeploy/

Finding exact requirements for a php application

I am developing a php application which my customers will download and install on their own servers. I know the base requirements for my application (like min. php version) but is there a way to generate a list of requirements that needed to run my application on windows or unix systems?
Thanks.
You mean, generate a list of requirements based on an analysis of your source code?
While in theory, that might be possible, I don't think such a solution exists. I think there is no way than analyzing your code by hand, with the PHP manual very close by.
Do you use GD? Then you need PHP with the GD module. Do you need to create GIF images with GD? Then you need GD, but not between versions 1.6 and (I think) 1.8. Do you use PDO? Then you need PHP > 5.1.0. And so on and so on.
In short, I'm afraid think this is going to be a manual process. Manual also as in "PHP manual" - the User Contributed Notes to each function and method are a gem, and any common cross-platform problems are usually noted there somewhere.
While you can trust that PHP x.y.z has a defined set of functions and behaviour, be sure to test well before you declare something suitable to run on a different server. IIS's support of PHP is way better now, I'm told, but the last time a ported a big PHP application over to IIS, it took me three days to work around all the mysterious bugs.
Just be aware of what you are using. For example, you should clearly communicate if you need something like .. a special database binding ( other then mysql ), xml libraries etc.., or even better, create an installer that is bundled with your software that checks that kind of stuff.
Other than that, there should be no problems concerning different servers ( apache / iis / fastcgi.. ). So to answer your question: you have to generate that list all by yourself.
As others have said, you'll need to manually keep track of special libraries and functions you're using. If you need PHP4 compatibility then you won't be able to use the built-in XML libraries for example. You can also check the list of functions added to PHP 5.
One thing I would recommend is installing WampServer if you have access to a Windows machine. Aside from being good for local development, you can download modules for most Apache/PHP/MySQL versions and test combinations.

Categories