Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.
Trending News
Changing PHP scripts to use mysqli instead of mysql?
First off let me say that I know mysql was depreciated with the release of PHP 5.5 in 2013. I'm not looking for admonishments about how I'm behind the times or similar comments.
I am not a professional web developer. I am self-taught, and my use has been limited to my company's web site as well as some internal applications. All of the servers still support mysql, however I will be replacing an internal server which will necessitate an update, so I am more or less forced to make the switch.
Part of the reason I have put this off is because each time I have played around with mysqli in the past I have not been able to make it work. This switch is going to force me to rework numerous pages, as well as rewrite functions.
What I'm looking for is a straightforward tutorial on implementing mysqli. Many of the things I have read, including the PHP web site has very terse instructions which are not particularly helpful in understanding the differences.
2 Answers
- dazabasLv 45 years ago
Don't know what you are talking about, I remember, yes so so many years ago when I made the switch (haha), there weren't any problems, or so minor that I don't remember them.
Don't over think it, disable mysql extension, enable mysqli, go through the errors one by one. If some of the errors can be easily fixed by a project wide search and replace of the API, then do that.
Many modern editors let you do a project wide search and replace, using the free Atom editor for example, open the folder your PHP project is in, do a Find > Find in Project
The problem you have is one of the reasons why some people prefer to use an access layer, and not use the DB API directly
An over smplified example,
function q($sql) {
mysql_query($sql);
}
So that you don't have to write mysql_query($sql); in your program, only q($sql); So when you update to mysqli, you just change what's in your q() function
- ChrisLv 75 years ago
Asking the question like this is not helpful; you need to show us what code you've tried and how it failed.
The basic idea is something like:
function my_query($query) {
$db = new mysqli($server, $username, $password, $database);
$db->set_charset("utf8");
$result = $db->query($query);
if ($result->num_rows > 0) {
while ($row = $result->fetch_assoc()) $rows[] = $row;
return $rows;
}
return null;
}