Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pg_escape_literal() expects parameter 1 to be resource, boolean given #709

Closed
gustavojm opened this issue Sep 6, 2017 · 5 comments · Fixed by #713
Closed

pg_escape_literal() expects parameter 1 to be resource, boolean given #709

gustavojm opened this issue Sep 6, 2017 · 5 comments · Fixed by #713

Comments

@gustavojm
Copy link
Contributor

pg_escape_literal() expects parameter 1 to be resource, boolean given

BASEPATH/Database/Postgre/Connection.php at line 217

210      * @param  string $str
211      * @return mixed
212      */
213     public function escape($str)
214     {
215         if (is_string($str) OR ( is_object($str) && method_exists($str, '__toString')))
216         {
217             return pg_escape_literal($this->connID, $str);
218         }
219         elseif (is_bool($str))
220         {
221             return $str ? 'TRUE' : 'FALSE';
222         }
223 
224         return parent::escape($str);

My code:

        $this->db = \Config\Database::connect();
        $fields = $this->db->getFieldData('categories');
@JakeAi
Copy link
Contributor

JakeAi commented Sep 7, 2017

If it's a bool, then the connection failed.

@gustavojm
Copy link
Contributor Author

Yes, but the database config is correct, because if I do

        $tables = $this->db->listTables();
        $fields = $this->db->getFieldData('categories');

then it succeeds.
If a previous method establishes the connection then it works...

@JakeAi
Copy link
Contributor

JakeAi commented Sep 8, 2017

I'll look in the morning.

@lonnieezell
Copy link
Member

Oops. Looks like I fixed this on MySQL but not on Postgres. Basically, just need to check within the escape method if the connection is valid and initialize the connection if it's not.

samsonasik added a commit to samsonasik/CodeIgniter4 that referenced this issue Sep 8, 2017
samsonasik added a commit to samsonasik/CodeIgniter4 that referenced this issue Sep 8, 2017
@samsonasik
Copy link
Member

I've created PR #713 for it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants