从MySQL到MySQLi的最简单过渡 [英] Simplest MySQL to MySQLi transition

查看:60
本文介绍了从MySQL到MySQLi的最简单过渡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用在课堂上教过的折旧的MySQL.我看到这不是正确的方法,有两个更好的选择:MySQLi,甚至更好的是PDO.由于我对OOP一无所知,因此我觉得切换到PDO有点困难,但我认为至少必须切换到MySQLi.我在此问题之前先检查了SO和其他来源的信息,以获取有关过渡的信息,我尝试应用所学的知识,但是结果并不太好,所以我将当前连接发布到数据库中,然后等待MySQLi此代码的过渡.如果附带说明会更好,因为学习是我的目标,而不仅仅是使用代码.如果没有,我将自己努力弄清楚,眼前有正确的代码,而旧代码将告诉我有什么不同.

I'm currently using the depreciated MySQL that I've been taught in a class. I saw that it's not the right way to go and there are two better options: MySQLi and, even better, PDO. While I find switching to PDO to be kinda difficult for me since I have no idea whatsoever about OOP, I think that switching to at least MySQLi is a must. I checked SO and other sources in advance of this question for information regarding the transition and I tried to apply what I learned but it didn't ended up too well so I'll just post my current connection to the database and wait for a MySQLi transition of this code. If it comes with explanations that's even better, since learning is my purpose, not just using the code. If not... I'll try to figure it out by myself, having the correct code in front of my eyes and the old code will show me what's different.

<?php
    define("DB_HOST", "localhost");
    define("DB_USER","root");
    define("DB_PASS", "");
    define("DB_DATABASE","spore_db");

    $connect = mysql_connect(DB_HOST,DB_USER,DB_PASS) or die(mysql_error());

    mysql_select_db(DB_DATABASE) or die(mysql_error());
?>

在降级之前,请让我知道,以便我可以编辑我的问题.谢谢!

Please let me know before downrating so I can edit my question. Thanks!

推荐答案

  1. 无论如何,这不是一个好问题. 堆栈溢出根本不是要求教程的地方.
  2. 您不必去搜索一本教程,而是去谷歌搜索一个教程,然后尝试,然后就遇到的特定问题提出一个问题.
  3. 以机械方式将mysql_功能替换为其mysqli_对应功能完全没有道理
  4. 您真正需要的是在应用程序代码中摆脱调用RAW API函数(无论是mysqli还是mysql).并开始使用某种抽象库.尤其是因为使用原始mysqli真是糟糕的体验
  5. PDO比mysqli更好,仅因为它本身就是这样的库.
  6. 就使用它而言,
  7. OOP并不那么令人恐惧.没有人要求您编写自己的OOP代码,而调用现有的OOP方法并不比调用熟悉的函数复杂.唯一的区别是->东西:

  1. This is not a nice question by any means. Stack overflow is not a place to ask for a tutorial at all.
  2. Instead of asking for a tutorial you have to google for one, then try, then ask a question on a particular problem you stuck with.
  3. Replacing mysql_ functions with their mysqli_ counterparts mechanically makes absolutely no sense
  4. What you really need is to get rid of calling RAW API functions, be it mysqli or mysql, right in the application code. And start using some sort of abstraction library instead. Especially because with working with raw mysqli is just awful experience
  5. PDO is better than mysqli only because it is being such a library itself.
  6. OOP is not that scary in terms of using it. Nobody asks you to write your own OOP code, while calling existing OOP methods is no more complex than calling familiar functions. The only difference is -> thing:

$result = function($data);
$result = $class->function($data);

这是全部,您需要了解有关使用OOP的知识(保存可变范围问题)

This is ALL you need to know about OOP to use it (save for the variable scope issues)

尝试PDO 并不像您想象的那么复杂.您有一天必须开始学习编程-因此,最好早点开始.

To try PDO out is not that complex as you imagine. You'd have to start learn programming some day - so, it's better to start sooner.

这篇关于从MySQL到MySQLi的最简单过渡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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