PDO Database access WHERE title = $title

后端 未结 5 1448
無奈伤痛
無奈伤痛 2021-01-26 15:03

I\'m trying to learn to use PDO instead of MySQLi for database access and I\'m having trouble selecting data from the database. I want to use:

$STH = $DBH->qu         


        
5条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-26 15:50

    Take a look at PDO::prepare and PDOStatement::execute. The safest way to add user content to a query is to prepare a basic statement and bind the parameter to it. Example (note the question mark in the SQL statement):

    $STH = $DBH->query('SELECT * FROM ratings WHERE title=? ORDER BY date ASC');
    $STH->execute( array( $title ) );
    
    while( $row = $STH->fetch( PDO::FETCH_ASSOC ) );
    

提交回复
热议问题