Thread: array syntax in pg_execute call
I have a complex php form which initializes rows in 4 tables. In each case I have employed prepared statements. In the first 3 everything works beautifully with as many as 45 columns involved. The 4th table (badtest) is driving me around the bend. Simplified, the schema would be: testcode CHAR[10] not null primary key testrank SMALLINT[] testraw SMALLINT[] And the script is: $query = "INSERT INTO badtest(testcode,testrank,testraw) VALUES($1,$2, $3)"; $result = pg_prepare($pg,"initbadtest",$query) or die('as usual'); pg_execute($pg,"initbadtest",array(testcode,'{0,0,0,0,0,0}','{0,0,0,0,0,0})); The only difference is the presence of arrays. Inclusion of this script stops the firm from being diplayed, but there are no logged items either for the system errorlog or postgresql itself. So 'die' does its job, so to speak, but what am I doing wrong here? The documentation for 8.3 section 14 mentions this array syntax is similar to 'C'. Yes, it is, but that is small comfort. I also tried the ARRAY[0.0.0.0.0.0] style but the same problem - no display. Remove the code and the script 'does it thing'. Has to be simple, but I can no longer see for looking. George
> pg_execute($pg,"initbadtest",array(testcode,'{0,0,0,0,0,0}','{0,0,0,0,0,0}));
Apparently there's missing quote here and what is testcode? Should it be 'testcode' or $testcode or maybe it is defined constant? Anyway, if you provided correct table definition your testcode column is declared as array of char (char(1) to be exact) - CHAR[10] which might be the reason. As for error messages - PHP emits warnings on query failure so you have to adjust error_reporting level appropriately to see them, you can also handle errors in your code for example like this:
$result = pg_execute(...);
if ($result === false) {
print pg_last_error();
die('Query failed');
}
Apparently there's missing quote here and what is testcode? Should it be 'testcode' or $testcode or maybe it is defined constant? Anyway, if you provided correct table definition your testcode column is declared as array of char (char(1) to be exact) - CHAR[10] which might be the reason. As for error messages - PHP emits warnings on query failure so you have to adjust error_reporting level appropriately to see them, you can also handle errors in your code for example like this:
$result = pg_execute(...);
if ($result === false) {
print pg_last_error();
die('Query failed');
}
I'm guilty of some careless typing. Sorry. I was trying to simplify things for the email only and made a bad matter worse. The testcode is the primary key for all tables and should have been shown as character(10), not char[10]. And yes, there is a comma missing after the closing } of the second array, but not in the actual code. Thanks very much for the tip about properly displaying the errors though. I will try to learn from that tomorrow when I have gained some needed sleep. My thanks for the help. George On Thu, 2008-03-13 at 04:34 +0300, Vyacheslav Kalinin wrote: > > > pg_execute($pg,"initbadtest",array(testcode,'{0,0,0,0,0,0}','{0,0,0,0,0,0})); > Apparently there's missing quote here and what is testcode? Should it > be 'testcode' or $testcode or maybe it is defined constant? Anyway, if > you provided correct table definition your testcode column is declared > as array of char (char(1) to be exact) - CHAR[10] which might be the > reason. As for error messages - PHP emits warnings on query failure so > you have to adjust error_reporting level appropriately to see them, > you can also handle errors in your code for example like this: > $result = pg_execute(...); > if ($result === false) { > print pg_last_error(); > die('Query failed'); > } >