473,775 Members | 2,615 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

PHP/MySQL warnings about results

I've made a function to fetch all results as an array of result-
arrays. Getting the result arrays is easy, via mysql_fetch_arr ay, and
function itself is quite simple, as follows:

function db_query($db, $query)
{
$result = mysql_query($qu ery, $db);
$res_array = array();

if ($result) //it is a search
{
while($data = mysql_fetch_arr ay($result,MYSQ L_ASSOC))
array_push($res _array,$data);
}

return $res_array;
}

But there's a slight problem: when the query in question is an INSERT,
UPDATE or DELETE query, PHP will show me a warning saying:

Warning: mysql_fetch_arr ay(): supplied argument is not a valid MySQL
result resource in /home/grad/ccomp/06/guedesav/public_html/PbBlog/inc/
db.php on line 28
(line 28 is "while($dat a = mysql_fetch_arr ay($result,MYSQ L_ASSOC))")

and havingthis warning on the HTML output leads to be impossible to
use header() to, for instance, go back to the post removal page. Is
there any way to know prior to fetching if my result is of and INSERT/
UPDATE/DELETE instead of a SELECT query?
Nov 21 '07
21 3706
Knut Krueger wrote:
Michael Fesser schrieb:
>.oO(Knut Krueger)
>>withour talking abut the SQL problem - see the other guys it should
be possible to prvent the error message with
$data = @mysql_fetch_ar ray($result,MYS QL_ASSOC))

I do not know whether it is working with
mysql_fetch_a rray($result,MY SQL_ASSOC))
but it is working with @mysql_query and @mysql_num_rows

Using '@' is really bad style in most cases. It suppresses the error
message instead of fixing it.

Micha
but it is better to supress one error instead of setting error_reporting
off, isn`t it?
Regards Knut
It's better to not cause the error in the first place.

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===

Nov 23 '07 #11
Jerry Stuckle schrieb:
Knut Krueger wrote:
>Michael Fesser schrieb:
>>.oO(Knut Krueger)

withour talking abut the SQL problem - see the other guys it should
be possible to prvent the error message with
$data = @mysql_fetch_ar ray($result,MYS QL_ASSOC))

I do not know whether it is working with
mysql_fetch_ array($result,M YSQL_ASSOC))
but it is working with @mysql_query and @mysql_num_rows

Using '@' is really bad style in most cases. It suppresses the error
message instead of fixing it.

Micha
but it is better to supress one error instead of setting
error_reportin g off, isn`t it?
Regards Knut

It's better to not cause the error in the first place.
Just one question to the sql problem.
where is technical the difference (count of SQL branches cpu cycles
etc.) to look for an entry suppress the error if, it is not there and
branch to the "error routine" instead using an other PHP-SQL call to
look for the record without error, and branch to the same "error
routine"? Both ways seems to be equal in the result.

Regards Knut
>
Nov 24 '07 #12
Knut Krueger wrote:
Jerry Stuckle schrieb:
>Knut Krueger wrote:
>>Michael Fesser schrieb:
.oO(Knut Krueger)

withour talking abut the SQL problem - see the other guys it should
be possible to prvent the error message with
>
>
$data = @mysql_fetch_ar ray($result,MYS QL_ASSOC))
>
I do not know whether it is working with
mysql_fetch _array($result, MYSQL_ASSOC))
but it is working with @mysql_query and @mysql_num_rows

Using '@' is really bad style in most cases. It suppresses the error
message instead of fixing it.

