Jump to content
MakeWebGames

PDO. The way forward?


Script47

Recommended Posts

So last night, I was told to check out PDO, as it's said to be easier, better and less confusing compared to others out there. So I did, I have to say I like it a lot, converted a full project from MySQLi_* to PDO, It's very simple to grasp (IMO) and I will be using it for future projects too. So if it's so easy, why doesn't everyone use it. I converted most of my code in like three hours while learning at the same time. Are there some hidden cons about it or something?

Link to comment
Share on other sites

Its just simpler to switch to MYSQLI especially if you come from mysql...PDO has a slight learning curve but nothing to extremely difficult. I switched from mysql to PDO a year or 2 ago and I've never had a problem with it. There are some cases where things take more steps like, mysql_num_rows for example in pdo there is a 3 step way to do it or you have to use PDO::FETCH_NUM format combined with count which I just recently ran across, but thats a simple example of something that takes a bit more to do but its a trade off, everything is useful for something and better at something.

Link to comment
Share on other sites

Its just simpler to switch to MYSQLI especially if you come from mysql...PDO has a slight learning curve but nothing to extremely difficult. I switched from mysql to PDO a year or 2 ago and I've never had a problem with it. There are some cases where things take more steps like, mysql_num_rows for example in pdo there is a 3 step way to do it or you have to use PDO::FETCH_NUM format combined with count which I just recently ran across, but thats a simple example of something that takes a bit more to do but its a trade off, everything is useful for something and better at something.

I did not know that, thanks for this, will check out that.

 

PDO is easy

Very nice input in thread.

Link to comment
Share on other sites

I only use PDO if it's required by the project at hand.

If it's a new project or my own, I generally stick to MySQLi as it does what I need.

I'd say it's down to preference, unless you need certain aspects of PDO that MySQLi doesn't have (IE: The ability to switch DBMS).

As for PDO being the way forward, I think both are a step forward, don't know how long either will last, or what will come at a later date, however both are recommended over PHP's mysql_* lib.

Link to comment
Share on other sites

Whats funny in this community, is that as soon as someone starts using a new close, the rest follow?

Personally, I'd opt for MySQLi, because I do not need 12 drivers supported, and I'd like the 3% - 5% speed difference from PDO to MySQLi.

http://net.tutsplus.com/tutorials/php/pdo-vs-mysqli-which-should-you-use/

I feel like, if you're trying to say MySQLi is the better choice, you definitely referenced the wrong article. Just saying.

Link to comment
Share on other sites

I would also say that multiple DB support (for a single project) is most of the time useless. Why? Because SQL is sadly not 100% uniform, so changing just the connection information to point to a new DB will not suffice to make your PDO enabled software work with another database unless you use only the most basic SQL features. Even join could be handled differently (look at how oracle uses the (+) sign ).

Also, unless you will sell your script to companies which have special requirements, having your script working only on MySQL should do the trick most of the cases.

Now is PDO useless? No I think it's more a question of trying to bring PHP up to par with let's say Java and it's JDBC which is a uniform way to access databases. It does make sense in general. Yet then, why offer MySQLi too? Well only the PHP developers can answer this question. Use either MySQLi or PDO, but what's sure, move away from the old MySQL interface and also, use the binding instead of passing the values inside the query string.

Link to comment
Share on other sites

  • 1 month later...

PDO is the way forward for a few reasons

MySQL functions WILL be depreciated as of php5.5 and onwards eventually removed, so its better to get moving towards it now then when your site breaks cause your using old code.

PDO can use many drivers list here:

PDO_CUBRID Cubrid

PDO_DBLIB FreeTDS / Microsoft SQL Server / Sybase

PDO_FIREBIRD Firebird

PDO_IBM IBM DB2

PDO_INFORMIX IBM Informix Dynamic Server

PDO_MYSQL MySQL 3.x/4.x/5.x

PDO_OCI Oracle Call Interface

PDO_ODBC ODBC v3 (IBM DB2, unixODBC and win32 ODBC)

PDO_PGSQL PostgreSQL

PDO_SQLITE SQLite 3 and SQLite 2

PDO_SQLSRV Microsoft SQL Server / SQL Azure

PDO_4D 4D

All round if your afraid to use PDO don't be cause you will love it in end and it will become a part of your coding career.

The more you use it the more it will become like second nature.

Link to comment
Share on other sites

PDO is the way forward for a few reasons

