Register now or log in to join your professional community.
If you're asking if you can connect using PDO and then subsequently use that PDO connection in a mysqli function, then no, you cannot do that.
12 $pdo = new PDO(...); mysqli_query($pdo, "...sql..."); // ERRORYou can connect twice to the same database using both PDO and mysqli, but each connection must be used only by same extension.
1234 $pdo = new PDO(...); $mysqli = new mysqli(...); $pdoStmt = $pdo->query("...sql..."); // OK $mysqliResult = $mysqli->query("...sql..."); // OKHowever, I agree with Manuel Bieh -- why would you want to do that? I suppose if you were calling some legacy library code that used mysqli but you wanted to use PDO in your new code, it's easier to open two connections than to rewrite some of the library code. But that's about the only reason I can think of not to use PDO consistently.
Answer copied from: https://www.quora.com/Is-it-posible-to-only-use-PDO-in-mysql-connection-but-the-other-mysql-query-using-mysqli
Yes to your question If I understood your question in a right way.
I think its better to use PDO in PHP coding to connect with various databases by preparing the connection string of that respective database and also a very standard one and is code reuse concept and also can be used as a dynamic polymorphism concept.
Please go through the below link for more clarity about PDO in PHP language.
http://code.tutsplus.com/tutorials/why-you-should-be-using-phps-pdo-for-database-access--net-12059
Thanks.