Micha
but it is better to supress one error instead of setting
error_reporti ng off, isn`t it?
Regards Knut

It's better to not cause the error in the first place.

Just one question to the sql problem.
where is technical the difference (count of SQL branches cpu cycles
etc.) to look for an entry suppress the error if, it is not there and
branch to the "error routine" instead using an other PHP-SQL call to
look for the record without error, and branch to the same "error
routine"? Both ways seems to be equal in the result.

Regards Knut
>>
CPU cycles have nothing to do with it. This is all about good
programming techniques.

It is much better to not make the call you know is going to cause an
error in the first place. The way you're doing it is just sloppy
programming. Such techniques are problems just waiting to happen.

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===

Nov 24 '07 #13
CPU cycles have nothing to do with it. This is all about good
programming techniques.
sure are CPU cycles and therefore SQL queries a question especially at
an internetserver.
It is much better to not make the call you know is going to cause an
error in the first place. The way you're doing it is just sloppy
programming. Such techniques are problems just waiting to happen.
If the record is more than 50% available, then there are less sql
queries with the suppress error method otherwise with the other method
is better.
I started programming with assembler and 8068 processors and in this
time everybody must take care about CPU and memory usage.

And if the CPU usage (means CPU instructions) was less with suppress
error it was a must to use this. That's why it is possible to suppress
errors.
In both cases the error handling was important but it was in different ways.
and using the @ including an error handling should not a bad programming
style if the usage of the server is more less.

Therefore I my mind there is still the question which way is with less
cpu usage. That's not the question for one user, but for 1000 users
simultaneously

Regards Knut
>
Nov 25 '07 #14
Knut Krueger wrote:
>CPU cycles have nothing to do with it. This is all about good
programming techniques.
sure are CPU cycles and therefore SQL queries a question especially at
an internetserver.
Nope, the reason for doing it correctly has nothing to do with CPU cycles.
>It is much better to not make the call you know is going to cause an
error in the first place. The way you're doing it is just sloppy
programming. Such techniques are problems just waiting to happen.

If the record is more than 50% available, then there are less sql
queries with the suppress error method otherwise with the other method
is better.
No it is not. It is stupid and sloppy. And anyone on one of my
projects who insisted on writing such crappy code would be looking for
another job.

You've been told the correct way to do it - have two functions, one for
SELECT statements and one for others.
I started programming with assembler and 8068 processors and in this
time everybody must take care about CPU and memory usage.
Damn youngster. I was programming a good 15 years before that. Try a
mainframe with 4,000 bytes (not 4K) of core memory and clock rates in
the 100's of kHz range. That describes the first system I was on.

But those days are long gone.
And if the CPU usage (means CPU instructions) was less with suppress
error it was a must to use this. That's why it is possible to suppress
errors.
Do you see a performance problem? I don't think so. But your way takes
up more time than necessary.
In both cases the error handling was important but it was in different
ways.
and using the @ including an error handling should not a bad programming
style if the usage of the server is more less.
No, error handling is not the important thing here. Writing good code
is. Which means not doing what causes the error in the first place.
Therefore I my mind there is still the question which way is with less
cpu usage. That's not the question for one user, but for 1000 users
simultaneously

Regards Knut
>>
Doing it the right way and not causing the error in the first place.
Anything else is just plain sloppy or lazy.

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===

Nov 25 '07 #15
..oO(Knut Krueger)
>CPU cycles have nothing to do with it. This is all about good
programming techniques.
sure are CPU cycles and therefore SQL queries a question especially at
an internetserver.
An if-branch or a function call really mean nothing to the CPU. But as
said elsewhere in this thread, it would be better to use two separate
functions, one for SELECT, another for INSERT/UPDATE/DELETE. This avoids
the problem right from the beginning. Couldn't be more efficient.
>It is much better to not make the call you know is going to cause an
error in the first place. The way you're doing it is just sloppy
programming. Such techniques are problems just waiting to happen.

If the record is more than 50% available, then there are less sql
queries with the suppress error method otherwise with the other method
is better.
Huh? The DB queries are the same. The difference is how the results (or
better the non-results) are handled.
>I started programming with assembler and 8068 processors and in this
time everybody must take care about CPU and memory usage.
PHP is not assembler, it's a much more abstract language. Optimization
in PHP starts on the algorithms, not on single CPU instructions or
language constructs. Google "premature optimization" if you want.
>In both cases the error handling was important but it was in different ways.
and using the @ including an error handling should not a bad programming
style if the usage of the server is more less.

Therefore I my mind there is still the question which way is with less
cpu usage. That's not the question for one user, but for 1000 users
simultaneous ly
If you run into performance problems, use a profiler to find the real
bottlenecks. It will definitely not be the error handling.

Micha
Nov 25 '07 #16
Jerry Stuckle schrieb:
>
Damn youngster. I was programming a good 15 years before that. Try a
mainframe with 4,000 bytes (not 4K) of core memory and clock rates in
the 100's of kHz range. That describes the first system I was on.

But those days are long gone.
>And if the CPU usage (means CPU instructions) was less with suppress
error it was a must to use this. That's why it is possible to suppress
errors.
Hi Grandpa ;-)
maybe you did some programming of VGA interfaces with more than on 64 Kb
segment in the past. It was a common and good style do disable the
integer overflow error during direct writing into the memory. (means for
1 line of code)

Why? The program needs *after* writing in the memory, therefore after
the integer overflow the branch to switch the memory page.
Preventing the error before would cause double and useless if -else
branches and would slow down the system.

That's my biggest part of knowledge and I am still programming those old
machines, because they are still in use and partially non exchangeable.

Back to SQL (and that's not my filed of expertise): I have one sql query
where normally (means nearly 100%) is an result after the sql query. I
have to branch depending on the results.

Why should I branch to the same code with an additional SQL query before
instead of suppressing the error and using one big switch case selection
and one of them is the error branch. In both cases there is an used and
working error procedure.

It is the individual responsibility to use the @ in very minor cases and
thinking about the consequences, but back to the OP in this case I
would agree to determinate whether there is better to determinate before
whether it is INSERT, UPDATE or DELETE. This would use the right
resources for that branch
Do you see a performance problem?
I was told form owner of an internet server farm that there are
performance problems on shared internet server, and on standalone with
hundreds of parallel accesses, especially in the MySQL part.
In his mind they could be minimized with better coding, means using the
queries in the very important branch, without losing of security.

Regards Knut

Nov 27 '07 #17
Knut Krueger wrote:
Jerry Stuckle schrieb:
>>
Damn youngster. I was programming a good 15 years before that. Try a
mainframe with 4,000 bytes (not 4K) of core memory and clock rates in
the 100's of kHz range. That describes the first system I was on.

But those days are long gone.
>>And if the CPU usage (means CPU instructions) was less with suppress
error it was a must to use this. That's why it is possible to
suppress errors.

Hi Grandpa ;-)
maybe you did some programming of VGA interfaces with more than on 64 Kb
segment in the past. It was a common and good style do disable the
integer overflow error during direct writing into the memory. (means for
1 line of code)

Why? The program needs *after* writing in the memory, therefore after
the integer overflow the branch to switch the memory page.
Preventing the error before would cause double and useless if -else
branches and would slow down the system.

That's my biggest part of knowledge and I am still programming those old
machines, because they are still in use and partially non exchangeable.

Back to SQL (and that's not my filed of expertise): I have one sql query
where normally (means nearly 100%) is an result after the sql query. I
have to branch depending on the results.

Why should I branch to the same code with an additional SQL query before
instead of suppressing the error and using one big switch case selection
and one of them is the error branch. In both cases there is an used and
working error procedure.
As others here have tried to tell you - you should have two functions.
One you use for SELECT statements, where you need the results returned.
The other for queries other than SELECT. The program calls the
appropriate function.
It is the individual responsibility to use the @ in very minor cases and
thinking about the consequences, but back to the OP in this case I
would agree to determinate whether there is better to determinate before
whether it is INSERT, UPDATE or DELETE. This would use the right
resources for that branch
This has nothing to do with using @ to block the error. It has
EVERYTHING to do with not creating the error in the first place.

Everyone here has told you the same thing. But you're being stubborn
and insisting on writing crappy code anyway.
Do you see a performance problem?
I was told form owner of an internet server farm that there are
performance problems on shared internet server, and on standalone with
hundreds of parallel accesses, especially in the MySQL part.
In his mind they could be minimized with better coding, means using the
queries in the very important branch, without losing of security.

Regards Knut
So? Why are you intentionally writing crappy code and knowingly causing
errors?

And you're just shooting in the dark as to what the problem is. Find
the real problem and fix it. It is most probably not in the processing
of the mysql_query() calls. Much more likely it's bad database design
and/or tuning.

And are you sure you always need all the results? What happens if a
query returns 10K rows? Retrieving all the rows and putting them in an
array itself takes time. Unless you have a need to cache the results
locally, you're causing delays in your code.

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===

Nov 27 '07 #18
Jerry Stuckle schrieb:
>Why should I branch to the same code with an additional SQL query
before instead of suppressing the error and using one big switch case
selection and one of them is the error branch. In both cases there is
an used and working error procedure.

As others here have tried to tell you - you should have two functions.
One you use for SELECT statements, where you need the results returned.
The other for queries other than SELECT. The program calls the
appropriate function.
Jerry, you snipped the wrong part:
but back to the OP in this case I would agree to determinate whether there is better to determinate before whether it is INSERT, UPDATE or DELETE. This would use the right resources for that branch
you see full acknowledge

I answered to Michael:
>Using '@' is really bad style in most cases. It suppresses the error
message instead of fixing it.
but it is better to supress one error instead of setting error_reporting off, isn`t it?
Normally I set error_reporting (E_ALL);
so I would like to see all errors
and you answered:
>
It's better to not cause the error in the first place.
And after that the tread goes the wrong way
I am using the @ f.e in one way.
There are tables which are proved after the registration process
f.e are there values in a couple of fields, is the additional table
inserted and filled etc.
So I tried to fix any error "in the first place"
If the table with id XY is not present it is an really unrealistic error
caused by manual deleting the table with phpmyadmin.

