If there is a way, I don’t think it’s a good idea.
It is quite possible to have one script use PDO and another one use mysqli. But I would advise to choose one and stick to it.
In the code you posted the pdo $conn will overwrite the mysqli $conn.
It is highly recommended that you not do that. Mixing 2 different database APIs together will cause your application to crash or have outrageously large amounts of fatal errors or warnings. If you are trying to support both database APIs, there is a better way by separating the two into 2 different files that run equivalent functions.
If anyone happens to be looking for a textbook example of Fear Uncertainty Doubt (FUD) then link to the above quote. As a bonus, it is also 100% fact free.
It depends how you go about the mixing. If you have a mysqli resource and try PDO methods or vice versus, it will error. If you use both but keep the resources and their associated methods in order, you may not get errors, but the code will be prone to confusion that might result in errors.
For example, it would be possible to use mysqli for a SELECT and PDO for an INSERT, but why? Two resource connections might not be disastrous but seems totally pointless to do to me.
The only exception where I’d want both is if I were refactoring code a bit at a time as I had the time to modify code I didn’t have the time to change all at once.
Sure. But there are times you might want to include a 3rd party module which might happen to use a different database api. I was simply reacting to the amazingly silly assertion in the quote.
I don’t think it’s silly at all. We had someone mix matching PDO and mysqli_ earlier last year. When I went to debug it, it came up with like 4 or 5 different errors. I honestly don’t think it’s “FUD” at all. If you want to, go right a head. But I won’t debug someone’s errors if they’ve been told more than once to not mix match database APIs. Now, that’s more silly.