p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


  Return to Index  

beginning_php thread: Mysql to Psql


Message #1 by "Srinivasan Prasanna" <Sri_core@m...> on Thu, 3 Oct 2002 00:07:50
I have a code which works fine with php and mysql. My client has changed 
the requirement of the db to psql. I have the table created in pgsql. How 
do I need to modify my code to submit the records for psql DB. 
The code for header.inc 
<?php 
$conn = pg_pconnect("dbname=consult host=my.domain.com port=5432 
user=consult") or die("Could not connect!"); 
?php> 
The error I get is: 
Parse error: parse error in /usr/local/tomcat/webapps/ussa/header.inc on 
line 3 

The sme header.inc in my sql is 
<?php 
$db = mysql_connect("localhost", "root"); 
mysql_select_db("cfm2php",$db); 
?> 
The submit page code part is: 
MysqlDB (this works) 
$SQL = "SELECT * FROM msu9900"; 

$result = mysql_query($SQL,$db); 


$SQL1 = "insert into msu9900"; 
$SQL1 = $SQL1 . " (FirstName, LastName, Street, City, State, Zip, 
HomePhone, EMail, WorkPhone, Languages, ServYrs, Country, AArea, 
Occupation, Employer) "; 
$SQL1 = $SQL1 . " values ('$fldfirst_name','$fldlast_name','$fldstreet','$f
ldcity','$fldstate','$fldzip','$fldhphone','$fldem
ail','$fldwphone','$fldlang','$fldsyrs','$fldcount
ry','$fldarea','$fldoccupation','$fldemp') "; 

$result1 = mysql_query($SQL1,$db); 
For psql (This does not work) 
$SQL = "SELECT * FROM msu9900"; 

//$result = mysql_query($SQL,$db); 
$result = pg_exec( $conn, $SQL ); 


$SQL1 = "insert into msu9900"; 
$SQL1 = $SQL1 . " (FirstName, LastName, Street, City, State, Zip, 
HomePhone, EMail, WorkPhone, Languages, ServYrs, Country, AArea, 
Occupation, Employer) "; 
$SQL1 = $SQL1 . " values ('$fldfirst_name','$fldlast_name','$fldstreet','$f
ldcity','$fldstate','$fldzip','$fldhphone','$fldem
ail','$fldwphone','$fldlang','$fldsyrs','$fldcount
ry','$fldarea','$fldoccupation','$fldemp') "; 

// $result1 = mysql_query($SQL1,$db); 
$result1=pg_exec($conn,$SQL); 

The error I get is:
Warning: Supplied argument is not a valid PostgreSQL link resource 
in /usr/local/tomcat/webapps/ussa/submit2.php on line 76

Warning: Supplied argument is not a valid PostgreSQL link resource 
in /usr/local/tomcat/webapps/ussa/submit2.php on line 84

Exactly the modified lines
// $result1 = mysql_query($SQL1,$db); 
$result1=pg_exec($conn,$SQL); 
I am thinking my connection string is an issue. 
Any thoughts/ideas? 
Thanks 
Sri


  Return to Index