Consider using PDO instead [duplicate] - mysqli

I have designed a website before 5 years using PHP MySQL and still works fine without any issues. I heard MySQL is officially deprecated as of PHP 5.5 and has been removed as of PHP 7. Also, PHP offers three different APIs to connect to MySQL (like MySQL, MySQLi, and PDO). My web server is updated frequently.
I understood, I have to move to newer API like MySQLi or PDO for safety. Now I am confused whether to choose MySQLi or PDO. Also, Is there any compatibility/migrating options available for such case?

Lets take a look at both of these extensions.
PDO
PDO is database neutral - You only need to learn one API to work with dozens of databases
So if you decide to move to another database, the only thing you would be changing is the DSN(data source name).
Support of both name and '?' placeholders for prepared statements.
Drupal uses PDO.
Mysqli
On the other hand Mysqli is designed specifically for Mysql databases and is recommended by Mysql. Mysqli works with Mysql and MariaDB databases.
Support of only '?' placeholders for prepared statements.
Joomla uses Mysqli
Conclusion
There are many conflicting arguments weather Mysqli or PDO runs faster. Both Mysqli and PDO use the same underlying drivers to access the database making the performance not worth comparing.
So there is no clear winner when working with Mysqli or PDO. But let's say you use Mysqli and then later you want to use another database, it would be a difficult transition.
The main strength of PDO over Mysqli is name placeholders for prepared statements and which is why I chose PDO over Mysqli.

The answer is fairly simple.
If, like majority of PHP users, you are going to use database API functions right in the application code, without any intermediate wrapper, then PDO is your only choice, as it's a sort of wrapper already, automating many operations that with mysqli have to be done manually.
No, there are no migration options, because the very approach is changed dramatically: instead of placing variables right in the query, they have to be substituted in the query with special marks. There is no way to automate this process.

PDO and MySQli both are used for database connection and both have their own advantage. In closer look PDO wins the battle but if you really stick with only one database provider then my personal best choice is use MySQLi.
You will also extract some good points from: http://code.tutsplus.com/tutorials/pdo-vs-mysqli-which-should-you-use--net-24059

Related

Why do I need models.py for a Flask app?

As a webapp novice, I'm not sure if I need to define models.py.
I already have a working Postgres database on Heroku that I've linked up with Postico and pgAdmin. Using these GUIs, it seems I can get and post data, and make structure changes very simply.
Most tutorials seem to glaze over the details and reasoning for having a models.py. Thanks!
Web frameworks typically enforce or encourage a Model-View-Controller (MVC) patterns that structures code such that the database code is kept separate to the presentation layer.
Frameworks like django come with and are more integrated with ORM functionality which is used to implement an MVC framework. The ORM allows you to programatically interact with your database without having to write sql code. It can let you create a schema as well as interact with it by mapping programming classes to tables and objects to rows.
Flask can be distinguished from many other web frameworks, like django, in that it is considered a micro framework. It is light weight and can be extended by adding extensions. If you need the database integration then you can use it with an external ORM tool like sqlalchemy (and optionally flask-sqlalchemy extension). You can then define a sqlalchemy model, for instance, in a file called model.py or schema.py, or any other name you find appropriate.
If you only need to run one or two queries against an existing postgres database and feel you have no need for the use of an ORM, you can simply use flask with the postgres driver and write the sql yourself. It is not mandatory to have a model.
A model/ORM can be beneficial. For example if you want to recreate an integration/test instance of the database, you can instruct the ORM tool to create a new instance of the database on another host by deploying the model. A model also provides a programming abstraction to the database, which in theory should make your code more database independent (well in theory, its hard to achieve this as databases can have subtle differences), and should make your code less tied to a specific database solution. Also, it alleviates the need of writing a language within a language (sql text strings within python code).

TideSDK - postgreSQL?

