简体   繁体   English

用PHP恢复MySQL数据的错误

[英]Errror recovering mysql data with php

i had installed freestyle extension in joomla (to allow php code in articles) im trying to access to a database in mysql with the next code 我已经在joomla中安装了freestyle扩展(以允许文章中的php代码),我尝试使用下一个代码访问mysql中的数据库

try {
    $conn = new PDO("mysql:host=$host;dbname=$dbname", $username, $password)

     $sql = "SELECT id, nombre, edad
            FROM Prueba";

    $q = $conn->prepare($sql);
    $q->execute(array('%son'));
    $q->setFetchMode(PDO::FETCH_ASSOC);

 while ($r = $q->fetch()) {
        echo sprintf('%s <br/>', $r['nombre']);
    }
} catch (PDOException $pe) {
    die("Could not connect to the database $dbname :" . $pe->getMessage());
}
?>

And i get this error in the article and i dont know why this is happening 而且我在文章中得到这个错误,我不知道为什么会这样

Parse error: syntax error, unexpected T_VARIABLE on line 13 解析错误:语法错误,第13行出现意外的T_VARIABLE

$conn = new PDO("mysql:host=$host;dbname=$dbname", $username, $password)

should be 应该

$conn = new PDO("mysql:host=$host;dbname=$dbname", $username, $password);

(You're missing a ';') (您缺少“;”)

Also I think your code isn't going to work exactly as planned since your SQL has no variables but you attempt to pass one to $q->execute() but I'm sure you can sort out what you're trying to do yourself... 另外我认为您的代码无法按计划正常工作,因为您的SQL没有变量,但是您尝试将其传递给$q->execute()但是我敢肯定您可以弄清楚自己要做什么你自己...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM