Question

Won't work on public server mysql_query():

Asked by: ewan69

Hi,

I have a webpage that is running fine on my local server but when i upload it to a shared public server(tried 2) I get this error message returned from my php.

<b>Warning</b>:  mysql_query(): supplied argument is not a valid MySQL-Link resource in <b>/home/********
/public_html/*********i/database.php</b> on line <b>25</b><br />

the code around the error is below, my server at home is ubuntu 9.04 lamp can post both phpinfo() outputs if needed..

Thanks, I am pulling my hair out...

22://Function to query the database.
function db_query($query, $link = 'db_link') 
23:function db_query($query, $link = 'db_link') 
24:{
 
25:global $$link;
 
26:$result = mysql_query($query, $$link) or db_error($query, mysql_errno(), mysql_error());
 
27:return $result;
 
28:}

                                  
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:

Select allOpen in new window

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2009-05-03 at 09:02:46ID24376248
Tags

apache php global var error

Topics

Apache Web Server

,

PHP and Databases

Participating Experts
2
Points
500
Comments
7

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. Cannot compile PHP/MySql, ie MySql not present in PhpInf…
    Have clear run out of ideas on this one. Have read multiple online tuts re how to get it compiled but cannot figure it out. Guess I could uninstall the three and use one of the install packages. Dont want to do this though, too much set up time already. All three component...
  2. MySQL info does not appear phpinfo()-phpmyadmin not …
    Hi, On Win XP, I installed Apache 2.0.58, php 5.1.6 and installed MySQL5.0.24. Php works fine since i can call phpinfo(). Thy Mysql seems to be starting because if I type 'Net START MySQL" in comand line, it tells that mysql already started, however. When i run phpinfo(...
  3. appserv php works on vista, but not phpmyadmin or phpinfo
    I have appserv v 2.5.9 working on my vista machine. If I create a php page, the code works. If I try to go to a page with phpinfo(), I get a blank page. If I got to phpmyadmin I get "Cannot load mysql extension. Please check your PHP configuration. - Documentation"
  4. is there a GUI for mysql server in ubuntu
    is there a GUI for mysql server in ubuntu
  5. <? phpinfo(); ?> dont work
    I`m using PHP + Mysql +Apache and using this: $function = 'mysql_connect'; if (function_exists($function)) { echo $function.' exists'; } else { echo $function.' cannot be found'; } Was getting: "cannot be found" Then i added in httpd.conf (apache) this line: PHP...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: gunnyPosted on 2009-05-03 at 10:21:39ID: 24290535

Hi ewan69,

I guess the code is fine, but the login to the DB did not work (that's why you don't have a valid link ressource!). Please check:

- hostname
- username/password

if you *think* those settings are ok, you should have a look at the return codes for mysql_connect and mysql_select_db! See the sample code below.

Cheers

Gunny

<?php
 
$HOSTNAME = 'localhost';
$USERNAME = 'username';
$PASSWORD = 'password';
$DATABASE = 'database';
 
$link = mysql_connect($HOSTNAME, $USERNAME, $PASSWORD);
if (!$link) {
    die('Could not connect: ' . mysql_error());
}
 
$db_selected = mysql_select_db($DATABASE, $link);
if (!$db_selected) {
    die ('Can\'t use database : ' . mysql_error());
}
 
mysql_close($link);
 
?>

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:

Select allOpen in new window

 

by: ewan69Posted on 2009-05-04 at 01:49:14ID: 24293357

Thanks for your help but nothing wrong with the details. I tried your code and it came up with no errors at all.
My code works on local server and also works on 1 public server but the other 2 just throw the same error. Below is the configure command part of the phpinfo() for one of the servers that doesn't work.

Thanks,

Ewan

'./configure' '--enable-bcmath' '--enable-calendar' '--enable-dbase' '--enable-exif' '--enable-fastcgi' '--enable-ftp' '--enable-gd-native-ttf' '--enable-libxml' '--enable-magic-quotes' '--enable-mbstring' '--enable-pdo=shared' '--enable-soap' '--enable-sockets' '--prefix=/usr' '--with-bz2' '--with-config-file-path=/usr/local/lib' '--with-config-file-scan-dir=/usr/local/lib/php.ini.d' '--with-curl=/opt/curlssl/' '--with-curlwrappers' '--with-freetype-dir=/usr' '--with-gd' '--with-gettext' '--with-imap=/opt/php_with_imap_client/' '--with-imap-ssl=/usr' '--with-jpeg-dir=/usr' '--with-kerberos' '--with-libxml-dir=/opt/xml2' '--with-libxml-dir=/opt/xml2/' '--with-mcrypt=/opt/libmcrypt/' '--with-mhash=/opt/mhash/' '--with-mime-magic' '--with-ming=/opt/ming/' '--with-mysql=/usr' '--with-mysql-sock=/var/lib/mysql/mysql.sock' '--with-openssl=/usr' '--with-openssl-dir=/usr' '--with-pdo-mysql=shared' '--with-pdo-sqlite=shared' '--with-png-dir=/usr' '--with-pspell' '--with-sqlite=shared' '--with-ttf' '--with-xpm-dir=/usr' '--with-xsl=/opt/xslt/' '--with-zlib' '--with-zlib-dir=/usr'

                                              
1:

Select allOpen in new window

 

by: NerdsOfTechPosted on 2009-05-04 at 02:07:21ID: 24293420

Do you have a script that you include that references the connection. If so, you may want to check to see if any directories are references as you may be dealing with a different OS

instead of /home/ you may be dealing with /usr/

etc

 

by: gunnyPosted on 2009-05-04 at 09:29:27ID: 24296670

Hi ewan69,

nerdsoftech could be right if you were using absolute pathnames. But I guess it would not even run on one single external server at that point.

Were you able to have a look at the "mysql_connect" function and see if the returned handle is checked for errors in your code? Putting "mysql_error()" right after it would then describe it all.

Have you access to the error log on the other 2 servers? If so, please have a look at them. They should also include PHP warnings and therefor tell you what you don't see on your webpage (maybe just doing a "show source" on the webpage itself will give you a hint as well though!).

Cheers

Gunny

 

by: ewan69Posted on 2009-05-13 at 06:36:39ID: 24374628

Hi, sorry for leaving it so long to reply...
If I change any log in details I get the first error attached to prove error report is on.

LINE 10:  $$link = mysql_connect($server, $username, $password);

Change the details back to what they should be and I get the problem error back, works on some servers but not others... The php log file on the server just shows the same errror.

LINE 25:$result = mysql_query($query, $$link) or db_error($query, mysql_errno(), mysql_error());


I have other php pages accessing the same database without problems so it must be the methods used in database.php

Thank you all for your help.

**********error with incorrect details*******
<b>Warning</b>:  mysql_connect() [<a href='function.mysql-connect'>function.mysql-connect</a>]: Unknown
 MySQL server host '*********.co.uk' (1) in <b>/home/*******/public_html/taxi/database.php</b>
 on line <b>10</b><br />
