关于错误打印和#34;数组到字符串转换"有关stackoverflow的许多问题。但似乎没有人帮助我。
我试图用php执行sql select语句。这是我正在处理的一些内容:
public static function getNumCGS(){
require 'includes/vars.php';
$paramArray = array(":table" => "campground_data");
$query = Utilities::dbSelect("SELECT count(*) FROM :table","campgrounddata", $paramArray);
$r = $query->fetch();
return $r["count(*)"];
}
在Utilities.php中:
public static function dbSelect($selectStmt, $dbName, $params){
require_once "config/config.php";
$dbh = Config::connect($dbName);
$query = $dbh->prepare($selectStmt);
$query->setFetchMode(PDO::FETCH_ASSOC);
$query->execute($params) or die("DB Error: " . $query->errorInfo());
return $query;
}
在Config.php中:
public static function connect($dbname){
$dbserver = "localhost";
$dbuser = "sys";//just a local server
$dbpass = "test1";//just a local server
try {
$dbh = new PDO("mysql:host=$dbserver;dbname=$dbname", $dbuser, $dbpass, NULL);
return $dbh;
}
catch (PDOException $e) {
printf("ERROR: %s", $e->getMessage());
exit();
}
}
如果我调用getNumCGS()它告诉我在dbSelect函数中执行查询的行中有一个Array to string转换问题。
我一直在关注教科书中的一个例子,不知道这笔交易是什么。我看到的示例将数组传递到执行调用中。