MySQL functions WILL be depreciated as of php5.5 and onwards eventually removed, so its better to get moving towards it now then when your site breaks cause your using old code.

PDO can use many drivers list here:

PDO_CUBRID Cubrid

PDO_DBLIB FreeTDS / Microsoft SQL Server / Sybase

PDO_FIREBIRD Firebird

PDO_IBM IBM DB2

PDO_INFORMIX IBM Informix Dynamic Server

PDO_MYSQL MySQL 3.x/4.x/5.x

PDO_OCI Oracle Call Interface

PDO_ODBC ODBC v3 (IBM DB2, unixODBC and win32 ODBC)

PDO_PGSQL PostgreSQL

PDO_SQLITE SQLite 3 and SQLite 2

PDO_SQLSRV Microsoft SQL Server / SQL Azure

PDO_4D 4D

All round if your afraid to use PDO don't be cause you will love it in end and it will become a part of your coding career.

The more you use it the more it will become like second nature.

PDO is just "ANOTHER" way forward, its not THE way.

Plus, in a game, would you use all those drivers? Probably not. In an industry software? Probably yes, and probably not. Most developers will stick to one driver, thus rendering PDO somewhat useless as you won't require all those drivers, and will just be a burden on yourself if you are mixing all the drivers.

Link to comment
Share on other sites

Ummm mate im not saying you have to use all drivers at all but what dont you understand about depreciation all mysql_query mysql_fetch_array row etc etc will be removed from php making it that you must use the PDO classes built for php or move to mySQli.. this mean any game site that connects to a db unless on older version of php will have to use PDO eventually or mySQLi ethier way for those using ext/mysql will be screwed..

the reason i showed the drivers was to open up that PDO is and will become very versitile. and the drivers are only used like this let me show you some example

 

private function Connect()
	{
		$this->settings = parse_ini_file("connect.ini.php");
		//BELOW IS WHERE DRIVER IS USED DEPENDING ON WHAT DB YOU NEED TO CONNECT TO
                       $dsn = 'mysql:dbname='.$this->settings["dbname"].';host='.$this->settings["host"].'';
		try 
		{
			// Read settings from INI file
			$this->pdo = new PDO($dsn, $this->settings["user"], $this->settings["password"]);

			// We can now log any exceptions on Fatal error. 
			$this->pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

			// Disable emulation of prepared statements, use REAL prepared statements instead.
			$this->pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);

			// Connection succeeded, set the boolean to true.
			$this->bConnected = true;
		}
		catch (PDOException $e) 
		{

			echo $this->ExceptionLog($e->getMessage());
			die();
		}
	}
Link to comment
Share on other sites

Ummm mate im not saying you have to use all drivers at all but what dont you understand about depreciation all mysql_query mysql_fetch_array row etc etc will be removed from php making it that you must use the PDO classes built for php or move to mySQli.. this mean any game site that connects to a db unless on older version of php will have to use PDO eventually or mySQLi ethier way for those using ext/mysql will be screwed..

the reason i showed the drivers was to open up that PDO is and will become very versitile. and the drivers are only used like this let me show you some example

 

private function Connect()
	{
		$this->settings = parse_ini_file("connect.ini.php");
		//BELOW IS WHERE DRIVER IS USED DEPENDING ON WHAT DB YOU NEED TO CONNECT TO
                       $dsn = 'mysql:dbname='.$this->settings["dbname"].';host='.$this->settings["host"].'';
		try 
		{
			// Read settings from INI file
			$this->pdo = new PDO($dsn, $this->settings["user"], $this->settings["password"]);

			// We can now log any exceptions on Fatal error. 
			$this->pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

			// Disable emulation of prepared statements, use REAL prepared statements instead.
			$this->pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);

			// Connection succeeded, set the boolean to true.
			$this->bConnected = true;
		}
		catch (PDOException $e) 
		{

			echo $this->ExceptionLog($e->getMessage());
			die();
		}
	}

Ummm mate, if you had to bother reading this thread. You would see on page one I said I would personally opt for MySQLi. I bet you now, 95% of people on here, are moving away from mysql, or know that mysql is going to be dead soon.

No need to show me examples.

Also "depreciation":

the decrease in value of assets (fair value depreciation), and

the allocation of the cost of assets to periods in which the assets are used (depreciation with the matching principle).

 

"Deprecation":

Deprecation is a status applied to a computer software feature, characteristic, or practice indicating it should be avoided, typically because of it being superseded.