Unable to connect to database server!
**********************************************
 
 
**********error on some servers but not others***********
<b>Warning</b>:  mysql_query(): supplied argument is not a valid MySQL-Link resource in <b>/home/******
/public_html/taxi/database.php</b> on line <b>25</b><br />
***********************************************************
 
 
the whole database.php file
 
<?php
 
//Make the database connection.
db_connect() or die('Unable to connect to database server!');
 
 
function db_connect($server = '**********', $username = '********', $password = '**********', $database = '***********', $link = 'db_link') 
{
global $$link;
$$link = mysql_connect($server, $username, $password);
if ($$link) mysql_select_db($database);
return $$link;
}
 
 
//Function to handle database errors.
function db_error($query, $errno, $error) 
{ 
die('<font color="#000000"><b>'.$errno.'-'.$error.'<br><br>'.$query.'<br><br><small><font color="#ff0000">[STOP]</font></small><br><br></b></font>');
}
 
//Function to query the database.
function db_query($query, $link = 'db_link') 
{
global $$link;
$result = mysql_query($query, $$link) or db_error($query, mysql_errno(), mysql_error());
return $result;
}
 
//Get a row from the database query
function db_fetch_array($db_query) 
{
return mysql_fetch_array($db_query, MYSQL_ASSOC);
}
 
//The the number of rows returned from the query.
function db_num_rows($db_query) 
{
return mysql_num_rows($db_query);
}
 
//Get the last auto_increment ID.
function db_insert_id() 
{
return mysql_insert_id();
}
 
 
//Add HTML character incoding to strings
function db_output($string) 
{
return htmlspecialchars($string);
}
 
//Add slashes to incoming data
function db_input($string, $link = 'db_link') 
{
global $$link;
	if (function_exists('mysql_real_escape_string')) 
	{
      	return mysql_real_escape_string($string, $$link);
    	} 
	elseif (function_exists('mysql_escape_string')) 
	{
     	return mysql_escape_string($string);
    	}
return addslashes($string);
}
 
 
?>
                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:

Select allOpen in new window

 

by: gunnyPosted on 2009-05-13 at 15:35:33ID: 24380312

Hi ewan69,

please put the following line right after the "global $$link" line in both functions "db_query" and "db_connect":

echo "You are trying to access link name '".$link."'<br>\n";

The double-dollar sign indicates to PHP it should use the variable named by the string contained inside $link. For example: if $link contains "database_link" then doing "$$link = 1" would assign the value "1" to the variable $database_link.

Since your db-connection seems to succeed, I assume your problem lies with $link changing from db_connect to db_query..... solving that, solves your issue. That variable is probably changed outside of database.php.

Gunny

 

by: ewan69Posted on 2009-05-14 at 06:38:19ID: 31577347

Hi Gunny, thank you very much for your help, nice to have things explained, all working now.
:)
Ewan

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...