Uncertain about recoding prepared statements from MySQL to PostgreSQL - Mailing list pgsql-novice

From G. J. Walsh
Subject Uncertain about recoding prepared statements from MySQL to PostgreSQL
Date
Msg-id 1194048798.27347.33.camel@www.dscdirectionalservices.com
Whole thread Raw
Responses Re: Uncertain about recoding prepared statements from MySQL to PostgreSQL  (John DeSoi <desoi@pgedit.com>)
List pgsql-novice
Within a lengthy form script:

In MySQL, I had, by way of example,

$sql = 'INSERT INTO testee VALUES (? ? ? ? ?)';
$stmt = $dbcx->stmt_init();
$stmt->bind_param('sssss',$protocode,$service,$sample,$normid,
$proctored);
$stmt->execute();

In PostgreSQL, to accomplish the same thing, I would want to try:

$query = "INSERT INTO testee (protocode,service,sample,normid,proctored)
VALUES ($1,$2,$3,$4,$5)";
$result = pg_prepare($cnx,"newtestee",$query);
pg_execute($cnx,"newtestee",array($protocode,$service,$sample,$normid,
$proctored));

Have I got this synyax down correctly?

I presume the pg_execute provides the data type information (the 'sssss'
in the MySQL bind-param???

I have modified another field (not shown above) as being type TIMESTAMP
DEFAULT now(). I assume I would 'pass over' such fields were they to
appear in the above example.

In MySQL the '?' placeholder in the INSERT was replaced with:
current_timestamp().

Thanks for the 'steer'. A few more coversions and I will develop a
rhythm of familiarity. For now, I want to avoid any bad habits and
faulty thinking. Its much more difficult to UNlearn than it is to learn
in the first place.

George





pgsql-novice by date:

Previous
From: Sean Davis
Date:
Subject: Unflatten array
Next
From: norman
Date:
Subject: Populate a database with username and generate MD5 hash