PHP學習筆記

架設PHP環境 on Windows

1. 安裝EasyPHP

http://www.easyphp.org/

2. 安裝PEAR

直接執行 \php\go-pear.bat

如果是自己手動安裝PHP的話,在DOS模式下打:

pear install PEAR-1.7.2
3. 安裝PEAR Extension

DB Extension,在DOS模式下打:

pear install DB-1.7.13
4. 修改 \conf_files\php.ini 設定

include_path = “.;${path}\php\PEAR

5. 其它

查詢PEAR Extension,清單在DOS模式下打:

pear list

DB連線操作

// host, username, password, dbname
$db = mysqli_connect('localhost', 'user', '1234', 'phptest');
if( !$db ) {
  die("Can't connect: " . mysqli_connect_error());
}

$sql = "select id from images limit 5"; <span class="comment">// sql query語法</span>
$q = mysqli_query($db, $sql);
while($r = mysqli_fetch_row($q)) { <span class="comment">// 將query出來的資料以Array的方式傳回</span>
  echo $r[0] . "\r\n";
}