|
|
|
ผมติด error unexpected 'use' (T_USE) C:\xampp\htdocs\prosever\index.php on line 7 ต้องการแสดงผลเป็นกราฟข้อมูลอ่าครับ |
|
|
|
|
|
|
|
พอดีผมใช้โปรแกรมของ slim firmwork ครับ เพื่อดึงค่าจากฐานข้อมูลนำมาแสดงผลเป็นกราฟแล้วมันขึ้น error แบบนี้ครับ
Parse error: syntax error, unexpected 'use' (T_USE) in C:\xampp\htdocs\prosever\index.php on line 7
อันนี้เป็นตัวโค้ดโปรแกรมครับ
Code (PHP)
<?php
{
require 'vendor/autoload.php';
//db
use Illuminate\Database\Capsule\Manager as Capsule;
$capsule = new Capsule;
$capsule->addConnection([
'driver' => 'mysql',
'host' => 'localhost',
'database' => 'energy_room',
'username' => 'root',
'password' => 'xxxxxx',
'charset' => 'utf8',
'collation' => 'utf8_general_ci',
'prefix' => '',
]);
// Set the event dispatcher used by Eloquent models... (optional)
// use Illuminate\Events\Dispatcher;
// use Illuminate\Container\Container;
// Make t his Capsule instance available globally via static methods... (optional)
//$capsule->setAsGlobal();
// Setup the Eloquent ORM... (optional; unless you've used setEventDispatcher())
$capsule->bootEloquent();
//link to mainsensor table
class light extends \Illuminate\Database\Eloquent\Model
{
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = ['lightin','lightout'];
public $timestamps = false;
}
//web page
$app= new \Slim\Slim();
//$app->get('/hello/:name',function($name){
// echo "hello, $name";
//});
$app->get('/input',function() use ($app, $capsule) {
$lightin = $app->request->get('lightin');
$lightout = $app->request->get('lightout');
// echo "$temp,$co2";
//write to database
$book = new \light(array(
'lightin' => $lightin,
'lightout' => $lightout
));
$book->save();
echo $book->toJson();
});
//graph
$app ->get('/graph',function() use($app, $capsule){
$graph = new ezcGraphLineChart();
$graph->title = 'lightsensor';
$x = [];
//read to database
$m = \light::all();
foreach ($m as $row) {
$x["lightin"][$row["date"]] = $row["lightin"];
$x["lightout"][$row["date"]] = $row["lightout"];
}
// echo $m->toJson();
// echo $m->temp;
// echo " ";
// echo $m->co2;''
foreach ( $x as $language => $data )
{
$graph->data[$language] = new ezcGraphArrayDataSet( $data );
}
$graph->render( 1280, 600, 'tutorial_line_chart.svg' );
echo "<img src='tutorial_line_chart.svg' />";
});
$app->run();
}
?>
Tag : PHP, MySQL, JavaScript, Windows
|
ประวัติการแก้ไข 2015-08-10 18:53:44 2015-08-10 18:54:48
|
|
|
|
|
Date :
2015-08-10 18:52:35 |
By :
sheepdanger |
View :
1108 |
Reply :
2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ใช้ PHP Version อะไรครับ PHP 5 >= 5.3.0 หรือเปล่าครับ
|
|
|
|
|
Date :
2015-08-11 09:14:08 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ใช้ php 5.6.8 ครับผม
|
|
|
|
|
Date :
2015-08-14 14:11:33 |
By :
sheepdanger |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 05
|