ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
``` <?php $serverName = "11.1.111.111,11111"; $database = "XXX"; $username = 'XXX'; $password = 'XXX'; try { $conn = new PDO( "sqlsrv:server=$serverName;Database=$database", $username, $password, array( //PDO::ATTR_PERSISTENT => true, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION ) ); $query = " SELECT id, firstname, lastname FROM table_name WHERE firstname LIKE :firstname "; $stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_FWDONLY)); // $stmt->execute(array(':firstname' => '%John1%')); $firstname = 'John1'; $stmt->execute(array(':firstname' => '%'.$firstname.'%')); // set the resulting array to associative $result = $stmt->setFetchMode(PDO::FETCH_ASSOC); echo 'ID | Firstname | Lastname <br/>'; foreach($stmt->fetchAll() as $k=>$row) { echo $row['id']. ' | '.$row['firstname']. ' | '.$row['lastname']. '<br/>'; } } catch(PDOException $e) { die("Error connecting to SQL Server: " . $e->getMessage()); } $conn = null; ```