【正文】
所以,如果你有包管理器,那么就全搞定了。是否需要安裝包管理取決于你所使用的PHP版本。Mysql_fetch_assoc是使用MYSQL_ASSOC取結(jié)果的另外一種方式。它的參數(shù)是查詢結(jié)果和一個可選的結(jié)果綁定方式。結(jié)果行的所有列都保存在一個數(shù)組里,可以方便地進(jìn)行訪問。10 取結(jié)果并顯示 使用mysql_fetch_row從結(jié)果集中取出一行,它的用法如下: array mysql_fetch_row ( resource $result)。這里同樣有必要檢查mysql_query的返回值不是FALSE來確保查詢字符串和數(shù)據(jù)庫連接都沒有問題。你可以使用字符串連接操作符(.)來構(gòu)建查詢:。8 構(gòu)建SQL SELECT查詢 構(gòu)建SQL查詢非常容易就是將一個字符串賦值給變量。 // Select the database $db_select=mysql_select_db($db_database)。 重新啟動Apache,這樣MySQL的支持就會被打開了。6 診斷連接錯誤 你可能遇到的一個錯誤是: Fatal error: Call to undefined function mysql_connect( ) in C:\Program Files\ApacheSoftware Foundation\\htdocs\ on line 4。無論有多少個PHP文件訪問數(shù)據(jù)庫,你只需要修改這一個文件。它是通過普通的PHP代碼,而不是MySQL特定的PHP函數(shù)完成的。PHP為你建立數(shù)據(jù)庫的連接,你可以立即開始查詢并得到結(jié)果。3 使用PHP函數(shù)查詢數(shù)據(jù)庫 我們會介紹如何使用PHP連接MySQL數(shù)據(jù)庫。2 資源 當(dāng)連接到MySQL數(shù)據(jù)庫的時候,你會使用到兩個新的資源。你可以連接到MySQL或者其他支持的數(shù)據(jù)庫。同樣,一些MySQL特定的函數(shù)被更一般的、可以用在很多數(shù)據(jù)庫上的函數(shù)所替代。它將交互過程中無關(guān)緊要的部分屏蔽起來,讓你關(guān)注于重要的部分。PHP有標(biāo)準(zhǔn)的函數(shù)用來操作數(shù)據(jù)庫。}Again, it’s good practice to check for an error and display it every time you access the database. Now that you’ve got a good database connection, you’re ready to execute your SQL query.7 Building the SQL SELECT Query Building a SQL query is as easy as setting a variable to the string that is your SQL query. Of course, you’ll need to use a valid SQL query, or MySQL returns with an error when you execute the query. The variable name $query is used since the name reflects its purpose, but you can choose anything you’d like for a variable name. The SQL query in this example is SELECT * FROM books. Make sure there are two lines that are not mented out by a semicolon (。Getting PHP to Talk to MySQl Now that you’re fortable using the MySQL client tools to manipulate data in the database, you can begin using PHP to display and modify data from the database. PHP has standard functions for working with the , we’re going to discuss PHP’s builtin database functions. We’ll also show you how to use the The PHP Extension and Application Repository (PEAR) database functions that provide the ability to use the same functions to access any supported database. This type of flexibility es from a process called abstraction. In programming interfaces, abstraction simplifies a plex interaction. It works byremoving any nonessential parts of the interaction, allowing you to concentrate on the important parts. PEAR’s DB classes are one such database interface abstraction. The information you nee