Hi all!
How can you get rid of the error that displays if you do a query which
returns no result and then try and fetch the array, WITHOUT having to
put the while in another conditional like if ($result != ''), something
more efficient if possible.
regards
Marc 7 3313
monomaniac21 said the following on 25/09/2006 16:43:
Hi all!
How can you get rid of the error that displays if you do a query which
returns no result and then try and fetch the array, WITHOUT having to
put the while in another conditional like if ($result != ''), something
more efficient if possible.
A query will only return no result if the syntax is invalid.
--
Oli
Oli Filth said the following on 25/09/2006 18:15:
monomaniac21 said the following on 25/09/2006 16:43:
>Hi all!
How can you get rid of the error that displays if you do a query which returns no result and then try and fetch the array, WITHOUT having to put the while in another conditional like if ($result != ''), something more efficient if possible.
A query will only return no result if the syntax is invalid.
That is, if the SQL syntax is invalid.
--
Oli
monomaniac21 wrote:
Hi all!
How can you get rid of the error that displays if you do a query which
returns no result and then try and fetch the array, WITHOUT having to
put the while in another conditional like if ($result != ''), something
more efficient if possible.
regards
Marc
You can always append the mysql_query with @, but then you're only
hiding a real problem.
Query's that return no results are not erroneous, they do not display an
error message. If you get an error message it means your query was
invalid. echo mysql_error() to find out why.
--
*************** **************
Chuck Anderson • Boulder, CO http://www.CycleTourist.com
*************** **************
monomaniac21 wrote:
Hi all!
How can you get rid of the error that displays if you do a query which
returns no result and then try and fetch the array, WITHOUT having to
put the while in another conditional like if ($result != ''), something
more efficient if possible.
regards
Marc
$result = mysql_query($qu ery);
$num = mysql_num_rows( $result);
if( $num ) {
while ($row = mysql_fetch_arr ay($result)){
//whatever
}
}
friglob said the following on 26/09/2006 11:09:
monomaniac21 wrote:
>> How can you get rid of the error that displays if you do a query which returns no result and then try and fetch the array, WITHOUT having to put the while in another conditional like if ($result != ''), something more efficient if possible.
$result = mysql_query($qu ery);
$num = mysql_num_rows( $result);
if( $num ) {
while ($row = mysql_fetch_arr ay($result)){
//whatever
}
}
But why bother? Both these tests do the same thing. If there are no
results (i.e. no rows returned), then the first call to
mysql_fetch_arr ay() will return false, and the while loop will stop.
--
Oli
I don't know if this will be more efficient than using a conditional,
but two other avenues, off the top of my head...
1) Turn off error messages, then enable again after your call. Something
like...
$oldErrorReport ing = error_reporting (0)
// ... do your stuff ...
error_reporting ($oldErrorRepor ting)
2) Do output buffering before and after your code to grab any unwanted
errors, notification, etc...
ob_start();
$oldErrorReport ing = error_reporting (E_ALL);
$oldHtmlErrors = ini_set('html_e rrors',0);
// ... do your stuff ...
$errorMessages = ob_get_clean();
error_reporting ($oldErrorRepor ting);
ini_set('html_e rrors',$oldHtml Errors);
if(trim($errorM essages) == '') {
mail('m*@exampl e.com','MySQL Error Report',$errorM essages)
}
Hmmm, this might be worthy of a wiki topic. Plus it might be a little
clearer with syntax highlighting. And I won't have to post multiple
times if I want to expand the whole error trapping idea when I have
time. The ideas are flowing already... dumping to different error log
files based on what routine(s) you're watching for instance. Anyway,
here's the link... http://www.gunthersoft.com/wiki/ErrorHandlingWithPHP
In article <11************ *********@i42g2 000cwa.googlegr oups.com>, mc******@google mail.com says...
Hi all!
How can you get rid of the error that displays if you do a query which
returns no result and then try and fetch the array, WITHOUT having to
put the while in another conditional like if ($result != ''), something
more efficient if possible.
regards
Marc
Klaus Brune wrote:
In article <11************ *********@i42g2 000cwa.googlegr oups.com>, mc******@google mail.com says...
>>Hi all!
How can you get rid of the error that displays if you do a query which returns no result and then try and fetch the array, WITHOUT having to put the while in another conditional like if ($result != ''), something more efficient if possible.
regards
Marc
I don't know if this will be more efficient than using a conditional,
but two other avenues, off the top of my head...
1) Turn off error messages, then enable again after your call. Something
like...
$oldErrorReport ing = error_reporting (0)
// ... do your stuff ...
error_reporting ($oldErrorRepor ting)
2) Do output buffering before and after your code to grab any unwanted
errors, notification, etc...
ob_start();
$oldErrorReport ing = error_reporting (E_ALL);
$oldHtmlErrors = ini_set('html_e rrors',0);
// ... do your stuff ...
$errorMessages = ob_get_clean();
error_reporting ($oldErrorRepor ting);
ini_set('html_e rrors',$oldHtml Errors);
if(trim($errorM essages) == '') {
mail('m*@exampl e.com','MySQL Error Report',$errorM essages)
}
Hmmm, this might be worthy of a wiki topic. Plus it might be a little
clearer with syntax highlighting. And I won't have to post multiple
times if I want to expand the whole error trapping idea when I have
time. The ideas are flowing already... dumping to different error log
files based on what routine(s) you're watching for instance. Anyway,
here's the link...
http://www.gunthersoft.com/wiki/ErrorHandlingWithPHP
(top posting fixed)
Much less efficient. When you get the error, the MySQL libraries have
to report it back to PHP, and PHP must handle the error. This may (and
generally does) have significant overhead - like logging the error,
determining if it can be handled or the script must be terminated, etc.
A conditional is just a quick test.
You should never plan on getting errors in your code and handling them
like you're suggesting. If for no other reason than a new release may
change the default error handling.
And BTW - please don't top post. Thanks.
--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp. js*******@attgl obal.net
=============== === This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Joshua Beall |
last post by:
Hi All,
I know that I can prepend functions with an '@' character in order to get
them to not output any errors, but I am wondering is there any way for a
function that I write to know if it has been called with the '@' character?
Then I can decide how errors are supposed to be handled. E.g., I could have
them emailed or logged, instead of...
|
by: erica |
last post by:
Hi,
I am currently writing PHP code for some polling software. When someone
votes, it stores their IP address in the database. From then on, they
cannot vote in that particular poll, they only view the results. There
are several polls in the database, and there is a field called
"status". When it is 0, the poll is "active" and can be voted...
|
by: Liam Caffrey |
last post by:
Hi,
I can see that by using the object ID rather that the object name, the
following SQL query works. Has anybody got any idea what is causing the
error?
-- Works OK
select o.id
,checksum_agg(binary_checksum(m.text))
from sysobjects o
|
by: dawnerd |
last post by:
Hi, I am developing a CMS and came across something which has never
happened to me before, and I re-wrote the specific script twice, both
differently, and still had the same error.
I'm not sure if it is apache, or php, or just an error I am not seeing.
here is the code:
<?php
/**
* Loop through the resultset
|
by: agphoto |
last post by:
when we do mysql_query with while and mysql_num_rows() together then while do no show the first row from table in database..
example :
<?
$conn = mysql_connect($DBhost,$DBuser,$DBpass) or die("Unable toconnect to database");
@mysql_select_db("$DBName") or die("Unable to select database $DBName"); $sqlquery = "SELECT * FROM $table WHERE...
| |
by: Cybex |
last post by:
I am trying to get this to work but when ever I enter an proper
integer it just hangs. The Switch default seems to catch the improper
integers but the right ones are not triggering the way I thought they
would.
Any help would be appreciated...
#include <iostream>
#include <string>
|
by: drgnhiker |
last post by:
And I seem to be missing the error...can't find it and the statements in one section duplicate other sections with no error....any help would be greatly appreciated: the following is the entire code...(Yes I know it is from a book but I got to learn it all from someplace :).....thanks in advance for any and all help and advice.
<?php
$db =...
|
by: TxSteve |
last post by:
Hello (I'm a rookie) and need help please understanding why my last row will not total.
Using SharePoint (MOSS 2007) built a data view and edited the stock code using this helpful advice; http://www.intranoggin.com/Lists/Posts/Post.aspx?List=4bd72ad6%2Db469%2D481e%2D9dcd%2Da30588ee81e5&ID=21 The page is working great except for the last user...
|
by: Topbidder |
last post by:
I have this error on the code
Parse error: syntax error, unexpected '"' in /home/topbidd/public_html/bid2/bid_classic.php on line 159
now i thought the error was this
It seems that the code has an extra " at the end before the ;
VALUES('" .$auction_id. "','" .$user_id. "','"
.converttonum(get_next_bid($auction_id)). "','" .$NOW....
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |