プロが教える店舗&オフィスのセキュリティ対策術

http://oshiete.goo.ne.jp/qa/8228275.html
の続編です。

何度もすみません、エラーは消えたのですが、やりたいことが実現できていないので、質問します・・・
mysqliを使ってデータベースを表示したいのですが、肝心の表示部分ができません。
printでテストしてみたのですが、中身が入っていない?ようなのです。
よくわからないので、教えて頂きたいです。
DBはphpmyAdminで作成しました。

/* 変数定義関連 */
/* mysqliの定義 */
global $mysqli;
$mysqli = new mysqli('localhost', 'root', "", "***_db");
//$link = mysqli_connect('localhost', 'root', "", "***_db");

/* 接続状況をチェックします */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
print("<BR>");

/* 現在のデフォルトデータベース名を返します */
if ($result = $mysqli->query("SELECT DATABASE()")) {
$row = $result->fetch_row();
printf("befor Default database is %s.\n", $row[0]);
$result->close();
}

print("<BR>");

/* データベースを ***_db に変更します */
$mysqli->select_db("***_db");

/* 現在のデフォルトデータベース名を返します */
if ($result = $mysqli->query("SELECT DATABASE()")) {
$row = $result->fetch_row();
printf("change after Default database is %s.<BR><BR>", $row[0]);
$result->close();
}

// データベースのdump
echo "↓start_dump<BR>";
echo "<pre>";var_dump($mysqli);echo "</pre>";
echo "↑end_dump<BR>";

// バインドデータ設定
$key = 'c_name';
$num = 1;

/* プリペアドステートメントを作成します whereの箇所はプレースホルダ(xxx=?)をつけること! */
/* 「*」 はダメってこと?ちゃんと指定しないとbind_resultでエラー?*/

$sql = "SELECT c_name,c_job,c_prace,c_working_time,c_salary,c_treats,c_capacity,c_person,c_process,c_interview_day,c_person_in_charge,c_single_word,c_contact,c_web_site,c_condition FROM `test_table` WHERE c_name=?";
$stmt = $mysqli->prepare($sql);
//printf("実行SQL<BR>");
//printf("%s<BR>",$sql);
if($stmt = $mysqli->prepare($sql)) {
//printf("%s<BR>",$stmt);
/* マーカにパラメータをバインドします */
//バインドする変数はprepareで読み込んだ変数個数?のみ
$stmt->bind_param('i', $num); // バインドする変数に設定して送る

/* クエリを実行します */
$stmt->execute();

/* 結果変数をバインドします */
//戻り値と全ての項目の変数名を関連付ける(項目1~16)※SELECTの数と合わせること。
$stmt->bind_result($col1,$col2,$col3,$col4,$col5,$col6,$col7,$col8,$col9,$col10,$col11,$col12,$col13,$col14,$col15);
//$stmt->bind_result($col1,$col2); // バインドする変数分設定

//$num = $stmt->fetch();//debug用
//printf("<BR>%s\n", $num);
printf("testes\n");
printf("%s",$col1);
printf("%s %s %s %s %s %s %s %s %s %s %s %s %s %s %s\n\n\n",$col1,$col2,$col3,$col4,$col5,$col6,$col7,$col8,$col9,$col10,$col11,$col12,$col13,$col14,$col15);

/* 値を取得します */
while ($stmt->fetch()){
printf("testes");//入ってない
printf("%s %s %s %s %s %s %s %s %s %s %s %s %s %s %s\n",$col1,$col2,$col3,$col4,$col5,$col6,$col7,$col8,$col9,$col10,$col11,$col12,$col13,$col14,$col15);
}

printf("<BR>num=%s\n", $num);


/* ステートメントを閉じます */
$stmt->close();
}

// 切断
$mysqli->close();

dumpは以下の通りに出ます
object(mysqli)#1 (19) {
["affected_rows"]=>
int(1)
["client_info"]=>
string(75) "mysqlnd 5.0.10 - 20111026 - $Id: e707c415db32080b3752b232487a435ee0372157 $"
["client_version"]=>
int(50010)
["connect_errno"]=>
int(0)
["connect_error"]=>
NULL
["errno"]=>
int(0)
["error"]=>
string(0) ""
["error_list"]=>
array(0) {
}
["field_count"]=>
int(1)
["host_info"]=>
string(20) "localhost via TCP/IP"
["info"]=>
NULL
["insert_id"]=>
int(0)
["server_info"]=>
string(6) "5.5.32"
["server_version"]=>
int(50532)
["stat"]=>
string(134) "Uptime: 6961 Threads: 1 Questions: 1535 Slow queries: 0 Opens: 100 Flush tables: 1 Open tables: 1 Queries per second avg: 0.220"
["sqlstate"]=>
string(5) "00000"
["protocol_version"]=>
int(10)
["thread_id"]=>
int(152)
["warning_count"]=>
int(0)
}

A 回答 (1件)

test_tableテーブルにc_name=1のレコードはほんとにあるのでしょうか?

この回答への補足

返信ありがとうございます。
tableの確認をしたかったのですが、phpmyadminがエラーになってしまい、確認できませんので、現在調査しているところです。そちらは別の質問でさせていただいているので、確認に時間がかかりそうです。

補足日時:2013/08/22 19:15
    • good
    • 0

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!