Also, to be frank. the mysql_* extension is deprecated. And yes it will throw out errors, but then again, you can suppress those errors via error_reporting:

error_reporting(E_ALL ^ E_DEPRECATED);

 

I iz gramma nazi!

The reason for my response to you is. The title is set as "PDO. The way forward?", now everyone is jumping on the bandwagon, trying to learn PDO because as title and posts suggest "its the way forward", when infact its not the only way and they could simply switch to MySQLi without much fuss.

You see my reasoning?

Link to comment
Share on other sites

I see your reasoning...

Also, to be frank. the mysql_* extension is deprecated. And yes it will throw out errors, but then again, you can suppress those errors via error_reporting:

?

1

error_reporting(E_ALL ^ E_DEPRECATED);

To be perfectly frank here this is bad form. You should not do this just cause it throws errors up suppressing errors notices dose not fix them.

and how can you suppress fatal errors when its fully removed that is just a quick fix dose not solve anything. teaching people to do this is just bad plain bad.

MySQLi is good for somethings but not for everything and it depends on situation.

also you can be a gramma nazi all you like shows what a dick you actually are.not everyone is perfect at English

Now my reasoning to PDO being the way forward is the fact its already becoming a industry standard, MySQLi is bound only to MySQL where as PDO can connect to many different databases as well as MySQL. So that in itself proves with out shadow of doubt that it better to use more flexible.(although this is not just my opinion there si many who think the same.

Just cause its not the only option dose not mean it wont be the best option. the learning curve for MySQLi is not hard at all pretty much same as old MySQL

PDO is harder to learn if your not a object orientated programmer. Once learned you start to see how much better it is and why, but again its personal preference.

You can say what you like but PDO is the way to go as everyone will most likely use it in end as industry standard. For me to get a job it is also one of the basic requirements for working where I work, now and im guessing would be same in any company similar to the one i work at.

Link to comment
Share on other sites

I see your reasoning...

To be perfectly frank here this is bad form. You should not do this just cause it throws errors up suppressing errors notices dose not fix them.

and how can you suppress fatal errors when its fully removed that is just a quick fix dose not solve anything. teaching people to do this is just bad plain bad.

MySQLi is good for somethings but not for everything and it depends on situation.

also you can be a gramma nazi all you like shows what a dick you actually are.not everyone is perfect at English

Now my reasoning to PDO being the way forward is the fact its already becoming a industry standard, MySQLi is bound only to MySQL where as PDO can connect to many different databases as well as MySQL. So that in itself proves with out shadow of doubt that it better to use more flexible.(although this is not just my opinion there si many who think the same.

Just cause its not the only option dose not mean it wont be the best option. the learning curve for MySQLi is not hard at all pretty much same as old MySQL

PDO is harder to learn if your not a object orientated programmer. Once learned you start to see how much better it is and why, but again its personal preference.

You can say what you like but PDO is the way to go as everyone will most likely use it in end as industry standard. For me to get a job it is also one of the basic requirements for working where I work, now and im guessing would be same in any company similar to the one i work at.

No where do I entail that users should suppress the errors. Was just stating a fact. And just because it is "deprecated" does not mean it can no longer be used. Just imagine all those websites out there that are out of date, and they are on shared hosts, and they upgrade php, then all those websites don't work? Thus is why you get "deprecated" errors. Not that it won't work any more.

Tell me, how much better is mysqli over pdo?

Also, tell me, how often do you find yourself using the other drivers of PDO?

Also, how many people have jumped on the bandwagon of PDO, thinking its "THE" way forward, and are pretty much using the mysql driver?

Again, PDO is just another option forward, its not "THE" way, so stop putting that out to everyone reading your posts.

As you stated yourself "PDO is harder to learn if your not a object orientated programmer", which goes to all new mccode game owners, cause mccode's does not have OOP!

As for industry standards. It might be a requirement to get a job if you got PDO on your CV. But its not an industry standard, never will be. Many industries will have their own reasonings as to why to choose mysqli over pdo, but thats their own opinion. After all, the PDO MySQL driver uses the same client library as MySQLi

The flexibility of PDO far outweighs mysqli, but then again, its to the coder as to what he requires.

I do not want to create an argument. And should be told that PDO is a better option forward, than just "ITS THE WAY FORWARD AND THATS THAT" attitude.

Link to comment
Share on other sites

No where do I entail that users should suppress the errors. Was just stating a fact. And just because it is "deprecated" does not mean it can no longer be used. Just imagine all those websites out there that are out of date, and they are on shared hosts, and they upgrade php, then all those websites don't work? Thus is why you get "deprecated" errors. Not that it won't work any more.

I cant win with you Ive already stated that its being depreciated we know this, you said thats ok we can suppress those errors. The fact you even show a option to suppress them shows you yourself would do that or at least thats what your teaching others by setting it as an example, some newbie coder would think thats there fix and never learn and cry when there script dies.

Also it's not just being depreciated it is being completely removed so yes those out of date website will stop working the day that happens unless they stay with older versions.Dose this make sence to you now.. I hope so....

Your opinion is yours, mine is mine when it come to becoming a industry standard I work in the industry so I like to think I know something about trends

there is enough evidence to prove its becoming a industry standard in php to say it isnt or wont is just bull**** they said same thing about OOP and looky now most major frameworks and websites are OOP orentated, they even said that about MVC and look now so many frameworks use this model. so stop kidding your self please.

also let me give you a example of why pdo and its driver ability is better, lets say you make a web game or online game with c++ and your using Microsoft SQL Server as database and you have a website and want to show of stats MySqli wont we able to connect to that db but PDO can this is another reason why PDO is the way to go there is many examples of why its better overall

I don't want a argument and am not saying you should defenitly choose PDO im just saying that the majority will go with PDO.

So I'm just gonna agree to disagree with you and that will be the end of it.

unless you can give me something to prove otherwise.

Edited by advocaite
Link to comment
Share on other sites

Getting us back on track a little, my personal choice is MySQLi.

My current line of work doesn't need PDO, so I won't use it.

The only thing that would be advantageous in my use of PDO is the catch the insecurities that I miss (which is bloody rare) - and I always proof-read my work.

I will admit, I've been having some serious thought about whether I should start using PDO full time and eradicate my MySQLi methods entirely, but I so little to no point.

My work is secure, so preparing statements isn't a necessity.

The people I work for prefer MySQLi over PDO.

I prefer MySQLi over PDO (then again, I'm much more comfortable with MySQLi).

All-in-all, I think I'm happy to switch over in the future should the industrial side demand it, but I'm happy with MySQLi.

It does what I want, when I want, and how - naturally, I've wrote my own class and a couple of abstraction layers and, they all use MySQLi (and a couple of converted-from-Python tricks)

Link to comment
Share on other sites

Getting us back on track a little, my personal choice is MySQLi.

My current line of work doesn't need PDO, so I won't use it.

The only thing that would be advantageous in my use of PDO is the catch the insecurities that I miss (which is bloody rare) - and I always proof-read my work.

I will admit, I've been having some serious thought about whether I should start using PDO full time and eradicate my MySQLi methods entirely, but I so little to no point.

My work is secure, so preparing statements isn't a necessity.

The people I work for prefer MySQLi over PDO.

I prefer MySQLi over PDO (then again, I'm much more comfortable with MySQLi).

All-in-all, I think I'm happy to switch over in the future should the industrial side demand it, but I'm happy with MySQLi.

It does what I want, when I want, and how - naturally, I've wrote my own class and a couple of abstraction layers and, they all use MySQLi (and a couple of converted-from-Python tricks)

I thought the same way as you, I was comfortable with MySQLi and my code was secure. But I thought why not, that's the reason I changed, plus I was told it would be used a lot more frequently in the future.

Link to comment
Share on other sites

The problem with sticking to MySQLi, is that you're bound to a MySQL database, whereas PDO offers a layer from the database, allowing you not to be bound to only a MySQL database - so in that respect, yes, it is the way forward for some development/live environments.

 

My work is secure, so preparing statements isn't a necessity.

- murphy's law applies

- quasi-perfect equilibrium applies

Edited by sniko
Link to comment
Share on other sites

The problem with sticking to MySQLi, is that you're bound to a MySQL database, whereas PDO offers a layer from the database, allowing you not to be bound to only a MySQL database - so in that respect, yes, it is the way forward for some development/live environments.

 

- murphy's law applies

- quasi-perfect equilibrium applies

Alright.. *rephrases*

My work is secured against threats I know how to secure against

Prepping statements is still not currently necessary, whether or not I'm setting myself up for future failure :P

Edited by Magictallguy
Grammatical error
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...