how does mysql_errno work?

This is a discussion on how does mysql_errno work? within the PHP Language forums, part of the PHP Programming Forums category; I'm having trouble capturing the error messages from my code which deals with MySql. In the constructor, I was ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 12-15-2004
lkrubner@geocities.com
 
Posts: n/a
Default how does mysql_errno work?


I'm having trouble capturing the error messages from my code which
deals with MySql. In the constructor, I was getting my site's
configuration info, and assigning the name of the database to a class
variable:


----------------------------
function McDatastoreConnectorMySql() {
$controllerForAll = & getController();
$this->resultsObject = & $controllerForAll->getObject("McResults",
"McDatastoreConnectorMySql");
$this->notifyObject = &
$controllerForAll->getObject("SingletonNotify",
"McDatastoreConnectorMySql");

if (is_object($this->resultsObject)) {
if (is_object($this->notifyObject)) {
$config = getConfig();
if (is_array($config)) {
extract($config);

$persistent = $db_persistent;
$db = $db_database;
$this->db = $db_database;
$server = $db_server;
$user = $db_user;
$password = $db_password;
$port = $db_port;
--------------------------




I was then using the variable $this->db and giving it to the function
mysql_errno(). Apparently this is the wrong thing to do. I've changed
my code so that now I'm handing it a link? That doesn't quite make
sense to me - if there is a problem with the database connection, then
there will be no link, yes?








--------------------------
if (stristr($query, 'SELECT') || stristr($query, 'SHOW') ||
stristr($query, 'EXPLAIN') || stristr($query, 'DESCRIBE')) {
$this->pp_queryid = @ mysql_query($query, $this->pp_linkid);
if (is_resource($this->pp_queryid)) {
$this->notifyObject->notify("McDatastoreConnector",
"databaseQuerySuccess");
$this->pp_firstquery = 1;
return $this->pp_queryid;
} else {
if (mysql_errno($this->pp_linkid) > 0) {
$errmsg = 'Query error: ' . mysql_error();
$this->resultsObject->error("In query(), in
McDatastoreConnectorMySql, we were not able to run our query. $errmsg
.. The query was: '$query' .", "McDatastoreConnectorMySql");
$this->notifyObject->notify("McDatastoreConnector",
"databaseQueryError");
$this->error();
}
}
} else {
-------------------------

Reply With Quote
  #2 (permalink)  
Old 12-15-2004
Janwillem Borleffs
 
Posts: n/a
Default Re: how does mysql_errno work?

lkrubner@geocities.com wrote:
> I was then using the variable $this->db and giving it to the function
> mysql_errno(). Apparently this is the wrong thing to do. I've changed
> my code so that now I'm handing it a link? That doesn't quite make
> sense to me - if there is a problem with the database connection, then
> there will be no link, yes?
>


Correct. When a link resource is available, you can pass it as an argument
to the mysql_errno(). When there isn't, just skip it.

You can even skip it in most cases, when you have a link resource available.
See the manual for more info.


JW




Reply With Quote
  #3 (permalink)  
Old 12-16-2004
lkrubner@geocities.com
 
Posts: n/a
Default Re: how does mysql_errno work?

Alright, I looked here:

http://www.php.net/mysql_errno

and clearly the identifier is optional, so I'll just leave it out. Why
would anyone ever need it?


When I was using the database name I got:

Warning: Supplied argument is not a valid MySQL-Link resource in
/home/httpd/vhosts/publicdomainsoftware.org/httpdocs/ppExtras/McDatastoreConnectorMySql.php
on line 164

Reply With Quote
  #4 (permalink)  
Old 12-16-2004
Michael Fesser
 
Posts: n/a
Default Re: how does mysql_errno work?

.oO(lkrubner@geocities.com)

>Alright, I looked here:
>
>http://www.php.net/mysql_errno
>
>and clearly the identifier is optional, so I'll just leave it out. Why
>would anyone ever need it?


You need it if you run multiple connections to database servers
simultaneously.

Micha
Reply With Quote
  #5 (permalink)  
Old 12-16-2004
Gordon Burditt
 
Posts: n/a
Default Re: how does mysql_errno work?

>http://www.php.net/mysql_errno
>
>and clearly the identifier is optional, so I'll just leave it out. Why
>would anyone ever need it?


Because some pages use more than one MySQL connection at the
same time, and need to check for errors on the correct connection.

Why use more than one connection? Several reasons include:

- The purpose of the code is to migrate, merge, or compare data
from one database to another.
- Databases needed are on different servers, or, for future-proofing,
may be on different servers in the future.
- No one login provides sufficient privileges to do what is needed.
- Switching databases before each query, or specifying it in the
query, is a pain.

Gordon L. Burditt
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 09:40 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0