質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
MySQL

MySQL(マイエスキューエル)は、TCX DataKonsultAB社などが開発するRDBMS(リレーショナルデータベースの管理システム)です。世界で最も人気の高いシステムで、オープンソースで開発されています。MySQLデータベースサーバは、高速性と信頼性があり、Linux、UNIX、Windowsなどの複数のプラットフォームで動作することができます。

mysqli

MySQLiはPHP5より導入されているデータベース用のドライバです。MySQL 4.1.3以降の新しい機能の利点をまとめています。

PHP

PHPは、Webサイト構築に特化して開発されたプログラミング言語です。大きな特徴のひとつは、HTMLに直接プログラムを埋め込むことができるという点です。PHPを用いることで、HTMLを動的コンテンツとして出力できます。HTMLがそのままブラウザに表示されるのに対し、PHPプログラムはサーバ側で実行された結果がブラウザに表示されるため、PHPスクリプトは「サーバサイドスクリプト」と呼ばれています。

Q&A

解決済

2回答

3734閲覧

PHPのエラー原因について

yutaishikawa_

総合スコア58

MySQL

MySQL(マイエスキューエル)は、TCX DataKonsultAB社などが開発するRDBMS(リレーショナルデータベースの管理システム)です。世界で最も人気の高いシステムで、オープンソースで開発されています。MySQLデータベースサーバは、高速性と信頼性があり、Linux、UNIX、Windowsなどの複数のプラットフォームで動作することができます。

mysqli

MySQLiはPHP5より導入されているデータベース用のドライバです。MySQL 4.1.3以降の新しい機能の利点をまとめています。

PHP

PHPは、Webサイト構築に特化して開発されたプログラミング言語です。大きな特徴のひとつは、HTMLに直接プログラムを埋め込むことができるという点です。PHPを用いることで、HTMLを動的コンテンツとして出力できます。HTMLがそのままブラウザに表示されるのに対し、PHPプログラムはサーバ側で実行された結果がブラウザに表示されるため、PHPスクリプトは「サーバサイドスクリプト」と呼ばれています。

0グッド

0クリップ

投稿2015/07/27 04:41

151行目の、class task の$this->mysqliの$this でパースエラーで弾かれてしまいます。
なにがいけないのでしょう。

calenderクラスを継承した task クラス でメソッドを作り、
task_doクラス でインスタンスを実行するつもりです。

PHP

