2014-01-25 73 views

回答

2

PDO基本查詢(讀Migrate from the MySQL Extension to PDO

// Step 1: Establish a connection 
$db = new PDO("mysql:host=localhost;dbname=YourDB", "YourUser", "YourPassword"); 

// Step 2: Construct a query 
$query = "SELECT * FROM songs"; 

// Step 3: Send the query 
$qresult = $db->query($query); 

// Step 4: Iterate over the results 
while($row = $qresult->fetch(PDO::FETCH_ASSOC)) { 
    $result[] = $row; 
} 

// Step 5: Free used resources 
$qresult->closeCursor(); 
$db = null; 
+0

,因爲我做我得到不能使用類型PDOStatement對象的對象數組 – Aivaras

+0

@Aivaras使用http://www.php.net/manual/en/pdostatement.fetchall.php –