phpのエラーについてです

このQ&Aのポイント
  • phpのエラーが表示される原因とは?
  • mysql_fetch_assoc()のパラメータが間違っている可能性
  • プログラムを実行する際のチェックポイント
回答を見る
  • ベストアンサー

phpのエラーについてです

mysql上のデータをphpでブラウザに表示するコードを書いています。 下記のプログラムを実行した所 Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in C:\xampplite\htdocs\shop\index.php on line 18 というようなエラーが表示されます。 本の通りに進めているので間違っていないはずなんですが・・ どこが成立していないのでしょうか??? <?php mysql_connect('localhost', 'root', '') or die(mysql_error()); mysql_select_db('mydb'); mysql_query('SET NAMES UTF8'); $recordSet = mysql_query('SELECT m.name, i.* FROM makers m, my_ items i WHERE m.id=i.maker_id ORDER BY id DESC'); ?> <table width="100%"> <tr> <th scope="col">ID</th> <th scope="col">メーカー</th> <th scope="col">商品名</th> <th scope="col">価格</th> </tr> <?php while ($table = mysql_fetch_assoc($recordSet)) { ?> <tr> <td><?php print(htmlspecialchars($table['id'])); ?></tb> <td><?php print(htmlspecialchars($table['name'])); ?></tb> <td><?php print(htmlspecialchars($table['item'])); ?></tb> <td><?php print(htmlspecialchars($table['price'])); ?></tb> </tr> <?php } ?> </table>

  • PHP
  • 回答数1
  • ありがとう数1

質問者が選んだベストアンサー

  • ベストアンサー
  • mzon
  • ベストアンサー率48% (26/54)
回答No.1

