RE: [PHP-GENERAL] insert from selects

From: Date: Thu, 08 Jun 2000 14:39:13 +0000
Subject: RE: [PHP-GENERAL] insert from selects
References: 1  Groups: php.db php.general 
Request: Send a blank email to php-general+get-1299@lists.php.net to get a copy of this message
Your query statement should have a link identifier, a lot of us use "$db", obtained from mysql_connect(): $result=mysql_query($sql,$db); Also, mysql_affected_rows() is supposed to take the link identifier, not the query result. Finally, i don't think mysql does inserts based on selects. You would find that out if you check the error code after your query: if ($errno=mysql_errno($db)) { $error=mysql_error($db); echo "Error #$errno inserting articles from art_queue: $error<br>\n"; exit; } > From: Chandrashekhar Bhosle [mailto:cnb@freeos.com] > Sent: Sunday, August 06, 2000 9:33 AM > To: 'PHP General List' > Cc: php-db@lists.php.net > Subject: [PHP-GENERAL] insert from selects > > > > hello, > I have a query like, > > $sql = "INSERT INTO articles (title, author, intro, body, related, > extra) SELECT title, author, intro, body, related, extra FROM art_queue > WHERE aid='$aid'"; > > $result mysql_query("$sql"); > > It runs perfectly fine but I don't get either, > > 1.) number of affected rows by mysql_affected_rows($result) function. > 2.) number of rows matched by mysql_num_rows($result) function. > > both say $result is not a valid MySQL Link identifier. > > how am I supposed to know if such queries of type > > "insert into (cols) select ... from" > > have done exactly what they were supposed to. that is, inserted and > selected n number of rows. > > right now one can only get if query fails or succeeds from > mysql_query(). > > - cnb. > > > > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net

« previous php.general (#1299) next »