如何在WordPress中使用mysqli [英] How to use mysqli in WordPress

查看:101
本文介绍了如何在WordPress中使用mysqli的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要知道如何在WordPress中使用mysqli.我不想使用wpdb或PDO其他任何东西.实际上,问题是有190多个用mysql编写的查询,我需要将它们转换为mysqli,我知道更好的解决方案是使用wpdb.但这会花费更多时间.所以我只需要知道如何在WordPress中使用mysqli.我已经用谷歌搜索了很多,但是每个人都建议使用wpdb,但是我想坚持使用mysqli.

I need to know how to use mysqli in WordPress. I don't want to use wpdb or PDO any thing else. Actually the issue is there are 190+ queries written in mysql and i need to convert them to mysqli, i know the better solution is to go with wpdb. But it would be more time taking. So i just i need to know how to use mysqli in WordPress. I have googled it lot but every where every one is suggesting to use wpdb, but i want to stick with mysqli.

所以现在我的代码是:

mysql_query("select * from `wp_users`);

如果我用mysqli编写,那将会是

if I write in mysqli it would be

mysqli_query($HOW_TO_GIVE_CONNECTION_HERE, "select * from `wp_users`);

谢谢!

推荐答案

从头开始,您想学习将MySQL与php结合使用是正确的.当您了解如何以及何时使用它们时,可以使用库,快捷方式和优化.这是基本的msqli可以多么简单的示例:

You're right to want to learn to use MySQL with php from the ground up. You can use libraries and shortcuts and optimizations when you appreciate how and when to use them. Here's an example of how straightforward basic msqli can be:

        <?php
                    $con=mysqli_connect("localhost","my_user","my_password","my_db");

                    // Check connection
                    if (mysqli_connect_errno())
                      {
                      echo "Failed to connect to MySQL: " . mysqli_connect_error();
                      }

                    // Perform queries
                    mysqli_query($con,"SELECT * FROM Persons");
                    mysqli_query($con,"INSERT INTO Persons (FirstName,LastName,Age)
                    VALUES ('Glenn','Quagmire',33)");

                    mysqli_close($con);
        ?> 

如果您对对象感到满意,这是一个很好的教程: http://codular.com/php-mysqli 但是此功能比较全面,可以为您提供PHP-MySQL的良好基础: https://www.binpress.com/tutorial /using-php-with-mysql-the-right-way/17

If you're comfortable with objects this is a good tutorial: http://codular.com/php-mysqli but this one is a bit fuller and will give you a very good grounding in PHP-MySQL: https://www.binpress.com/tutorial/using-php-with-mysql-the-right-way/17

这篇关于如何在WordPress中使用mysqli的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