1<?php 2// dbconnect.php 3class dbconnect { 4 //mysqli の インスタンス化 、接続 5 public function ConnectDb() { 6 $this->mysqli = new mysqli('localhost', '//////', '/////', '//////'); 7 if ($this->mysqli->connect_error){ 8 die('Connect Error (' . $this->mysqli->connect_errno . ') '. $this->mysqli->connect_error); 9 exit; 10 } 11 } 12} 13class Calender extends dbconnect { 14 protected $weeks = array(); 15 protected $timeStamp; 16 protected $task = ''; 17 protected $userData = array(); 18 protected $taskData = array(); 19 // mysqli の メソッド 20 public function __construct(){ 21 $dbconnect = new dbconnect(); 22 if ($this->timeStamp === false) { 23 $this->timeStamp = time(); 24 } 25 parent::dbconnect(); 26 } 27 // 現在の日時取得 (Y-m) 28 public function setTimeStamp(){ 29 $ym = isset($_GET['ym']) ? $_GET['ym'] : date("Y-m"); 30 $this->timeStamp = strtotime($ym . "-01"); 31 if ($this->timeStamp === false){ 32 $this->timeStamp = time(); 33 } 34 } 35 // 現在の日時取得 (Y-m-d) 36 public function setTimeStamp_day(){ 37 $ymd = isset($_GET['ymd']) ? $_GET['ymd'] : date("Y-m-d"); 38 $this->timeStamp = strtotime($ymd); 39 if ($this->timeStamp === false){ 40 $this->timeStamp = time(); 41 } 42 } 43 //空の処理を準備 44 public function task() { 45 return $this->task; 46 } 47 // カレンダー作成 48 public function query() { 49 // SQLで今月を取得する処理。先月の最終日と翌月の初日を不等号で期間を指定し、ANDで結ぶ。 50 $lastMonth = date("Y-m-d",strtotime("last day of - 1 month",$this->timeStamp)); 51 $nextMonth = date("Y-m-d",strtotime("first day of + 1 month",$this->timeStamp)); 52 $userData = array(); 53 // PHP->MySQLtable 54 $query = $this->mysqli->query("SELECT * FROM tasks WHERE task_date > '$lastMonth' AND task_date <'$nextMonth'"); 55 if (!$query) { 56 die('クエリーが失敗しました。'.mysql_error()); 57 } 58 // 連想配列で$rowを取得する 59 while($row = $query->fetch_assoc()) { 60 $userData[date('j',strtotime($row['task_date']))] = array( 61 // 各メンバ取得 62 'id' => $row['id'], 63 'title' => $row['title'], 64 'task_date' => $row['task_date'], 65 'place' => $row['place'], 66 'memo' => $row['memo'], 67 ); 68 } 69 // 最終日取得 70 $lastday = date("t",$this->timeStamp); 71 // 1日の曜日番号の数だけ空白を出力(7月だと3つ) 72 $youbi = date("w",mktime(0,0,0,date("m",$this->timeStamp),1,date("Y",$this->timeStamp))); 73 // $weekを初期化 74 $week = ""; 75 // 結合代入演算子を使用して、<td>を取得。一週間(0~6の<td>)が完成。 76 $week .= str_repeat('<td></td>', $youbi); 77 // 上記の定義で1日から31日までfor文で取得 78 for ($day = 1; $day <= $lastday; $day++ ,$youbi++) { 79 // もし$userData[日付]の変数が 空の場合 80 if (isset($userData[$day])) { 81 // リンクをはる 82 $week .= '<td><a href="taskListDay.php">'.$day.'</a></td>'; 83 }else{ 84 // リンクをはらない 85 $week .= '<td class="youbi_'.($youbi % 7).'">'.$day.'</td>'; 86 } 87 // $youbiを7で割った余り=6。(土曜日) 88 if ($youbi % 7 == 6 OR $day == $lastday) { 89 // もし 1 = $lastdayだったとき、<tb>に$youbiを7で割ったものを6で引く 90 if($day == $lastday) { 91 $week .= str_repeat('<td></td>', 6 - ($youbi % 7)); 92 } 93 // 結果、<tr>は$week 94 $this->weeks[]='<tr>' .$week .'</tr>'; 95 // $weekを初期化する 96 $week = ''; 97 } 98 // week""を初期化し続ける処理によってカレンダー型を形成。 99 } 100 } 101 public function Create(){ 102 // $pass = file_get_contents('edition.php'); 103 // PHP->MySQLtable 104 // タスクのパラメータを送れるようにする。 105 $view = $this->mysqli->query("SELECT * FROM tasks"); 106 // エラー処理 107 if (!$view) { 108 die('クエリーが失敗しました。'.mysql_error()); 109 } 110 while ($this->row = $view->fetch_assoc()) { 111 // 各メンバ取得 112 $id = $this->row['id']; 113 $title = $this->row['title']; 114 $task_date = $this->row['task_date']; 115 $place = $this->row['place']; 116 $memo = $this->row['memo']; 117 $this->task .= "<tr><td><a href='edition.php'>${title}</a></td><td>${task_date}</td><td>${place}</td><td>${memo}</td></tr>"; 118 } 119 } 120 // html記述用 121 public function h($s){ 122 return htmlspecialchars($s, ENT_QUOTES, 'UTF-8'); 123 } 124 // リストを取得 125 public function mysqli_result() { 126 return $this->mysqli; 127 } 128 // タスクを取得 129 // 一週を取得 130 public function getWeeks() { 131 return $this->weeks; 132 } 133 // 前月を取得 134 public function prev() { 135 return date("Y-m", mktime(0, 0, 0, date("m", $this->timeStamp)-1, 1, date("Y", $this->timeStamp))); 136 } 137 // 翌月を取得 138 public function next() { 139 return date("Y-m", mktime(0, 0, 0, date("m", $this->timeStamp)+1, 1, date("Y", $this->timeStamp))); 140 } 141 // 現在の日時を取得 (Y-m) 142 public function yearManth() { 143 return date("Y-m" ,$this->timeStamp); 144 } 145 public function getData(){ 146 return $this->userData; 147 } 148} 149class task extends Calender { 150 // メソッドを作成 151 protected $stmt = $this->mysqli; 152 protected $create = ""; 153 protected $enter = $stmt->extends; 154 155 public function setSQL() { 156 return $this->stmt; 157 } 158 public function create() { 159 return $this->create; 160 } 161 public function Enter() { 162 return $this->enter; 163 } 164} 165class task_do extends task { 166 // 引数を作成 167 protected $inSert = $this->stmt->prepare("INSERT INTO tasks (id,title,task_date,place,memo) VALUES (?,?,?,?,?)"); 168 protected $upDate = $this->stmt->prepare("DELETE FROM tasks where task_date = ?"); 169 protected $deLete = $this->stmt->prepare("UPDATE tasks set title = ? where id = '$id';"); 170 171 public function inSert() { 172 $this->create = "INSERT INTO tasks VALUES (NULL,'Stuttgart','DEU','Stuttagart',617000)"; 173 $this->stmt->query($this->create); 174 $this->enter; 175 } 176 public function upDate() { 177 $this->upDate; 178 $this->enter; 179 } 180 public function deLete() { 181 $this->deLete; 182 $this->enter; 183 } 184} 185 186 187?>

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答2