『C:\xampplite\htdocs\index.php の第18行に誤りがあります。』 『mysql_fetch_assoc() は、第1パラメータがリソースであるべき』のエラーです。 18行目がどこかわからないが 『while ($table = mysql_fetch_assoc($recordSet)) {』多分これかな? 『$recordSet』がSQLの結果になっていないためエラーになってます。 原因は、いろいろ 1.DBにデータがない、 2.DBのフィールドとSELECT文が一致していない 3.接続先のDBを間違えている。 4.そもそもPHPでMYSQLが使えない(PHP.iniでロードしてない) などなど、 「mysql_connect('localhost', 'root', '') or die(mysql_error()); mysql_select_db('mydb'); mysql_query('SET NAMES UTF8'); $recordSet = mysql_query('SELECT m.name, i.* FROM makers m, my_ 」 それぞれの関数の実行結果を確認するようにすれば、どこで原因があるのかわかると思います。 調べてみてください。 あと、「mysql_fetch_assoc() expects parameter 1 to be resource」で検索するとそれなりに情報がヒットしますよ (英語も多いですが、そこは雰囲気で確認してみるべし)

関連するQ&A

  • テーブルの情報が一部しか表示されません。(php)

    すべてのID分の提出状況を表示させたい("○"か"×")のですが、 id=1の提出状況しか表示されません。 テストデータはid=5までの5件を入力しています。 $recordSet2 = mysql_query('SELECT * FROM report'); をwhileにいれてみたり試行錯誤してみたのですが、上手くいきません。 ご指摘よろしくお願い致します。 プログラム <table width="70%"> <tr> <th scope="col"><bl>ID</bl></th> <th scope="col"><bl>教科名</bl></th> <th scope="col"><bl>課題名</bl></th> <th scope="col"><bl>担当教員</bl></th> <th scope="col"><bl>提出期限</bl></th> <th scope="col"><bl>再提出</bl></th> <th scope="col"><bl>再提出期限</bl></th> <th scope="col"><bl>提出状況</bl></th> </tr> <?php $recordSet = mysql_query('SELECT * FROM exercise ORDER BY id'); while ($table = mysql_fetch_assoc($recordSet)){ ?> <tr> <td><?php print(htmlspecialchars($table['id'])); ?></td> <td><?php print(htmlspecialchars($table['lessonname'])); ?></td> <td><?php print(htmlspecialchars($table['name'])); ?></td> <td><?php print(htmlspecialchars($table['teacher'])); ?></td> <td><?php print(htmlspecialchars($table['presentday'])); ?></td> <td><?php print(htmlspecialchars($table['represent'])); ?></td> <td><?php print(htmlspecialchars($table['representday'])); ?></td> <td><?php $recordSet2 = mysql_query('SELECT * FROM report'); $report = mysql_fetch_assoc($recordSet2); if ($table['lessonname'] == $report['lessonname'] && $table['name'] == $report['exercisename']) { if(eregi($member['name'], $report['upfile'])) { echo "○"; }else { echo "×"; } } ?></td> </tr> <?php } ?> </table>

    • ベストアンサー
    • PHP
  • テーブルの情報が一部しか表示されません。(php)

    すべてのID分の提出状況を表示させたい("○"か"×")のですが、 id=1の提出状況しか表示されません。 >>CODE $recordSet2 = mysql_query('SELECT * FROM report'); <<CODE をwhileにいれてみたり試行錯誤してみたのですが、上手くいきません。 ご指摘よろしくお願い致します。 プログラム >>CODE <table width="70%"> <tr> <th scope="col"><bl>ID</bl></th> <th scope="col"><bl>教科名</bl></th> <th scope="col"><bl>課題名</bl></th> <th scope="col"><bl>担当教員</bl></th> <th scope="col"><bl>提出期限</bl></th> <th scope="col"><bl>再提出</bl></th> <th scope="col"><bl>再提出期限</bl></th> <th scope="col"><bl>提出状況</bl></th> </tr> <?php $recordSet = mysql_query('SELECT * FROM exercise ORDER BY id'); while ($table = mysql_fetch_assoc($recordSet)){ ?> <tr> <td><?php print(htmlspecialchars($table['id'])); ?></td> <td><?php print(htmlspecialchars($table['lessonname'])); ?></td> <td><?php print(htmlspecialchars($table['name'])); ?></td> <td><?php print(htmlspecialchars($table['teacher'])); ?></td> <td><?php print(htmlspecialchars($table['presentday'])); ?></td> <td><?php print(htmlspecialchars($table['represent'])); ?></td> <td><?php print(htmlspecialchars($table['representday'])); ?></td> <td><?php $recordSet2 = mysql_query('SELECT * FROM report'); $report = mysql_fetch_assoc($recordSet2); if ($table['lessonname'] == $report['lessonname'] && $table['name'] == $report['exercisename']) { if(eregi($member['name'], $report['upfile'])) { echo "○"; }else { echo "×"; } } ?></td> </tr> <?php } ?> </table> <<CODE

    • ベストアンサー
    • PHP
  • よくわかるPHPの教科書のエラー?について

    わからないところがあるので教えて下さい。 (コード) <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www. w3.org/TR/xhtmll/DTD/xhtmll- transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="ja" xml:lang="ja"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> <title>PHP入門</title> </head> <body> <?php require('dbconnect.php'); $page = $_REQUEST['page']; if($page =='') { $page =1; } $page = max($page, 1); //最終ページを取得する $sql ='SELECT COUNT(*) AS cnt FROM my_items'; $recordSet = mysqli_query($db, $sql); $table = mysqli_fetch_assoc($recordSet); $maxPage = ceil($table['cnt'] /5); $page = min($page, $maxPage); $start = ($page - 1) * 5; $recordSet = mysqli_query($db, 'SELECT m.name, i.* FROM makers m, my_items i WHERE m.id=i.maker_id ORDER BY id DESC LIMIT ' . $start . ',5'); ?> <p><a href="input.php">新しい商品を登録する。</a></p> <table width="100%"> <tr> <th scope="col">ID</th> <th scope="col">メーカー</th> <th scope="col">商品名</th> <th scope="col">価格</th> <th scope="col">編集・削除</th> </tr> <?php while($table = mysqli_fetch_assoc($recordSet)) { ?> <tr> <td><?php print(htmlspecialchars($table['id'])); ?></td> <td><?php print(htmlspecialchars($table['name'])); ?></td> <td><?php print(htmlspecialchars($table['item_name'])); ?></td> <td><?php print(htmlspecialchars($table['price'])); ?></td> <td><a href="update.php?id=<?php print(htmlspecialchars($table['id'])); ?>">編集</a> <a href="delete.php?id=<?php print(htmlspecialchars($table['id'])); ?>" onclick="return confirm('削除してもよろしいですか?');">削除</a> </td> </tr> <?php } ?> </table> <ul class="paging"> <?php if($page > 1) { ?> <li><a href="index.php?page=<?php print($page - 1); ?>">前のページへ </a></li> <?php } else { ?> <li>前のページへ</li> <?php } ?> <?php if($page < $maxPage) { ?> <li><a href="index.php?page=<?php print($page + 1); ?>">次のページへ </a></li> <?php } else { ?> <li>次のページへ</li> <?php } ?> </ul> </body> </html> 参考書?はよくわかるPHPの教科書5.5対応なのですが、一番初めにこのファイルを開くと Notice: Undefined index: page in C:\xampp\htdocs\shop\index.php on line 14っとエラー?が出ます。 次のページ、前のページを押すとエラー?は消えるのですが、とっても気になります。 なるべくなら、エラーを非表示にせずにプログラム内で問題を解決したいのですが・・・ 初心者なのでどうして良いかわかりません。 出来れば、とってもわかりやすい解決を出来ればお願いしたいです。(馬鹿なので・・・) よろしくお願いします。

    • ベストアンサー
    • PHP
  • 「未定義の変数」の定義について(PHP)

    ●質問の主旨 添付画像の左端に Notice: Undefined index: page in C:\xampp\htdocs\shop\index.php on line 3 ということで、未定義の変数ということでおしらせが出ています。 この表示を消すためにはどうすれば良いでしょうか? ご存知のかた、ご教示願います。 ●質問の補足 下記のコードで言えば、 $page =$_REQUEST['page']; のうち、pageが定義されていないことが、表示の原因である気がします。 しかし、どこをどう書き換えれば、表示が消えるのかが分かりません。 ●参考文献 たにぐちまこと「よくわかるPHPの教科書」(P210)の index.phpファイル ●開発環境 windows8 xammp1.8.1 ●コード <?php require('dbconnect.php'); $page =$_REQUEST['page']; if ($page == '') { $page = 1; } $page = max($page, 1); //最終ページを取得する $sql = 'SELECT COUNT(*) AS cnt FROM my_items'; $recordSet = mysql_query($sql); $table = mysql_fetch_assoc($recordSet); $maxPage = ceil($table['cnt'] / 5); $page = min($page, $maxPage); $start = ($page - 1) * 5; $recordSet = mysql_query('SELECT m.name, i. * FROM makers m, my_items i WHERE m.id=i.maker_id ORDER BY id DESC LIMIT ' . $start .',5'); ?> <!DOCTYPE html> <html lang="ja"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <link rel="stylesheet" type="text/css" href="style.css" /> <title>Webシステムをつくる</title> </head> <body> <div id="wrap"> <div id="head"> <h1>トップページ</h1> </div> <div id="content"> <p style="margin-top: 20px"> <table width="100%"> <tr> <th scope="col">ID</th> <th scope="col">メーカー</th> <th scope="col">商品名</th> <th scope="col">価格</th> </tr> <?php while ($table = mysql_fetch_assoc($recordSet)) { ?> <tr> <td><?php print(htmlspecialchars($table['id'])); ?></td> <td><?php print(htmlspecialchars($table['name'])); ?></td> <td><?php print(htmlspecialchars($table['item_name'])); ?></td> <td><?php print(htmlspecialchars($table['price'])); ?></td> </tr> <?php } ?> </table> <ul class="paging"> <?php if ($page > 1) { ?> <li><a href="index.php?page=<?php print($page - 1); ?>">前のページへ</a></li> <?php } else { ?> <li>前のページへ</li> <?php } ?> <?php if ($page < $maxPage) { ?> <li><a href="index.php?page=<?php print($page + 1); ?>">次のページへ</a></li> <?php } else { ?> <li>次のページへ</li> <?php } ?> </ul> </p> </div> <div id="foot"> <p><img src="images/txt_copyright.png" width="136" height="15" alt="(C) H2O Space. MYCOM" /></p> </div> </div> </body> </html>

    • ベストアンサー
    • PHP
  • 同じコードを使っているのにエラーはなぜ?

    ●質問の意味 先日、似たような質問をいたしました。 「未定義の変数」の定義について(PHP) http://okwave.jp/qa/q8060182.html それと同じようなコードを書いていますが、 エラーが出ます。なぜでしょうか? ご存知の方、よろしくお願いします。 ●質問の補足 下記のコードの3行目 $page = isset($_GET['page']) ? intval($_GET['page']) : 1; についてエラーが出ています。 コメントアウトしている //$page =$_REQUEST['page']; は、参考文献の方のコードですがこちらでもエラーが出ます。 ●参考文献 たにぐちまこと「よくわかるPHPの教科書」(P215)の update.phpファイル ●開発環境 windows8 xammp1.8.1 ●コード(update.php) <?php require('dbconnect.php'); //$page =$_REQUEST['page']; $page = isset($_GET['page']) ? intval($_GET['page']) : 1; if ($page == '') { $page = 1; } $page = max($page, 1); //最終ページを取得する $sql = 'SELECT COUNT(*) AS cnt FROM my_items'; $recordSet = mysql_query($sql); $table = mysql_fetch_assoc($recordSet); $maxPage = ceil($table['cnt'] / 5); $page = min($page, $maxPage); $start = ($page - 1) * 5; $recordSet = mysql_query('SELECT m.name, i. * FROM makers m, my_items i WHERE m.id=i.maker_id ORDER BY id DESC LIMIT ' . $start .',5'); ?> <!DOCTYPE html> <html lang="ja"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <link rel="stylesheet" type="text/css" href="style.css" /> <title>Webシステムをつくる</title> </head> <body> <div id="wrap"> <div id="head"> <h1>トップページ</h1> </div> <div id="content"> <p style="margin-top: 20px"> <table width="100%"> <tr> <th scope="col">ID</th> <th scope="col">メーカー</th> <th scope="col">商品名</th> <th scope="col">価格</th> </tr> <?php while ($table = mysql_fetch_assoc($recordSet)) { ?> <tr> <td><?php print(htmlspecialchars($table['id'])); ?></td> <td><?php print(htmlspecialchars($table['name'])); ?></td> <td><?php print(htmlspecialchars($table['item_name'])); ?></td> <td><?php print(htmlspecialchars($table['price'])); ?></td> </tr> <?php } ?> </table> <ul class="paging"> <?php if ($page > 1) { ?> <li><a href="index.php?page=<?php print($page - 1); ?>">前のページへ</a></li> <?php } else { ?> <li>前のページへ</li> <?php } ?> <?php if ($page < $maxPage) { ?> <li><a href="index.php?page=<?php print($page + 1); ?>">次のページへ</a></li> <?php } else { ?> <li>次のページへ</li> <?php } ?> </ul> </p> </div> <div id="foot"> <p><img src="images/txt_copyright.png" width="136" height="15" alt="(C) H2O Space. MYCOM" /></p> </div> </div> </body> </html>

    • ベストアンサー
    • PHP
  • PHPでtableをループさせたい!

    【急募!】PHPでMysqlから取り出した値をHTMLのtableで出力したい。 うまくいかなくて困ってます。 今回で2度目の質問となります。今回も急いでおります。 現在、プログラムの勉強をして半年近くになります。本日3/3までに作成を完了しなければならず困っております。 何日か掛けて調べたのですが、まだまだ勉強不足の為に理解が出来ませんでした。 PHPで作成をしております。データベースから取り出した値をHTMLで作成したtableに出力後、tableをデータベースに入っている数だけループさせたいです。※イメージ画像あり おそらくwhile分でループさせれば良いとういうのは理解できるのですが、テーブル自体を増やすやりかたかが解りません。 while(データーベースの値をループさせてひとつずつ出力する。,テーブルも同じ数出力する) 全部取り出したら break で抜ける......となると思うのですが、書き方か解りません。 mysql_fetch_arrayというものもあるようですがまだ理解ができません。 答え合わせになってしまうのが恐縮でございますが、答え合わせのコードを頂けましたら嬉しいです。 まだ理解が浅いため、質問の内容に理解が出来なければ、ご連絡を頂きましたら改善改良をします。 お恥ずかしいですが、ソースを乗せさせて頂きますので宜しくお願い致します。 <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <link href="css/style2.css" rel="stylesheet" type="text/css"> <title>管理画面</title> </head> <body> <div id="main"> <?php $dsn='mysql:dbname=motorlinks;host=localhost'; $user='root'; $password=''; $dbh=new PDO($dsn,$user,$password); $dbh->query('SET NAMES utf8'); $sql='SELECT code,gazou,name,shiyo,price,shiharai,first,sample,comment FROM pone WHERE 1'; $stmt=$dbh->prepare($sql); $stmt->execute(); print'製品一覧<br><br>'; print'<form method="post"action="pone_branch.php">'; ?> <?php while(true) { $rec=$stmt->fetch(PDO::FETCH_ASSOC); if($rec==false) { break; } print $rec['gazou']; print $rec['name']; print $rec['shiyo']; print $rec['price'].'円'; print $rec['shiharai']; print $rec['first']; print $rec['sample']; print $rec['comment']; print'<br>'; }?> <table width="800" border="1" cellpadding="0"> <?php print'<input type="radio"name="ponecode"value="'.$rec['code'].'">'; ?> <tr> <th colspan="2" rowspan="4" scope="col"><?php '<img src="gazou/burank.jpg" width="200" height="150" alt=""/>'; ?></th> <th width="162" height="4" scope="col">Product Name</th> <th width="162" height="4" scope="col">Specification</th> <th width="162" height="4" scope="col">Price</th> <th width="162" height="4" scope="col">Payment</th> </tr> <tr> <td height="63">&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> </tr> <tr> <th width="162" height="4" scope="col">First Order</th> <th width="162" height="4" scope="col">Sample</th> <th width="162" height="4" scope="col">Comment</th> <th width="162" height="4" scope="col">Contact</th> </tr> <tr> <td height=63">&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> </tr> </table> <?php print'<br>'; print'<input type="submit" name="disp" value="参照">'; print'<input type="submit" name="add" value="追加">'; print'<input type="submit" name="edit" value="修正">'; print'<input type="submit" name="delete" value="削除">'; print'</form>'; ?> <br> <a href="index_mo.html">トップメニューへ</a><br> </form> </div> </body> </html>

    • ベストアンサー
    • PHP
  • PHP、mysql、html 表のセル内の文字列の長さによってセル幅が変わる。

    こんばんは。PHP・mysql共に初心者の者です。どなたかお知恵をお貸しください。以下に環境を記します。 Windows2000/sp5 Apache/2.0.55 PHP/5.0.5 MySQL 5.0 mysqlから取り出したレコードを<table>で表形式にて表示する物を作っておりますが、ヘッダ部と表示部を別々に<table>タグで囲んであるせいか、セルの大きさの整合性が取れなくなりました。 表示部では、データの文字列の長さによってそれぞれのセルの大きさが違っている状態です。ヘッダ部と表示部をまとめて<table>タグで囲んだり等、色々と試行錯誤しましたが、行き詰まりました。何か良いアイデアはないものでしょうか? 長くなりますのでwhile文からのソースを晒します。 while ($col = mysql_fetch_array($rst)) { $body .=<<<eof <table> <tr> <td NOWRAP><input type="checkbox" name="chk[]" value="{$col["id2"]}"></td> <td NOWRAP>{$col["id"]}</td> <td NOWRAP><a href='/meibo_view.php?id={$col["id"]}'>$col[name]</a></td> <td NOWRAP>{$col["age"]}</td> </tr> </table> eof; } $body = <<<eof <table> <tr> <th NOWRAP>詳細</th> <th NOWRAP>ID</th> <th NOWRAP>氏名</th> <th NOWRAP>年齢</th> </tr> {$body} </table> eof; mysql_free_result($rst); $con = mysql_close($con); ?>

    • 締切済み
    • PHP
  • php + mysql でフォーム作成時のエラー

    データベースから取り出したデータをラジオボタンで選択し、それをデータベース(別のテーブル)に追加させる機能を作りたいです。 非常に初歩的なことだとは思うのですがご教授ください。 MySQL 4.0.27 PHP 5.2.11 <FORM ACTION="cone3.php" METHOD="post"> <?php $srv = ""; // サーバー名 $id = ""; // ユーザーID $passwd = "; // パスワード $dbn = ""; // データベース名 $sql = "SELECT code, lname, lecturer, kind, gradetype FROM Lecture"; // SQL文 // データベースに接続する $db = mysql_connect($srv,$id,$passwd); mysql_select_db($dbn,$db); $rs = mysql_query($sql,$db); //--- テーブルのレイアウト --- 開始 -----------------------> print("<TABLE><TR>"); print("<TR><th> </th><th>講義名</th><th>教員</th><th>科目区分</th><th>配当学年</th></tr>"); while($row = mysql_fetch_array($rs)) { print '<tr><td><input type="radio" name="regist" value="$row['code']"></td>'; print '<td>' . $row['lname'] . '</td>'; print '<td>' . $row['lecturer'] . '</td>'; print '<td>' . $row['kind'] . '</td>'; print '<td>' . $row['gradetype'] . '</td>'; print '</tr>'; print ("</TR>"); } print("</TABLE>"); print_r($_POST); echo "<br />\n"; mysql_free_result($rs); mysql_close($db); //--- 終了 ---> ?> <input type="submit" name="submit" value="送信"> </form> 以上のようなソースでラジオボタンで配列の$row[code]の値を送りたいんですがうまくいきません。 よろしくお願いします。

    • ベストアンサー
    • PHP
  • PHPでMySQLにデーターを追加するところで壁に当たってしまいました

    PHPでMySQLにデーターを追加するところで壁に当たってしまいました。 PHP5.3&MYSQL5.1 1.フォームへ入力 2.確認画面 3.MySQLへデーター追加 1.form <html> <head><title></title></head> <body> <form method="post" action="conf.php"> <table> <tr><th>番号</th><td><input type="text" name="id" /></td></tr> <tr><th>タイトル</th><td><input type="text" name="title" /></td></tr> <tr><th>テキスト</th><td><textarea name="cont" cols="40" rows="5" /></textarea></tr> <tr><th>日付け</th><td><input type="text" name="update" size="10" /></td></tr> </table> <input type="submit" value="送信" /><input type="reset" value="リセット" /> </form> </body> </html> 2.確認画面 <html> <head><title></title></head> <body> <table> <tr><th>番号</th><td><?php echo htmlspecialchars($_POST["id"]) ?></td></tr> <tr><th>タイトル</th><td><?php echo htmlspecialchars($_POST["title"]) ?></td></tr> <tr><th>テキスト</th><td><?php echo htmlspecialchars($_POST["cont"]) ?></td></tr> <tr><th>日付け</th><td><?php echo htmlspecialchars($_POST["update"]) ?></td></tr> </table> <form method="post" action="upld.php"> <input type="hidden" name="did" value="<?php echo htmlspecialchars($_POST["id"]) ?>" /> <input type="hidden" name="title" value="<?php echo htmlspecialchars($_POST["title"]) ?>" /> <input type="hidden" name="cont" value="<?php echo htmlspecialchars($_POST["cont"]) ?>" /> <input type="hidden" name="update" value="<?php echo htmlspecialchars($_POST["update"]) ?>" /> <input type="submit" value="登録" /> </form> </body> </html> 3.MySQLへデーター追加 <?php $Con = mysql_connect("localhost","root",""); if ($Con == false) {dir ("MySQLの接続に失敗。");} if (!mysql_select_db("phpdata",$Con)) {dir ("データーベース接続に失敗。");} $sql = "insert into daimoku(id,title,cont,update) values('".$_POST["id"]."','".$_POST["title"]."','".$_POST["cont"]."','".$_POST["update"]."')";//SQL文の作成 $res = mysql_query($sql) or die(mysql_error());//クエリの実行 mysql_close($Con);//切断 ?> <html> <head> <title></title> </head> <body> <p>ご登録ありがとうございました。</p> <a href="01.php">戻る</a> </body> 以上のコードでデーターの追加が出来ません。 どなたか教えていただけないでしょうか?

    • ベストアンサー
    • PHP
  • mysqliについて

    PHP初心者です PHP 5.2.5 MySQL 5.1.22 レンタルサーバーのphpのバージョンが php5.2.5ではpdoがバグで使えないらしいのでmysqliを使おうとしています。PHP 5.2.5でもmysqliはバグありますか? mysqliでMYSQLに接続するにはどうすればいいのでしょうか? いままではこんな感じでしたがmysqliにするとどんなコードになるのでしょうか? $link=mysql_connect('localhost', 'user', 'pass')or die(mysql_error()); mysql_select_db(user'); mysql_query('SET NAMES UTF8'); $start=1; $hyouji=10; $recordSet = mysql_query(sprintf('SELECT * FROM hoge2 ORDER BY id LIMIT %d, %d' , ',$start,$hyouji)); <?php while ($table = mysql_fetch_assoc($recordSet)) { ?> <tr> <td><?php print($table['id']); ?></td> <td><?php print($table['name']); ?></td> </tr> <?php } ?>

    • ベストアンサー
    • PHP

専門家に質問してみよう