473,387 Members | 1,592 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Cannot turn off errors from @mysql_connect

Hi All,

I have a script that runs on two servers - one with SQL, and one without.
I have coded it so that it doesn't matter on which server it runs, but when I try to connect (to determine which strategy to follow) with:
Expand|Select|Wrap|Line Numbers
  1. function connect_to_sql_ok() {
  2.     $conn = @mysql_connect($this->mysql_host, $this->mysql_user, $this->mysql_pass) or die('<hr />MySQL Error: ' .mysql_error(). '<hr />'); 
  3.     if ($conn != false) {
  4.         $rs = mysql_select_db($this->mysql_db, $conn);
  5.     }
  6.     return $conn;    
  7. }
.. I get "MySQL Error: Access denied for user blahblah@blah.
This is on the server without MySQL. The same code with access to MySQL runs just fine.

I don't want the error getting printed out - I just want the routine to quietly return FALSE, so that I can get on with the other strategy.

I have set as follows:
error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);

I thought that @ would suppress errors from a function, but it seems not..

Does anyone have any idea?

Thanks..
Nov 26 '08 #1
6 2112
pbmods
5,821 Expert 4TB
Heya, AgentSpanky.

You can try turning off display_errors (PHP: Runtime Configuration - Manual), but this will kill error messages for all errors, and they will still show up in your log.

One idea would be to try checking for mysql's pidfile before attempting to connect (Class: Daemons::PidFile). MySQL generally stores this in the var directory within the installation directory that was specified when MySQL was installed.

Checking for the pidfile will only work if you are running the database on the same machine as your web server.
Nov 26 '08 #2
Hi pbmods,

Agree that probably turning off all errors is not what I want..

I'm not sure if php offers a process ID hook - I can't find one. I looked in the /var/ directory, and the /var/db/ also, but couldn't see anything interesting.

I tried get_loaded_extensions() which "returns the names of all the modules compiled and loaded in the PHP interpreter".
That didn't help much, as mysql has been enabled, but just doesn't exist.

Any other ideas why this particular @ doesn't work?

Thanks.
Nov 26 '08 #3
Markus
6,050 Expert 4TB
Take away the or die() clause at the end of your connection variable.
Nov 26 '08 #4
Hi Markus,

Yep - done that.

My problem isn't how to display or handle the error, but rather that it occurs in the first place.
Any other way of detecting if there is an sql service available that doesn't raise an error when it fails would be ok, too..

Thanks.
Nov 26 '08 #5
Well, I've given up.
I'm now just checking which server its on (with a global variable - yuk!) based on it's URL, and determining behaviour based on that.

Thanks for your comments..
Nov 27 '08 #6
Markus
6,050 Expert 4TB
You could use a try-catch block.
Nov 27 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

10
by: Douglas Buchanan | last post by:
I am using the following code instead of a very lengthly select case statement. (I have a lot of lookup tables in a settings form that are selected from a ListBox. The data adapters are given a...
13
by: Csaba Gabor | last post by:
I'm not talking javascript hara-kiri here. I've got a database of web pages or snippets I've created and I'd like to display them in a table. So on my server (in PHP) I take all the files, and...
8
by: baustin75 | last post by:
Posted: Mon Oct 03, 2005 1:41 pm Post subject: cannot mail() in ie only when debugging in php designer 2005 -------------------------------------------------------------------------------- ...
2
by: AK | last post by:
My understanding is that unlike CHAEK and FOREIGN KEY constraints, we cannot have UNIQUE ones NOT ENFORCED, and the reason is very simple: UNIQUE constraints are implemented as UNIQUE indexes. One...
10
by: Jean-David Beyer | last post by:
I have some programs running on Red Hat Linux 7.3 working with IBM DB2 V6.1 (with all the FixPacks) on my old machine. I have just installed IBM DB2 V8.1 on this (new) machine running Red Hat...
11
by: RdR | last post by:
Hi, I am using Q Replication, I need to set to logging to capture changes on a table but the table has more than 18 characters for the name, I looked at the docs, it mentioned that table names...
4
by: Bazza Formez | last post by:
Hi, Unlike some people I have read about in this news group, I am having trouble turning off debug.... but the error message seems to indicate the opposite. When I set debug="false" in...
19
by: lawrence k | last post by:
How can I find out where my script is outputting to the screen for the first time? My error logs are full of stuff like this: PHP Warning: session_start(): Cannot send session cache...
1
by: Cirene | last post by:
Here's my code: Dim usr As MembershipUser = Membership.GetUser(CType(CType(fvPosterInfo.FindControl("UserNameLabel"), Label).Text, String)) usr.IsApproved = False After I set usr.IsApproved...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...

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.