is there a way to connect to a postgreSQL Database? I've noticed that the PHP module doesn't have the postgres extensions and its not possible to load it dynamically.
Is there any other way? An external PHP scripts will be the worst solution.
Alex
I don't have direct experience with Tide, but reviewing their docs here are the places I would look:
Javascript-> PostgreSQL Is there a possibility of connecting postgreSQL directly to Javascript?
Python -> PostgreSQL, like psychopg.
If that fails, along with other similar languages, MAY be able to find another driver written fully in a language like this.
The PostgreSQL protocol is extensively documented and several implementations exist for it. You could probably adapt either the Javascript driver or implement in another language to give you a direct driver to PostgreSQL http://www.postgresql.org/docs/9.1/static/protocol-flow.html

Postgresql Manager

I have been working with Microsoft SQL Server since 6.5 along with other database like Oracle, MySQL and SQLite. I equally appreciate or hate all these DBMS for some point or the other.
On our forthcoming project, we are considering Postgres in the back-end. I have already started playing with it, pretty interesting for me.
I have always heard good comments on Postgres database, but I don't like the admin studio at all. While creating new a table, I hate the way of creating columns on pgAdmin by having to click add button again and again.
Are there any "Studios" for Postgres database that provide
more organized table creation process (spreadsheet like)
graphical view designer
What's wrong with plain SQL? Writing plain SQL goes much faster than click-wait-click-wait-type-click-wait-ok-wait. You could use any tool for this, pgAdmin as well.
Open Office Base can also connect with PostgreSQL, works like MS Access. And talking about MS Access, MS Access can also connect to PostgreSQL to create tables, views, etc.
See this official list of Administration/Development tools.
EMS SQL Manager seems to be a good option.
for the graphical view of SQL queries
maybe SQLeo can Help

Connecting to a MySQL database using Xcode and Objective-C

I have been interested in working with a MySQL database in my iPhone or Mac projects. How is a connection performed in Objective-C?
I only had a bit of experience with PHP, but heck, that is a bit too different =/
Check this tutorial for connectivity with SQLite.
You will not be able to connect to MySQL directly from the iPhone. You must use some intermediate layer such as a Web application with PHP.
So, you will have something like this:
iPhone POSTING a request to the WebServer using HTTP
Web Server connecting to the MySQL database
Web Server returning data to the iPhone (XML, plain text)
iPhone processing the data
You can use this technique to query and insert/update/delete data.
Once I found this library for MySQL, and I am aware how it works.
It's a much better option not to deal directly with MySQL, but use Apple's Core Data API.
It allows you to manage an relational database without having to write SQL. It's very fast, very useful. Good stuff.
Try absrd which recycles connections across concurrent threads (queues).
If you want to connect to a MySQL database, use MySQL's Connector/C API library which, as Objective-C is a strict superset of C, you can use without any issues. I helped someone with the installation of it here.

What's the likelihood of Orchard CMS running on postgresql database?

And if that is not possible, what are the implications of using SQL Express? Would there be anything wrong with using SQLExpress for the CMS db, and postgresql for my app?
Orchard does use NHibernate under the bonnet (http://www.orchardproject.net/docs/Orchard-dependencies-and-libraries.ashx), however the orchard web platform installer only allows you to choose between the sql compact database or a SQL Server instance (including express) -
see http://www.orchardproject.net/docs/Installing-Orchard.ashx
So out of the box at the moment no but as Raymond points out you can always write your own provider and contribute it to the Orchard project. (Check out this forum response to mysql - http://orchard.codeplex.com/Thread/View.aspx?ThreadId=229968).
NHibernate is the ORM that Orchard is using to access the database. NHibernate supports postgresql so the answer is yes. And ofcourse you can also write your own dataaccess layer that services access.
A few months after this question was asked, Marek Habersack added Mono support to Orchard. Part of that effort was adding support for running Orchard on PostgreSQL.
The patches for this must have been accepted as the current instructions for running Orchard on Mono do not require them to be added.
There were problems, at least initially, with the connection being dropped but there are reports of it running well.
I am not deeply familiar with this particular product, but unless they explicitly state that they support a certain SQL implementation, the chances are extremely slim that it would just happen to work. A quick look around their site suggests that you will need to use Microsoft's SQL Server.