$today = date('Y-m-d');
$result = mysqli_query($con,"SELECT * FROM calendar where live_date>='".$today."' order by live_date");
วันอาทิตย์ที่ 13 เมษายน พ.ศ. 2557
วันพฤหัสบดีที่ 27 กุมภาพันธ์ พ.ศ. 2557
install phpmyadmin
ที่ตัว raspberry pi
apt-get install phpmyadmin
เลือก apache2
config = yes
nano /etc/phpmyadmin/apache.conf
ไปที่บรรทัดล่างสุด แล้วเพิ่มข้อความนี้
Include /etc/init.d/apache2 restart
เมื่อเสร็จแล้ว ให้เข้า ip address ของ raspberry pi แล้วตามด้วย /phpmyadmin
ก็จะเจอหน้าตาแบบนี้
ก็ให้ใส่ user name และ password ที่เราตั้งไว้ เป็นอันเรียบร้อย เราก็จะสามารถเข้าไปดู database ที่อยู่ในตัวของ raspberry pi ได้ โดยผ่านหน้า web browser ได้
ที่มา
http://www.dingleberrypi.com/2012/09/tutorial-install-phpmyadmin-on-your-raspberry-pi/
apt-get install phpmyadmin
เลือก apache2
config = yes
nano /etc/phpmyadmin/apache.conf
ไปที่บรรทัดล่างสุด แล้วเพิ่มข้อความนี้
Include /etc/init.d/apache2 restart
เมื่อเสร็จแล้ว ให้เข้า ip address ของ raspberry pi แล้วตามด้วย /phpmyadmin
ก็จะเจอหน้าตาแบบนี้
ก็ให้ใส่ user name และ password ที่เราตั้งไว้ เป็นอันเรียบร้อย เราก็จะสามารถเข้าไปดู database ที่อยู่ในตัวของ raspberry pi ได้ โดยผ่านหน้า web browser ได้
ที่มา
http://www.dingleberrypi.com/2012/09/tutorial-install-phpmyadmin-on-your-raspberry-pi/
วันอาทิตย์ที่ 2 กุมภาพันธ์ พ.ศ. 2557
PHP แสดงวันที่
แสดงวัน โดยใช้ php มีหลายรูปแบบ
<?php// Assuming today is March 10th, 2001, 5:16:18 pm, and that we are in the
// Mountain Standard Time (MST) Time Zone$today = date("F j, Y, g:i a"); // March 10, 2001, 5:16 pm $today = date("m.d.y"); // 03.10.01 $today = date("j, n, Y"); // 10, 3, 2001 $today = date("Ymd"); // 20010310 $today = date('h-i-s, j-m-y, it is w Day'); // 05-16-18, 10-03-01, 1631 1618 6 Satpm01$today = date('\i\t \i\s \t\h\e jS \d\a\y.'); // it is the 10th day.$today = date("D M j G:i:s T Y"); // Sat Mar 10 17:16:18 MST 2001$today = date('H:m:s \m \i\s\ \m\o\n\t\h'); // 17:03:18 m is month $today = date("H:i:s"); // 17:16:18 $today = date("Y-m-d H:i:s"); // 2001-03-10 17:16:18 (the MySQL DATETIME format) ?>
ตัวอย่าง การแสดงผลเป็นวันที่ dd-mm-yyyy<?php
$con=mysqli_connect("localhost","root","1","test");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM my_table");while($row = mysqli_fetch_array($result))
{ echo date('d-m-Y',strtotime($row['live_date']));
echo date('l', strtotime( $row['live_date']));
}mysqli_close($con);
?>
ที่มาhttp://th1.php.net/manual/en/function.date.php
PHP connect database
php connect to database
mysqli_connect(host,username,password,dbname);
example
<?php
// Create connection
$con=mysqli_connect("localhost","root","abc123","my_db");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM table_name");
while($row = mysqli_fetch_array($result))
{
echo $row['column1'];
echo $row['column2'];
}
mysqli_close($con);
?>
mysqli_connect(host,username,password,dbname);
example
<?php
// Create connection
$con=mysqli_connect("localhost","root","abc123","my_db");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM table_name");
while($row = mysqli_fetch_array($result))
{
echo $row['column1'];
echo $row['column2'];
}
mysqli_close($con);
?>
PHP ส่งค่าตัวแหร ไปหน้าอื่น
สมมติว่าเราต้องการส่งค่าจาก file1.php ไปยัง file2.php
ใน file1.php เราก็ต้องใส่ method get ลงไปก่อน
<td>
<form action="search.php" method="get" target="_blank";>
<input type="text" name="search" style="border:0">
<td>
<input type="submit" value="Search" style="border:0;">
</td>
</form>
</td>
จากนั้นใน file2.php
<?php
$var_value = $_GET['search'];
echo 'Hello ' . $var_value . '!';
?>
เท่านี้ก็เรียบร้อยโรงเรียนจีน
ที่มา
http://stackoverflow.com/questions/871858/php-pass-variable-to-next-page
วันอาทิตย์ที่ 26 มกราคม พ.ศ. 2557
mysql
ที่มา
http://www.pantz.org/software/mysql/mysqlcommands.html
http://www.tutorialspoint.com/mysql/index.htm --> ดีมาก
http://www.siteground.com/tutorials/php-mysql/connect-mysql/
http://www.unzeen.com/article/2173/
http://www.unzeen.com/article/2693/
ก่อนอื่นเราต้อง login user อย่างแรกครับ
ด้วยการเปิด terminal แล้วพิมพ์
mysql -u root -p
show databases; จะแสดงชื่อ database ออกมาว่ามีอะไรบ้าง
การ login database
use xxx; โดย xxx คือชื่อของ database ที่ต้องการเข้าใช้
show tables; แสดง table ว่ามี table อะไรบ้าง
drop database xxx; ลบ database
drop table xxx; ลบ table
select * from xxx where xxx;
เพิ่มข้อมูล
insert into table_name (field_name1,field_name2,field_name3) value ('x','y','z');
flush privileges;
ถ้าลืม password
# mysqld_safe --skip-grant-tables &
# mysql -u root
mysql> use mysql;
mysql> update user set password=PASSWORD("newrootpassword") where User='root';
mysql> flush privileges;
mysql> quit
# /etc/init.d/mysql stop
# /etc/init.d/mysql start
สร้าง table ใหม่
http://www.pantz.org/software/mysql/mysqlcommands.html
http://www.tutorialspoint.com/mysql/index.htm --> ดีมาก
http://www.siteground.com/tutorials/php-mysql/connect-mysql/
http://www.unzeen.com/article/2173/
http://www.unzeen.com/article/2693/
ก่อนอื่นเราต้อง login user อย่างแรกครับ
ด้วยการเปิด terminal แล้วพิมพ์
mysql -u root -p
show databases; จะแสดงชื่อ database ออกมาว่ามีอะไรบ้าง
การ login database
use xxx; โดย xxx คือชื่อของ database ที่ต้องการเข้าใช้
show tables; แสดง table ว่ามี table อะไรบ้าง
drop database xxx; ลบ database
drop table xxx; ลบ table
select * from xxx where xxx;
เพิ่มข้อมูล
insert into table_name (field_name1,field_name2,field_name3) value ('x','y','z');
flush privileges;
ถ้าลืม password
Recover a MySQL root password. Stop the MySQL server process. Start again with no grant tables. Login to MySQL as root. Set new password. Exit MySQL and restart MySQL server.
# /etc/init.d/mysql stop# mysqld_safe --skip-grant-tables &
# mysql -u root
mysql> use mysql;
mysql> update user set password=PASSWORD("newrootpassword") where User='root';
mysql> flush privileges;
mysql> quit
# /etc/init.d/mysql stop
# /etc/init.d/mysql start
สร้าง table ใหม่
CREATE TABLE table_name (column_name column_type,...);
ตัวอย่าง type -> int, varchar(10)
ตัวอย่างเช่น
create table Artist(ArtistID int not null auto_increment, ArtistName varchar(30) not null,Tel int, JoinDate date, primary key (ArtistID));
โชว์ column จาก table
show columns from table_name;
เพิ่มข้อมูลใหม่
INSERT INTO table_name ( field1, field2,...fieldN ) VALUES ( value1, value2,...valueN );
แก้ไขข้อมูล
UPDATE table_name SET field1=new-value1, field2=new-value2 [WHERE Clause]
แก้ไข type ของ column
ALTER TABLE tablename MODIFY columnname INTEGER;
เพิ่ม column ใหม่
alter table table_name add column_name type;
ALTER TABLE contacts ADD email VARCHAR(60) FIRST;
ALTER TABLE contacts ADD email VARCHAR(60) FIRST;
วันเสาร์ที่ 25 มกราคม พ.ศ. 2557
install php, apache and apache
setup raspberry pi
sudo dpkg-reconfigure tzdata
sudo apt-get update
sudo apt-get upgradekeep firmware up to date
sudo apt-get install ca-certificates
sudo apt-get install git-coresudo
wget http://goo.gl/1BOfJ -O /usr/bin/rpi-update && sudo chmod +x /usr/bin/rpi-updatesudo rpi-updatesudo shutdown -r now
setup SSH
connect to raspberry pi by ssh
ssh pi@192.168.0.4
install php and apache
sudo apt-get install apache2 php5 libapache2-mod-php5
if get installation error, run
sudo groupadd www-datasudo usermod -g www-data www-datarestart service
sudo service apache2 restart
Now enter the I.P. address of your Raspberry Pi into your web browser, and you should see a simple page that says "It Works!"
install mysql
sudo apt-get install mysql-server mysql-client php5-mysqlinstall ftp
sudo chown -R pi /var/www
sudo apt-get install vsftpd
configure ftp
sudo nano /etc/vsftpd.confChange anonymous_enable=YES toanonymous_enable=NO, Uncomment local_enable=YES and write_enable=YES, then go to the bottom of the file and add force_dot_files=YES. Now save and exit the file.
restart vsftp
sudo service vsftpd restart
sudo passwd rootLog out of your SSH session, and log back in as root. (You MUST do this)
Edit the password configuration file:
nano /etc/passwd
Find the line pi:x;1000:1000:Raspberry Pi User,,,:home/pi:/bin/bash and add a # sign to the beginning of it. Now save and exit the file.
- NOTE: This step has been known to cause errors, and lock people out of their Raspberry Pi. After saving the file, open a new SSH window and try to login as pi. If you get an access denied message, remove the # sign in front of: pi:x;1000:1000:Raspberry Pi User,,,:home/pi:/bin/bash
add the user pi as mod
usermod -d /var/www pi
Now exit your SSH session, and log back in as pi, then grant mod rights toroot.
sudo usermod -L root
Now exit. Your server should be up and running. You can transfer files through FTP by using your servers IP, and connecting through port 21.
ที่มา http://www.wikihow.com/Make-a-Raspberry-Pi-Web-Server
สมัครสมาชิก:
บทความ (Atom)


