php查询mysql数据库prepare语句用法,使用prepare可以优化数据库查询
$mysql = new mysqli('localhost', 'root', 'root', 'databaseName') or die('There was a problem connecting to the database'); $stmt = $mysql->prepare('SELECT id, title, content FROM tableName'); $stmt->execute(); $stmt->bind_result($id, $title, $content); while($row = $stmt->fetch()) : ?> <h2> <!--?php echo $title; ?--></h2> <!--?php echo $content; ?--> <!--?php endwhile; ?-->