Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Call Me Tom <noemail@noemail.com> |
|---|---|
| Newsgroups | alt.php.sql |
| Subject | UPDATE Problem |
| Message-ID | <eps67dda1pu0dhqi8gfqshnf20k6rt3iji@4ax.com> (permalink) |
| Date | 2018-02-01 15:07 -0500 |
In table test there is a text field. For all rows I want to change the
first 34 characters to something else. Here is my code.
<?php
require_once('./includes/mysql_connect.php');
$query = "SELECT report_id,fsacars_rep_url
FROM test";
$result=$dbh->query($query);
$numin=$result->rowCount();
echo "$numin";
while($url_orig=$result->FETCH(PDO::FETCH_NUM)) {
$report_id = $url_orig[0];
$url_trim = substr($url_orig[1],34);
$url_new = 'http://localhost/CAA' . $url_trim;
$sql="UPDATE test
SET fsacars_rep_url = $url_new
WHERE report_id = $report_id";
$dbh->exec($sql);
}
From tests I have shown that values are correct, However, the UPDATE
fails. A response in a PHP forum was:
"You are updating the table before recovering all the rows from a row
set. The exec will invalidate the internal "cursor" that is used to
fetch the rows one by one."
So, my question here is how do I change the first 34 characters of a
field in every row of the table?
Back to alt.php.sql | Previous | Next — Next in thread | Find similar
UPDATE Problem Call Me Tom <noemail@noemail.com> - 2018-02-01 15:07 -0500
Re: UPDATE Problem "J.O. Aho" <user@example.net> - 2018-02-01 22:07 +0100
Re: UPDATE Problem Call Me Tom <noemail@noemail.com> - 2018-02-01 17:33 -0500
csiph-web