WordPressで関数get_row()に問題があり、自分の状況に満足のいく答えが見つかりません。それはWordPress関数get_row()が正しく動作しません
function take_category() {
$table_result = array();
$connect_to = connect_to_db();
$question = "select id_cat, name_cat from category";
if (!($result=$connect_to->get_results($question, ARRAY_N))) {
return false;
}
$prepared_row =$connect_to->prepare("%s", $question);
var_dump($prepared_row);
$row=$conntect_to->get_row($prepared_row, ARRAY_N, 1); // line 689
var_dump($row).'</br>';
for ($count=0; $row=$conntect_to->get_row($question, ARRAY_N, 1);
$count++) {
$table_result[$count] = $row;
.........
return $table_result;
この関数はのfunctions.phpに配置された私のコードの一部です。機能connect_to_db()も同様に、このファイルに定義されています。データベースへ
function connect_to_db() {
global $wpdb;
$wpdb = new wpdb('****', '', '****store', 'localhost');
if (!$wpdb) {
return false;
} else{
$wpdb->query('SET autocommit = 1;');
return $wpdb;
}
}
接続が正常に働いています。機能も正しく動作します。
string(39) "'select id_cat, name_cat from category'"
しかし、ショーはNULLを引き起こす
$row=$conntect_to->get_row($prepared_row, ARRAY_N, 1); // line 689
var_dump($row);
コードの次の部分:致命的なエラー
***Fatal error:** Uncaught Error: Call to a member function get_row() on
null in ....\functions.php:689 Stack trace: #0 ...\indeks.php(12):
take_category() #1 {main} thrown in ...\functions.php on line 689*
ファイルindeks.phpこれはのvar_dump($ prepared_row)でありますは、ファンクションのtake_cate血みどろの()が呼び出されます。
$row=$connect_to->get_row("select id_cat, name_cat from category",
ARRAY_N, 1);
は、私が見のvar_dump($行):
array(2) { [0]=> string(1) "2" [1]=> string(9) "Textbooks" }
と
$cat_table = take_category();
をしかし、私はこのように私のライン689を変更した場合同じ致命的なエラー!
機能に問題がありますget_row?
親愛なる紳士私は問題が見つかりました。あなたの腰をひねって申し訳ありません...
親愛なる紳士!返信ありがとうございます。私はこの間違いを見つけて修正したと書きました。残念ながら、私は私の質問を削除することができませんでした。ごめんなさい。 –