Forum Moderators: coopster
Executing the MySQL query below into outfile from a shell works great, and returns (for example):
Query OK, 430 rows affected (1 min 10.83 sec) So I figured I could write a PHP script to avoid having to type the query into the shell, each time:
$dbconn=mysql_connect("localhost","uid","pwd"); mysql_select_db("database",$dbconn); $result=mysql_query("select tracking_code,count(tracking_code) into outfile 'result.txt' from records group by ip_address",$dbconn); And to get the same "affected rows" count offered by the shell execution, I added:
$count=mysql_result($result,0,0); I also tried
mysql_affected_rows(), mysql_num_rows() and some other, user-submitted things found on the PHP Manual pages. In each case, the execution of the PHP script resulted in the outfile holding the right data, but I keep getting
... supplied argument is not a valid MySQL result resource ... for any of the counting functions I try. I'm running a recent XAMPP installation on Win98SE, if that makes any difference.
Any help is truly appreciated.
$dbconn ... mysql_select_db ... $result ... $count ... echo "$count Rows\n"; That's the whole thing ... well, I also include a
where clause to select records from particular date ranges. That's the part I don't want to have to type into the shell, each time. But other than the additional where timestamp > 109924980 && timestamp < 109938245, it's the same. If I can get it counting, I'll use an array of timestamp data and loop through, but I'm not there, yet. What's particularly odd, to me, is that the shell execution reported 'affected rows', yet
mysql_affected_rows returns the error (I know it shouldn't be appropriate, anyway) as does mysql_num_rows (which is for SELECT statements like this one). Maybe the outfile instruction is appropriating the buffer used by
mysql_num_rows et al. in a way such that it's not available to the subsequent functions? [edited by: StupidScript at 6:37 pm (utc) on Jan. 12, 2006]
If you really wanted to get the number of rows you could repeat the query just as a regular select and then use mysql_num_rows
<added>
$result=mysql_query("select tracking_code,count(tracking_code) into outfile 'result.txt' ...
I bet that in this case it won't return a resource at all, the value of $result is probably null, 1 or 0 as there is no result, the query finishes all by itself.