php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #24125 Unable to add records when opened with odbc_pconnect
Submitted: 2003-06-11 09:58 UTC Modified: 2003-08-18 19:44 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: michael at redboxcode dot com Assigned:
Status: No Feedback Package: ODBC related
PHP Version: 4.3.2 OS: Win NT
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: michael at redboxcode dot com
New email:
PHP Version: OS:

 

 [2003-06-11 09:58 UTC] michael at redboxcode dot com
This problem went away when I changed odbc_Pconnect to just odbc_connect

If I read a table then attempt to insert a record to the table the results are reported successful but the record is NOT added.

If I insert the record then read the table it works correctly.

Changing the pconnect to connect corrected the problem.

If you need additional info, please email. I can strip down the scripts to create a sample of the problem.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-06-11 12:13 UTC] sniper@php.net
You should have added the short sample without us having to ask for it..(doesn't this read in the help page for "how to report" ??)

 [2003-06-11 23:17 UTC] michael at redboxcode dot com
note: these files, the access database and phpinfo() are zipped at www.redboxcode.com/Michael.zip

*************************  page1.php *******************
<?PHP

$connect_id = odbc_pconnect("mydata","",0) or die ("Cannot connect to database");

echo "<html>\n";
echo "<head>\n";
echo "<title>Insert record then read table</title>\n";
echo "</head>\n";
echo "<body>\n";

// First insert a record into the database
$sql_command = "insert into mytable (name,time_stamp) values ('Michael','".date("F j G:i:s")."');";
$result = odbc_exec( $connect_id, $sql_command );
echo "<br>".$result." = ".$sql_command."<br>";

// Display the table
$sql_command = "select * from mytable order by time_stamp;";
$rsDetail = odbc_exec($connect_id, $sql_command);
echo "<br>".$rsDetail." = ".$sql_command."<br>";
$more_records = odbc_fetch_row($rsDetail);
echo "<table border=1><tr><th>id</th><th>name</th><th>time stamp</th></tr>\n";
while ($more_records)
{
  echo "<tr><td>".odbc_result($rsDetail,'id')."</td>";
  echo "<td>".odbc_result($rsDetail,'name')."</td>";
  echo "<td>".odbc_result($rsDetail,'time_stamp')."</td></tr>\n";
  $more_records = odbc_fetch_row($rsDetail);
}
echo "</table>\n";
echo "<br><a href='page2.php'>Next try to read table then insert a record</a><br>";
echo "<br><a href='page3.php'>Clear the table</a><br>";
echo "</body>\n";
echo "</html>\n";
?>

*************************  page2.php *******************
<?PHP

$connect_id = odbc_pconnect("mydata","",0) or die ("Cannot connect to database");

echo "<html>\n";
echo "<head>\n";
echo "<title>Read table then insert a record</title>\n";
echo "</head>\n";
echo "<body>\n";

// Display the table
$sql_command = "select * from mytable order by time_stamp;";
$rsDetail = odbc_exec($connect_id, $sql_command);
echo "<br>".$rsDetail." = ".$sql_command."<br>";
$more_records = odbc_fetch_row($rsDetail);
echo "<table border=1><tr><th>id</th><th>name</th><th>time stamp</th></tr>\n";
while ($more_records)
{
  echo "<tr><td>".odbc_result($rsDetail,'id')."</td>";
  echo "<td>".odbc_result($rsDetail,'name')."</td>";
  echo "<td>".odbc_result($rsDetail,'time_stamp')."</td></tr>\n";
  $more_records = odbc_fetch_row($rsDetail);
}
echo "</table>\n";

// Now insert a record into the database
$sql_command = "insert into mytable (name,time_stamp) values ('Michael','".date("F j G:i:s")."');";
$result = odbc_exec( $connect_id, $sql_command );
echo "<br>".$result." = ".$sql_command."<br>";


echo "<br><a href='page1.php'>Back to insert a record then display table</a><br>";
echo "<br><a href='page3.php'>Clear the table</a><br>";
echo "</body>\n";
echo "</html>\n";
?>

*************************  page3.php *******************
<?PHP

$connect_id = odbc_pconnect("mydata","",0) or die ("Cannot connect to database");

echo "<html>\n";
echo "<head>\n";
echo "<title>Clear the table and start over</title>\n";
echo "</head>\n";
echo "<body>\n";

// Clear mytable database
$sql_command = "delete * from mytable;";
$result = odbc_exec( $connect_id, $sql_command );
echo "<br>".$result." = ".$sql_command."<br>";

// Display the table
$sql_command = "select * from mytable order by time_stamp;";
$rsDetail = odbc_exec($connect_id, $sql_command);
echo "<br>".$rsDetail." = ".$sql_command."<br>";
$more_records = odbc_fetch_row($rsDetail);
echo "<table border=1><tr><th>id</th><th>name</th><th>time stamp</th></tr>\n";
while ($more_records)
{
  echo "<tr><td>".odbc_result($rsDetail,'id')."</td>";
  echo "<td>".odbc_result($rsDetail,'name')."</td>";
  echo "<td>".odbc_result($rsDetail,'time_stamp')."</td></tr>\n";
  $more_records = odbc_fetch_row($rsDetail);
}
echo "</table>\n";
echo "<br><a href='page1.php'>Insert a record then display the table</a><br>";
echo "<br><a href='page2.php'>Display the table then insert a record</a><br>";
echo "</body>\n";
echo "</html>\n";
?>
 [2003-06-12 05:44 UTC] sniper@php.net
Maybe I didn't stress enough the word SHORT example script..? :) 

Can you please make this ONE file and max. 15 lines.
No HTML either, please.

 [2003-06-16 07:49 UTC] michael at redboxcode dot com
please note: I noticed that I am actually on version 4.3.1
Windows NT localhost 4.0 build 1381 

inserting a record then reading the database works in this code

<?PHP
$connect_id = odbc_pconnect("mydata","",0) or die ("Cannot connect to database");
// First insert a record into the database
$sql_command = "insert into mytable (name,time_stamp) values ('Michael','".date("F j G:i:s")."');";
$result = odbc_exec( $connect_id, $sql_command );
echo $result." = ".$sql_command."\n";
// this will work correctly
?>

reading the database and THEN inserting the records does NOT work in this code.

<?PHP
$connect_id = odbc_pconnect("mydata","",0) or die ("Cannot connect to database");
// first read the table
$sql_command = "select * from mytable order by time_stamp;";
$rsDetail = odbc_exec($connect_id, $sql_command);
// Now insert a record into the database
$sql_command = "insert into mytable (name,time_stamp) values ('Michael','".date("F j G:i:s")."');";
$result = odbc_exec( $connect_id, $sql_command );
// The command returns a valid results, but the record is NOT in the database
?>
 [2003-06-16 08:30 UTC] sniper@php.net
Please update to PHP 4.3.2 first.

 [2003-06-17 20:46 UTC] michael at redboxcode dot com
I've upgraded my development machine to 4.3.2 and the behavior still exist.
 [2003-06-25 15:05 UTC] kalowsky@php.net
Please turn on SQL Logging in your ODBC Administrator and post the appropriate portions to this bug... aka from the first initial connect to the last ODBC command for the script.  Please note you MAY need to delete the unique identifing material in the script (aka a username/password).  
 [2003-08-18 19:44 UTC] sniper@php.net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Open". Thank you.


 [2004-10-02 11:55 UTC] giosp at panozzo dot it
My platform: PHP4.3.9, Win2003, .mdb file

It seems that INSERT and DELETE are cached, they never get executed if they are the last sql commands of your script.
Adding a "SELECT" at the end (as in the following sample), make them works.

<?php
	$dsn = "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=C:\Inetpub\wwwroot\pxfm\db\pxfmw.mdb;DefaultDir=C:\Inetpub\wwwroot\pxfm\db";
	$con = odbc_pconnect($dsn,"","") or die("Connection error<BR>\n".odbc_errormsg());
	$r = odbc_exec($con,"select * from testtab") or die("error: ".odbc_errormsg());
	while( odbc_fetch_row($r) ) {
		print "ID=".odbc_result($r,"id")."<BR>\n";
		print "NAME=".htmlspecialchars(odbc_result($r,"name"))."<BR>\n";
		print "<P>\n";
	}
	
	// This is just silently ignored !!
	odbc_exec($con,"INSERT INTO testtab (id,name) values(12,'john')") or die("exec error!");
	
	// If you uncomment the following line, the INSERT is executed, but not the DELETE
	// odbc_exec($con,"DELETE FROM testtab") or die("delete error");
	
	// The following line makes it works, despite id=99999 does not exists
	// odbc_exec($con,"SELECT * from testtab where id=99999");
?>
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Thu Nov 26 04:01:23 2020 UTC