我有一个设置使用Apache24,php环境和postgresql数据库。 我想填充数据库表中的一些列(不是全部),但它不像我所期望的那样工作。pg_query INSERT INTO无法正常工作
我碰到下面的错误/警告和db不填充: 警告:pg_query():查询失败:ERROR:语法错误或接近 “c329a92850f6d539dd376f4816ee2764517da5e0235514af433164480d7a” LINE 1:......总之,盐)VALUES(DEFAULT ,[email protected],per,8254c329a92850 ... ^在C:\ Users \ Public \ Server \ Apache24 \ htdocs \ eMe \ newuser.php上线34
对此的任何支持都非常感谢。寻找类似的问题,但不能解释我的上下文中的答案
<?php
# Registration form input to postgresql user table in myDB
session_start();
# Retrieve data from input form
$username = $_POST['username'];
$email = $_POST['email'];
$password = $_POST['password'];
# Concatenate and hash password with salt
require_once(dirname(__DIR__).'\eMe\saltgenerator.php');
global $randString;
#$randString = pg_escape_string($randString);
$isalt = pg_escape_string($randString);
$saltandpassword = $isalt. $password;
$hashedpassword = hash('sha256', $saltandpassword, false);
$username = pg_escape_string($username);
$email = pg_escape_string($email);
$hashedpassword= pg_escape_string($hashedpassword);
# Insert data into Postgresql database
# INSERT INTO table_name (column1, column2, column3 .....) VALUES (value1, value2, value3....)
include_once(dirname(__DIR__).'\eMe\config.php');
$query = "INSERT INTO users (userid, mailaddress, username, userpassword, salt) VALUES (DEFAULT, $email, $username, $hashedpassword, $isalt)";
#$result =
#pg_query_params($query);
pg_query($query);
?>
我试图包括引号和如link所述的反引号报价,但它不能解决问题。错误/警告略有不同,但:
警告:pg_query():查询失败:ERROR:语法错误或接近 “`” LINE 1:INSERT INTO用户(userid
,`mailaddress`,`username`,`使用... ^在第30行的C:\ Users \ Public \ Server \ Apache24 \ htdocs \ eMe \ newuser.php上
可能的重复[何时使用单引号,双引号和反引号在MySQL](https://stackoverflow.com/questions/11321491/when-to-use-single-quotes-double- quotes -and-backticks-in-mysql) – aynber
我真的推荐切换到PDO,它可以与pgsql进行交互。通过准备好的语句和参数绑定,您将永远不必担心引用问题,而且您不需要转义您的值。 – aynber
感谢您的意见。我看看我是否设法使用PDO。我觉得有点难以理解语法/设置 – om78