ابدأ بالتواصل مع الأشخاص وتبادل معارفك المهنية

أنشئ حسابًا أو سجّل الدخول للانضمام إلى مجتمعك المهني.

متابعة

Is it posible to only use PDO in mysql connection, but the other mysql query using mysqli?

user-image
تم إضافة السؤال من قبل Faten Almajaly
تاريخ النشر: 2015/09/02
Wajahat Ali
من قبل Wajahat Ali , Business Analyst II , S&P Global Market Intelligence (Legacy SNL Financials)

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..."); // ERROR

You 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..."); // OK

However, 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

Gayasuddin Mohammed
من قبل Gayasuddin Mohammed , Advocate , Practicing Law before High Court at Hyderabad

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.

 

المزيد من الأسئلة المماثلة

هل تحتاج لمساعدة في كتابة سيرة ذاتية تحتوي على الكلمات الدلالية التي يبحث عنها أصحاب العمل؟