In response to PJ <af.gourmet@xxxxxxxxxxxx>: > In trying to learn both php and postgresql as a novice, I am trying to > debug a double migration of our old website from php4 to php5 and from > postgres 7.4 to 8.3. > I am running freebsd 7.0 on two machines and sometimes debugging from a > Windows XP. > The migrations themselves went fine; now to debug and make them actually > work so I can tear this thing apart and rebuild with a new concept, > design & implementation. > So far, I am getting this error: > > "pg_exec(): supplied argument is not a valid PostgreSQL link resource" > in this code (third line -->) > > ...snip > function SQLQuery( $query ) { > global $dbh,$curr_row,$result_hash; > if( !($r=pg_exec($dbh, $query)) ) { > if (error_reporting()>0) { > echo "<hr>SQL error (".pg_ErrorMessage($dbh).")<br>in > ($query) <hr>"; > } > return 'error'; > } > $curr_row[$r] = 0; > $rows=@@pg_numrows( $r ); > if(eregi("insert",$query)) { > #list($f1,$f2)=split('INTO',strtoupper($query)); > $f=array(); > if(eregi('(.*)into(.*)',$query,$f)) { > list($tablename,$bullshit)=split("\(",$f[2]); > $result_hash[$r]=$tablename; > } > } > return $r; > } > snip ... > > What, then, is a valid link resource? is it the strings or their > content? I have been trying to figure out if pg_exec is valid in > postrgres or should it be replaced by another function? There seem to be > a number of these functions that are returning the same error... > I have also not been able to determine the content of the strings $dbh, > $query or most other strings while debugging with eclipse, trying with > phped, devphp .... I seem to be connecting to the remote server (freebsd > with apache2.2.8 on LAN) Note that there is a pgsql+php mailing list that may be more helpful with your issues. However, I would suggest adding a var_dump($dbh) prior to the pq_exec() call as a debugging step. The output should say that $dbh is a resource. If it does not, then the connection attempt failed, or the value of that variable was lost or something else earlier in your code. A resource is a special kind of PHP variable, it is not a string, it is a resource, with a resource ID. It points to internal PHP data structures that do special things (in this case, point to a PG connection) You're using the correct commands, but the data your passing them doesn't appear to be correct. Perhaps add some debugging around the pg_connect() to ensure it's working properly. -- Bill Moran Collaborative Fusion Inc. http://people.collaborativefusion.com/~wmoran/ wmoran@xxxxxxxxxxxxxxxxxxxxxxx Phone: 412-422-3463x4023