我有一个名为 $db 的对象,它在函数内部时会输出其他内容:
<?php
$dsn = "pgsql:"
. "host=ec2-54-217-239-27.eu-west-1.compute.amazonaws.com;"
. "dbname=dat08vv8oqt1j1;"
. "user=secret :);"
. "port=5432;"
. "sslmode=require;"
. "password=secret :)";
$db = new PDO($dsn);
$sql = "create table parent_children (
parent_path varchar,
child_path varchar,
primary key(parent_path,child_path),
foreign key (parent_path) references nodes (path),
foreign key (child_path) references nodes (path)
)";
/*$sq = $db ->query($sql);*/
print_r($db);
myqueries($sql, $db);
function myqueries($myobject, $sql){
print_r($myobject);
die();
};
第一次输出
PDO Object ( )
下一次:
create table parent_children ( parent_path varchar, child_path varchar, primary key(parent_path,child_path), foreign key (parent_path) references nodes (path), foreign key (child_path) references nodes (path) )
问题是这在函数内部不起作用:
$sq = $myobject ->query($sql);
但它在它之外起作用。