0

ベストアンサー

php

1class task extends Calender { 2 // メソッドを作成 3 protected $stmt = $this->mysqli; 4 protected $create = ""; 5 protected $enter = $stmt->extends; 6 7 : 8 9}

Parse error: syntax error, unexpected '$this' (T_VARIABLE) in php.php on line 151

そのような位置に $this を書くことはできません。

継承元の dbconnect クラスの $this->mysqli$stmt に入れたいということだと思いますが、
それなら次のようにコンストラクタを使う必要があります。

php

1class task extends Calender { 2 3 protected $stmt = $this->mysqli; 4 protected $create = ""; 5 protected $enter = $stmt->extends; 6 7 public function __construct() { 8 parent::__construct(); 9 $this->stmt = $this->mysqli; 10 $this->enter = $stmt->extends; 11 } 12 13 : 14 15}

task_do クラスも同様です。

php

1class task_do extends task { 2 3 protected $inSert; 4 protected $upDate; 5 protected $deLete; 6 7 public function __construct() { 8 parent::__construct(); 9 $this->inSert = $this->stmt->prepare("INSERT INTO tasks (id,title,task_date,place,memo) VALUES (?,?,?,?,?)"); 10 $this->upDate = $this->stmt->prepare("DELETE FROM tasks where task_date = ?"); 11 $this->deLete = $this->stmt->prepare("UPDATE tasks set title = ? where id = '$id';"); 12 } 13 14 : 15}

投稿2015/07/27 04:51

ngyuki

総合スコア4514

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

yutaishikawa_

2015/07/27 05:00

コメントありがとうございました。 無事解決致しました。
guest

0

クラス定義部では$thisは使えません。コンストラクタで初期化してください。

投稿2015/07/27 04:50

maisumakun

総合スコア145121

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

yutaishikawa_

2015/07/27 05:00

コメントありがとうございました。 無事解決致しました。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問