But this error is included in the proof function from those selected
data before updating the data.

So could you give me an good explanation why I should test whether the
table is existent and update the data after a positive answer, except
that I realize the error two lines earlier one times in 10 years?

and at least I did not say anything else than Michael

Knut

Nov 28 '07 #19
Knut Krueger wrote:
Jerry Stuckle schrieb:
>>Why should I branch to the same code with an additional SQL query
before instead of suppressing the error and using one big switch case
selection and one of them is the error branch. In both cases there is
an used and working error procedure.

As others here have tried to tell you - you should have two functions.
One you use for SELECT statements, where you need the results
returned. The other for queries other than SELECT. The program calls
the appropriate function.
Jerry, you snipped the wrong part:
>but back to the OP in this case I would agree to determinate whether
there is better to determinate before whether it is INSERT, UPDATE or
DELETE. This would use the right resources for that branch

you see full acknowledge

I answered to Michael:
>>Using '@' is really bad style in most cases. It suppresses the error
message instead of fixing it.
but it is better to supress one error instead of setting
error_reportin g off, isn`t it?

Normally I set error_reporting (E_ALL);
so I would like to see all errors
and you answered:
>>
It's better to not cause the error in the first place.

And after that the tread goes the wrong way
In general, it's also a bad idea to have error_display enabled in a
production system. It can show other things about your system when
there are problems - things you don't necessarily want known (i.e.
contents of SQL statements). But it's necessary for development.
>
I am using the @ f.e in one way.
There are tables which are proved after the registration process
f.e are there values in a couple of fields, is the additional table
inserted and filled etc.
So I tried to fix any error "in the first place"
If the table with id XY is not present it is an really unrealistic error
caused by manual deleting the table with phpmyadmin.
People shouldn't be deleting needed tables in a system. Or, if it's an
optional table, see if it exists before accessing it (SHOW TABLES).
But this error is included in the proof function from those selected
data before updating the data.
??? I don't understand this part.
So could you give me an good explanation why I should test whether the
table is existent and update the data after a positive answer, except
that I realize the error two lines earlier one times in 10 years?
But this has nothing to do with the original question. And if something
occurs 1 time in 10 years due to operator error, I wouldn't consider it
a problem.
and at least I did not say anything else than Michael

Knut


--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===

Nov 28 '07 #20

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
3848
by: Reply via newsgroup | last post by:
Folks, When performing an update in mysql (using PHP), can I find out how many records were matched? mysql_affected_rows() won't work... and I have the following problem that I thought I could resolve with a simple function: Example: I have 50records - I want to update a selection of the recods - some,
0
6460
by: Gordon | last post by:
I have 2 tables t and t1. In this case, t1 is a copy of t. I want to delete rows from t1 based on criteria on the t table and a relationship between t ad t1 (in this case the id column). In the results below, I would think that the delete should have deleted row 1 {1 5 me) and not row 3 (1 5 they) when I run this statement delete t1 from t, t1 where t.id = t1.id and t.id=1 and t.name = 'me'; Any ideas on why row 2 is deleted?
0
3527
by: Lenz Grimmer | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi, MySQL 4.0.14, a new version of the popular Open Source/Free Software Database, has been released. It is now available in source and binary form for a number of platforms from our download pages at http://www.mysql.com/downloads/ and mirror sites.
4
867
by: Ka | last post by:
I install a mysql server in default installation with latin charset, but I want to use GBK(a chinese charset), so that I can store and search chinese words directly. so, I download, unpack and then rewrite the mysql.spec and then recompile the package mysql-3.23.56-1.80.src.rpm. first, this file contains some files: # rpm2cpio mysql-3.23.56-1.80.src.rpm |cpio -t
0
3264
by: I.P. | last post by:
Hi, it's my story. I have two 4.0.14 mysql server on one machine with win XP Professional polish version. First acts as master: on port 3300 Second acts as slave: on port 3301 below my configuration:
0
2146
by: I.P. | last post by:
No one has replied to my post. ----- Original Message ----- From: "I.P." <jancio_wodnik@wp.pl> To: <mysql@lists.mysql.com> Sent: Monday, August 18, 2003 1:01 PM Subject: mysql 4.0.14 + replication + windows XP PROF Hi, it's my story.
13
1963
by: miker2 | last post by:
HI, I'm having trouble writing to a MySql db using python and the MySQLdb module. Here is the code: import MySQLdb base = MySQLdb.connect(host="localhost", user="blah", passwd="blah", db="test_py") cursor = base.cursor() cursor.execute("INSERT INTO table (field) VALUES (int)")
1
15391
by: Ike | last post by:
Recently, I began using a different MySQL verver (i.e. different machine as well as different version#, going from 4.12a to 4.1.9 max). The following query used to work: select firstname, lastname, from associates where username like 'nancianne' but now fails with: "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'from associates
1
5285
by: PowerLifter1450 | last post by:
I've been having a very rough time installinig mySQL on Linux. I have been following the instructions form here: http://www.hostlibrary.com/installing_apache_mysql_php_on_linux Everytime I get to #./configure it goes through all of the preparing tables and starting mysqlServer and daemon, but than immediaetly says "mysql ended" -- I try to do #make right after anyway, but I get the error "No targets specified and no makefile found" -- Any...
0
9622
marktang
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10107
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8939
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7464
isladogs
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6718
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5360
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4017
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3611
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2853
bsmnconsultancy
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.