473,388 Members | 1,499 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,388 software developers and data experts.

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("SELECT * FROM temp_stories");

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

while($row = mysql_fetch_array($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("SELECT * FROM temp_stories",$dbi);

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

while($row = mysql_fetch_array($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 2815
On Wed, 14 Dec 2005 10:42:56 -0500, Sugapablo <ru**@REMOVEsugapablo.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_db($dbname);

$res = mysql_query("SELECT * 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("SELECT * 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_identifier

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.uk :: 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
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...
3
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...
0
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...
39
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...
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 -------------------------------------------------------------------------------- ...
0
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...
3
by: fantomel | last post by:
<?php /* Create the mysql class_exists */ class mysql {
5
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...
1
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
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...
0
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...

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.