http://drupal.org/node/224333 has two examples incorrect for d7, one refers to db_fetch_array in d7 and one refers to db_fetch_object in d7. These functions don't exist in D7 according to api.drupal.org and return a function not found.
Example 1:
Drupal 6.x:
function example_uninstall() {
$result = db_query("SELECT * FROM {example}");
while ($data = db_fetch_object($result)) {
db_query("DELETE FROM {variable} WHERE name = '%s'", 'example_'. $data->nid);
}
drupal_uninstall_schema('example');
}
Drupal 7.x:
function example_uninstall() {
$result = db_query("SELECT * FROM {example}");
while ($data = db_fetch_object($result)) {
db_query("DELETE FROM {variable} WHERE name = '%s'", 'example_', $data->nid);
}
}
Example 2:
Example - Drupal 6:
$result = db_fetch_array(db_query("SELECT * FROM {boxes} WHERE bid = %d", $bid));
Drupal 7:
$result = db_fetch_array(db_query("SELECT * FROM {block_custom} WHERE bid = %d", $bid));
Or just do a find on the page for db_fetch
I'm unsure what the correct example (hence why I was hitting this page in the first place, to find the answer for what I should be using in this situation)
Comments
Comment #1
jhodgdonThanks for reporting this! For future reference, we manage the Converting Modules guides in the Drupal Core issue queue, using tag "Needs Update Documentation".
Comment #2
coderintherye CreditAttribution: coderintherye commentedGreat, thank you, I will use that tag in the future.
I've actually got a number of things to file against that page :/, wondering if I should make them all one issue or separate issues?
Comment #3
jhodgdonSeparate issues for separate issues, if that makes sense. For example, if several places have the same problem, they can be grouped in the same issue (e.g., several examples are using old DB-related functions). But if the problems are unrelated, they should be in separate issues.
Are you interested in fixing any of the issues in the Needs Update Doc queue? Filing the issues is a HUGE help (you can verify yours are not there before you filed them), but fixing them would also be helpful.
You probably don't have permission to edit that page, but if you're interested, and feel you are a good writer of documentation, we can take care of that.
Comment #4
coderintherye CreditAttribution: coderintherye commentedAwesome, thanks for the response, and yes I am interested. I've done documentation at my previous job, so feel that at the least I won't detract from the page ;)
Given all the 6 -> 7 work I do, it's important for me to get that page in shape, because it's my go to resource almost every day.
Comment #5
droplet CreditAttribution: droplet commentedIn D7, default mode is fetch into object (PDO::FETCH_OBJ, equal to db_fetch_object in D6)
db_fetch_array
http://api.drupal.org/api/drupal/includes--database.mysql.inc/function/d...
which return ..
it used MYSQL_ASSOC, so turn into D7 and PDO, we do something like:
more:
http://www.php.net/manual/en/pdostatement.fetch.php
Comment #6
droplet CreditAttribution: droplet commentedmaybe this more clean
Comment #7
jhodgdonRE #4 - I thought the page was locked for editing, but looking at the input format I dont' think it is. Do you see the edit link at the top?
Comment #8
coderintherye CreditAttribution: coderintherye commentedI could have sworn it was before. Considering now that it is not (or that i am now just no longer blind), hopefully I can start making additions/revisions. Thanks.
Comment #9
jhodgdonPerhaps someone changed the input format and made that page editable. I thought it was locked before also.
Comment #10
jhodgdonI believe I have made the necessary changes. There were only two places I saw that used db_fetch_* in D7 examples, and I fixed both of them. If someone could review the changes and verify they are correct, that would be helpful. Meanwhile, marking fixed.
http://drupal.org/node/224333/revisions/view/1482240/1482266
Comment #11
droplet CreditAttribution: droplet commentedit looks good.