標籤:
12345678910111213141516171819202122232425262728293031323334353637383940 |
<?php //串連參數 $host = "localhost" ; $user = "root" ; $pwd = "111111" ; $db = "test" ; $linkID =mysql_connect( $host , $user , $pwd ); //建立一個mysql串連 if (! $linkID ){ echo "<font color=‘red‘>unable to connect!</font>" ; } mysql_select_db( $db ) or die ( "unable to select database" ); //選擇一個資料庫 $SQL_SELECT_SYMBOLS = "select * from symbols" ; $result =mysql_query( $SQL_SELECT_SYMBOLS ) or die ( "error in query :$query. " .mysql_errno()); //執行SQL語句 if (mysql_num_rows( $result )>0){ echo ‘<table cellpadding="10" border="1">‘ ; echo ‘<tr><th>id</th><th>country</th><th>animal</th><th>cname</th></tr>‘ ; while ( $obj =mysql_fetch_object( $result )){ echo "<tr>" ; echo "<td>" . $obj ->id. "</td>" ; echo "<td>" . $obj ->country. "</td>" ; echo "<td>" . $obj ->animal. "</td>" ; echo "<td>" . $obj ->cname. "</td>" ; echo "</tr>" ; } echo "</table>" ; } else { echo "記錄未找到!" ; } mysql_free_result( $result ); //釋放記錄集所佔用的記憶體 mysql_close( $linkID ); //關閉資料庫連接 ?> |
php範例程式碼之使用mysql_fetch_object函數