🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
MySQL PDO连接 ``` <?php $servername = "localhost"; $username = "root"; $password = "123456"; $dbname = "test"; try { $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password); $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $query = "SELECT id, title, content FROM data"; $stmt = $conn->prepare( $query ); $stmt->execute(); // set the resulting array to associative $result = $stmt->setFetchMode(PDO::FETCH_ASSOC); foreach( $stmt->fetchAll() as $k=>$v) { echo $v['id'].' | '.$v['title'].' | '.$v['content'].'<br/>'; } } catch(PDOException $e) { echo "Error: " . $e->getMessage(); } ```