funbinod Posted May 19, 2019 Share Posted May 19, 2019 hello all! i'm learning postgresql. i was just trying to fetch some data using prepared statement. but found that it is quiet different than mysql. the all i learnt searching on the web is this. $cuidstmt = $pgsql->prepare("SELECT cid, uid FROM user WHERE name=?"); if(!$cuidstmt) { echo "Error: " . $pgsql->errorInfo()[2]; } else { $cuidstmt->bindParam('i', $u); $cuidstmt->execute(); $cuidstmt->fetch(); } but i could not understand how can i print the required data. where the data is stored. just like in mysqli we can bind result on a string, how can i do that in pgsql? can u please help me? Link to comment Share on other sites More sharing options...
funbinod Posted May 19, 2019 Author Share Posted May 19, 2019 i found that what i learnt so far is also wrong. i corrected the aforementioned code like this $cuidstmt = $pgsql->prepare("SELECT cid, uid FROM user WHERE name=?"); if(!$cuidstmt) { echo "Error: " . $pgsql->errorInfo()[2]; } else { $cuidstmt->execute(array($u)); $cuidstmt->execute(); $cuidstmt->fetch(); } but i still couldn't understand how can i get the result(s). where can i get the data from 'cid' and 'uid' columns mentioned in the prepared statement. thank u all in advance. Link to comment Share on other sites More sharing options...
dsonesuk Posted May 19, 2019 Share Posted May 19, 2019 The same way you would use to display results from mysql, a while loop that gets each row from $cuidstmt ->fetch( ) where you refer to specific column names. Link to comment Share on other sites More sharing options...
justsomeguy Posted May 20, 2019 Share Posted May 20, 2019 Are you using a database wrapper or something? I don't see an object-oriented interface for the PGSQL functions in the PHP manual. Link to comment Share on other sites More sharing options...
Funce Posted May 20, 2019 Share Posted May 20, 2019 3 hours ago, justsomeguy said: Are you using a database wrapper or something? I don't see an object-oriented interface for the PGSQL functions in the PHP manual. Looks like PDO to me. Link to comment Share on other sites More sharing options...
justsomeguy Posted May 20, 2019 Share Posted May 20, 2019 If that's PDO then it's exactly the same. PDO isn't different based on which database driver is used, that's the entire purpose. Different databases might have different capabilities, though, for example when checking the number of records that were returned. Link to comment Share on other sites More sharing options...
Ingolme Posted May 21, 2019 Share Posted May 21, 2019 I'd assign the value returned by ->fetch() to a variable and print it out to see what it contains. You only need to call ->execute() once, the second one will probably cause an error. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now