473,787 Members | 2,971 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help: mysql_connect() doesn't seem to return resource link indentifier.

I have a small test script connecting to a MySQL database. It seems to
work, unless I try to use the resource link identifier returned by
mysql_connect() ;

This works and returns all the rows in the table:

<?php
include("../config.php");

$dbi = mysql_connect($ dbhost,$dbuname ,$dbpass);
mysql_select_db ($dbname);

$res = mysql_query("SE LECT * FROM temp_stories");

if($dbi)
echo "PASS<BR>";
else
echo "FAIL<BR>";

while($row = mysql_fetch_arr ay($res)) {
echo $row['title']."<br/>";
}
?>
This does NOT work and returns no rows:

<?php
include("../config.php");

$dbi = mysql_connect($ dbhost,$dbuname ,$dbpass);
mysql_select_db ($dbname);

$res = mysql_query("SE LECT * FROM temp_stories",$ dbi);

if($dbi)
echo "PASS<BR>";
else
echo "FAIL<BR>";

while($row = mysql_fetch_arr ay($res)) {
echo $row['title']."<br/>";
}
?>
As you can see, the only change was including ",$dbi" in the mysql_query()
function.

Both scripts echo "FAIL" from the if($dbi) check, yet I do get the rows I
ask for when not including the resource link in mysql_query().

Any idea what's going on here? Everything worked fine before a server
upgrade (which I did not do and don't have the details on).

(Yes, I have tried including the resource link in the mysql_select_db ()
function, but that too causes failure.)

No errors are echoed to the screen even using "or die(mysql_error ())";

--
Sugapablo
http://www.sugapablo.net

Dec 14 '05 #1
2 2837
On Wed, 14 Dec 2005 10:42:56 -0500, Sugapablo <ru**@REMOVEsug apablo.com> wrote:
I have a small test script connecting to a MySQL database. It seems to
work, unless I try to use the resource link identifier returned by
mysql_connect( );

This works and returns all the rows in the table:

<?php
include("../config.php");

$dbi = mysql_connect($ dbhost,$dbuname ,$dbpass);
Add error handling at this point.

$dbi = mysql_connect($ dbhost,$dbuname ,$dbpass)
or die(mysql_error ());

And call error_reporting (E_ALL) first and make sure display_errors is on - no
point turning away any help you can get.
mysql_select_d b($dbname);

$res = mysql_query("SE LECT * FROM temp_stories");

if($dbi)
echo "PASS<BR>";
else
echo "FAIL<BR>";
Why are you testing $dbi this late? You should also test $res here, but you
should have tested $dbi earlier.
$res = mysql_query("SE LECT * FROM temp_stories",$ dbi);

As you can see, the only change was including ",$dbi" in the mysql_query()
function.

Both scripts echo "FAIL" from the if($dbi) check, yet I do get the rows I
ask for when not including the resource link in mysql_query().
The manual has a possible clue:

http://uk.php.net/mysql_query
"link_identifie r

The MySQL connection. If the link identifier is not specified, the last
link opened by mysql_connect() is assumed. If no such link is found, it will
try to create one as if mysql_connect() was called with no arguments. If by
chance no connection is found or established, an E_WARNING level warning is
generated."

Perhaps you have your MySQL database set up so that mysql_connect() with no
args actually succeeds. In which case the first version will succeed (link
identifier missing, so it auto-creates one), whereas the second one is being
passed "false" and so fails immediately?

Bit of a long shot - but could make sense if the default username and password
are set in php.ini, or even your database is wide open and allows null
usernames and passwords (can you even set MySQL up this way?), and it's the
only thing I can think of that's consistent with $dbi being false in BOTH cases
despite one of them actually returning data.
No errors are echoed to the screen even using "or die(mysql_error ())";


Put this check on each and every mysql_ call, not just the mysql_query.
--
Andy Hassall :: an**@andyh.co.u k :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool
Dec 14 '05 #2
On Wed, 14 Dec 2005 19:12:46 +0000, Andy Hassall wrote:
Bit of a long shot - but could make sense


Solved.

The php script was actually failing on the mysql_connect() function, and
then going right ahead and selecting the database and going ahead with the
queries. It would accept any connection that did NOT try to connect with
a password.

That's why it returned a false resource link, and that's why it wuoldn't
query using that link but would query without it.

To fix it, I basically had to reiterate the passwords (enter them again)
into the mysql.user table. I have no idea why as the value in the table
was identical before and after, but it DID work. (Perhaps the privileges
were not flushed during the system upgrade?)
--
Sugapablo
http://www.sugapablo.net

Dec 14 '05 #3

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

Similar topics

6
1937
by: Ciprian Ilie | last post by:
Hi there, If you look at the code below, you will see that I am using a template in order to display some photos on my website. I also have "previous" and "next" buttons/link which increment the PhotoId in my table so you can easily navigate. I only have 35 rows in this particular table, but when you get to the 35th picture, clicking on next takes you to 36 which does not exist. Same when you are on id 1 and click previous.
3
1952
by: spacemancw | last post by:
I'm reading an article on MySQL/PHP at http://hotwired.lycos.com/webmonkey/99/21/index3a_page4.html?tw=programming It's very good for me starting out but I have a question. I'm using OS X Panther 10.3.2 MySQL 4.0.15 PHP 4.3.2 (cli) (built: Sep 13 2003 22:04:20)
0
462
by: aquilo at hotmail.com | last post by:
I have these 3 errors and below are lines 17-19. Any suggestions what I am forgetting? Warning: mysql_select_db(): supplied argument is not a valid MySQL-Link resource in /home/---/public_html/----/register2.php on line 17 Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/---/public_html/----/register2.php on line 18 Warning: mysql_close(): supplied argument is not a valid MySQL-Link
39
3337
by: Mark Johnson | last post by:
It doesn't seem possible. But would the following also seem a violation of the general notions behind css? You have a DIV, say asociated with class, 'topdiv'. Inside of that you have an anchor (and whatever it contains), associated with class, 'a'. Somewhere else in, 'topdiv', there is a span or element (containing whatever), associated with class, 'b'.
8
5483
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 -------------------------------------------------------------------------------- Hello, I have a very simple problem but cannot seem to figure it out. I have a very simple php script that sends a test email to myself. When I debug it in PHP designer, it works with no problems, I get the test email. If
0
5576
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted ******************************************************** For this teeny job, please refer to: http://feeds.reddit.com/feed/8fu/?o=25
3
1500
by: fantomel | last post by:
<?php /* Create the mysql class_exists */ class mysql {
5
4626
by: jkershner | last post by:
I have a js script inside php code that is connected to mysql, the php code is listing the results from the query then, the onmouseover function is supposed to show the description of the title for that specific title, however, the mouseover is displaying all the descriptions for every title. Also, will you let me know if I have code in here that is not needed? I'm very new to php/js <script type="text/javascript" language="JavaScript">...
1
2276
by: chienee | last post by:
here is the code <?php session_cache_limiter('private,must-revalidate'); session_start(); require_once("config.php"); include ("classes/db_functions.php"); include ("classes/display.php");
0
9497
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10169
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...
1
10110
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8993
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
7517
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
5398
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
4067
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
3670
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2894
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.