Home > database >  Cannot connect to Snowflake Database [PHP]
Cannot connect to Snowflake Database [PHP]

Time:12-02

The structure of the table I'm trying to reach is as such:

  • Database: INTERNAL_STUFF
  • Schema: INTERNAL_TEST
  • Table: TEST_TABLE_SIMPLE

I create a PDO as such:

    $dbh = new PDO("snowflake:account=$this->account", $this->user, $this->password);
    $dbh->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );

If I use this query:

    $result = $dbh->query("SELECT * FROM INTERNAL_STUFF.INTERNAL_TEST.TEST_TABLE_SIMPLE");

I end up getting this response - 'Schema 'INTERNAL_STUFF.INTERNAL_TEST' does not exist or not authorized.'. So it appears to be treating the database and the schema as just the schema.

If I use the same query but drop the database from the front:

    $result = $dbh->query("SELECT * FROM INTERNAL_TEST.TEST_TABLE_SIMPLE");

I end up getting this response - 'SQLSTATE[22000]: Data exception: 90105 Cannot perform SELECT. This session does not have a current database. Call 'USE DATABASE', or use a qualified name.'

What am I doing wrong here? My user has access to the correct role to view the table, and that exact query (the longer of the two) works just fine in a Snowflake Worksheet.

CodePudding user response:

Can you execute query USE DATABASE INTERNAL_STUFF and next query USE SCHEMA INTERNAL_TEST before you execute your main Sql query.

CodePudding user response:

You may also set the default namespace(database & Schema) for your user using Alter User statement.

Details: https://docs.snowflake.com/en/sql-reference/sql/alter-user.html#usage-notes

  • Related