By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,948 Members | 795 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,948 IT Pros & Developers. It's quick & easy.

how does mysql_errno work?

P: n/a

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 {
-------------------------

Jul 17 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
lk******@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


Jul 17 '05 #2

P: n/a
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

Jul 17 '05 #3

P: n/a
.oO(lk******@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
Jul 17 '05 #4

P: n/a
>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
Jul 17 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.