Vijay Chauhan Vijay Chauhan - 4 months ago 8
PHP Question

completely run in localhost but not in live server in postgreSQL

my code look like these.

$host = "host=localhost";
$port = "port=5432";
$dbname = "dbname=test_db";
$credentials = "user=postgres password=";

$db = pg_connect( "$host $port $dbname $credentials" );

$query = "INSERT INTO table_test_som(uid, book_status, book_datetime, dom_id, from_date, to_date, from_time
, to_time, event) VALUES ('4', '1', '2016-07-19 12:29:42', '27', '2016-07-22', '2016-07-22', '11:30', '12:00', 'Booking_vijay')";

$result = pg_query($query);

if (!$result) {
$errormessage = pg_last_error();
echo "Error with query: " . $errormessage;
exit();
}

printf ("These values were inserted into the database");
pg_close();



  • In localhost my code run completely, when i execute in server then it will display an error like :

    Error with query: ERROR: permission denied for sequence table_test_som


Answer

This should not happen with the postgres user. I am betting that you have changed this code when tried on the live server.

$credentials = "user=postgres password=";

The actual user does not have privileges for sequences. You can fix it by

GRANT USAGE, SELECT ON ALL SEQUENCES IN SCHEMA public to my_user;

Taking care to replace my_user with the actual username that you are using in your php code.

If ALL doesn't work for you, the only option is to execute this query on each table that causes trouble.