2014-01-25 22 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 –