PHP を使った簡単なサンプルプログラムを実際にいくつか作成してみます。
PHPにはMySQLを利用するための関数が、あらかじめ用意されています。実はデータベースの基本的な操作は7つの関数だけで行なえます。 今回はその内の6つについて解説します。もちろん便利なMySQL関数はたくさんありますが、最初に覚えるのはこれだけで十分です。 しかも関数は使うパターンが決まっているので、一度基本的なプログラムを作ればあとは流用することができます。 またMySQLのデフォルトでは、パスワードが無い「root」ユーザーが設定されているので、これを接続に使うことにします。 mysqlデータベースのuserテーブル 【1】sample100 フォルダを作成します。 【2】新たに select.php を作成します。 *「\」はWindowsではエンマークのことです。 保存先 C:\phpdev\www\test\sample100 ファイル名 select.php <?php $u
<?php $list = array( array("no"=>3, "cat"=>5, "body"=>"リンゴ"), array("no"=>2, "cat"=>4, "body"=>"みかん"), array("no"=>4, "cat"=>5, "body"=>"ナシ"), array("no"=>6, "cat"=>3, "body"=>"バナナ"), array("no"=>1, "cat"=>4, "body"=>"オレンジ") ); usort($list, create_function('$a, $b', 'return $a["cat"]-$b["cat"];')); print_r("<pre>"); print_r($list); print_r("</pre>"); ?>
正規表現をまとめてみる。 preg_match で使われる正規表現の書き方の前に まずは、 <検索対象文字列が1行か?それとも複数行か?> 文字列の中からパターンに合致する部分を探し出す場合、その文字列が1行(改行文字が1つ)なのか、複数行(改行文字が複数)なのかで、マッチ演算子を適切に指定。 preg_match("/パターン/", 調べる文字列); "/パターン/" //文字列の1行目のみを調べる "/パターン/g" //複数行を調べる "/パターン/s" //改行文字を無視し、1行とみなして調べる ついでに、 "/パターン/i" //文字列の大文字・小文字を区別しない "/パターン/is" //大文字・小文字を区別せず、1行とみなして調べる <基本> preg_match は、文字列中に現れた最初のパターンのみを検出。
C++のようにPHPにも「クラス」と「オブジェクト」と言う概念があります。クラスは、変数及びこれらの変数で動作する関数を1つに集めたもののことです。とりあえず例を見てみましょう。 <?php class sample_class { var $name = "Apple"; function print_fruits ( ) { print "テスト出力:" . $this -> name . "<br>\n"; } } $obj1 = new sample_class ( ); $obj2 = new sample_class ( ); $obj1 -> name = "Banana"; $obj1 -> print_fruits ( ); $obj2 -> print_fruits ( ); ?> ここではまず、sample_classと言う名のクラスが定義されています。その中身という
胡蝶蘭 奈良 ご質問があればお気軽に当店までお電話にてご連絡下さい。 あくまで目安とお考えください。 ・午前中・午後 ◎日曜・祝日、及び、一部地域では配達時間のご希望は承る事ができません。 」定期装花。 また、国宝や世界文化遺産に指定されている建造物や仏像が多く残されています。 成田花園 (神奈川県)の情報が更新されました。 12:00以降に送信していただいたご注文・・・・翌日発送(2~3日以降の到着)が可能です。 しかしながら、大事にしていることは、その農園の思いであると安永店長は語る。 (チューリップス) (愛知県)の情報が更新されました。 1万円以下のものもいろいろとありますが、お祝いとして贈るのならば1万円前後のものは最低と見ておいたほうが良いでしょうね。 ショップの方に相談し、ご提案されたのが、こちらのお花でした。 お誕生日・各種お祝いやプレゼント、お悔やみ、お供えなどのお花の贈
検索結果をPHPを使ってリストボックスに出すにはどうしたらよいでしょうか? イメージ的には http://jsajax.com/Articles/ListBox/339 のようなものの片方に、検索結果を入れたもの。 検索結果を選択し、対象になったものを隣のリストボックスに入れるというものを想定します。 リンク先にでもよいのでコード付きでよろしくお願いします。
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く