No PostgreSQL link opened yet

邮差的信 提交于 2021-02-19 07:06:27

问题


I am completly new to databases and am trying to make a simple query to a postgreSQL database. Now the problem is that I don't really understand how things work. In my index.php I do

$dbconn = pg_connect("host=myhost port=5432 dbname=mydbname user=myuser password=mypass sslmode=require options='--client_encoding=UTF8'") or die('Could not connect: ' . pg_last_error());

And I am connected to the database. When I try to query it from another myphp.php

$query = "INSERT INTO public.account_recover_users VALUES ($mykey,$email,$name)";
$result = pg_query($query);

I get the error in the title description. What is the proper way to connect to the database so that I can access it from other files than index.php as well?

P.S. $mykey,$email,$name are 3 variables containing a key (randomly-generated), an email and a name.

来源:https://stackoverflow.com/questions/16443051/no-postgresql-link-opened-yet

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!