[pgsql-jp: 29894] Re: pg_atoi エラーが出る
Takashi Mochizuki
mochizuki @ adcoop.co.jp
2003年 5月 15日 (木) 11:24:20 JST
望月です。
恥ずかしながら、私の投稿
$sql = "insert into hoge (someflg,code,textcode) values (0,nextval('code'),'$textcode')";
は誤りでした。
お詫びして訂正いたします。
$textCode = 'str010101954';
$sql = "INSERT INTO table1(someflg, textCode) VALUES(0,'$textCode')";
pg_exec($con, $sql);
で、pg_atoiのエラー がでるのは上記以外のカラムが実際は存在するのではない
でしょうか?
insertする順番がずれているのが原因かと思います。
以下テスト用(構成:PostgreSQL-7.3.2,Apache_1.3.27,PHP 4.3.2RC1)
Table "public.hoge"
Column | Type | Modifiers
----------+----------+--------------------------------------------------------
someflg | smallint |
code | integer | not null default nextval('public.hoge_code_seq'::text)
textcode | text |
serial_test=# select * from hoge;
someflg | code | textcode
---------+------+--------------
0 | 1 | str010101954
2 | 2 | abcde
2 | 3 | abcde
4 | 4 | abcde
5 | 5 | abcde
5 | 6 | abcde
5 | 7 | abcde
10 | 8 | abcde
(8 rows)
<?php
$connectdbname = "host=127.0.0.1 port=5432 user=nobody dbname=serial_test";
$someflg = $_POST["someflg"];
$textcode= $_POST["textcode"];
$dbhandle = pg_connect($connectdbname) or die("dbhandle failed");
$sql = "insert into hoge (someflg,textcode) values ('$someflg','$textcode')";
pg_query($dbhandle,"BEGIN");
pg_query($dbhandle,$sql);
pg_query($dbhandle,"COMMIT");
?>
<html>
<head>
<title>シリアル番号</title>
</head>
<body>
<h1>シリアル番号</h1>
<table border="1">
<tr valign=top align=left>
<th>番号</th>
<th>テキスト</th>
</tr>
<form method="post" action="<?php print("http://{$_SERVER['HTTP_HOST']}{$_SERVER['PHP_SELF']}"); ?>">
<tr valign=middle align=left>
<td><input type="text" name="someflg" size=12 maxlength=32 value="<?php print("$someflg"); ?>"></td>
<td><input type="text" name="textcode" size=12 maxlength=32 value="<?php print("$textcode"); ?>"></td>
<td align=right><input type="submit" name="serial_test" value="シリアル番号"></td>
</tr>
</form>
</table>
</body>
</html>
以上
pgsql-jp メーリングリストの案内