【发布时间】:2014-07-10 08:16:24
【问题描述】:
我需要为我的项目转换这个新的数据库连接并将数据库中的信息检索到旧的方式。我已经按照旧式方式 PHP 4.0 完成了连接,但我需要将此 PDO 连接代码用于旧数据库连接,因为我不熟悉如何使用旧数据库连接来使用和检索信息。 谢谢。
<?php
$pdo = new PDO('mysql:host=localhost;dbname=sitepoint', 'root', '*****');
$opts = $_POST['filterOpts'];
$qMarks = str_repeat('?,', count($opts) - 1) . '?';
$statement = $pdo->prepare("SELECT mobile_phone.id, name, model, price FROM mobile_phone INNER JOIN brand ON brand_id = brand.id WHERE name IN ($qMarks)");
$statement -> execute($opts);
$results = $statement -> fetchAll(PDO::FETCH_ASSOC);
$json = json_encode($results);
echo($json);
?>
我已经用旧的数据库连接尝试过这种方式,但它什么也没给我:
$opts = $_POST['filterOpts'];
$qMarks = str_repeat('?,', count($opts) - 1) . '?';
$statement = "SELECT mobile_phone.id, name, model, price FROM mobile_phone INNER JOIN brand ON brand_id = brand.id WHERE name IN ($qMarks)";
$statement1 = mysql_query($statement);
$results = mysql_fetch_assoc($statement1);
$json = json_encode($results);
echo($json);
【问题讨论】:
标签: mysql database-connection php4 php-5.4