You are here: Re: Help: mysql_connect() doesn't seem to return resource link indentifier. « PHP Programming Language « IT news, forums, messages
Re: Help: mysql_connect() doesn't seem to return resource link indentifier.

Posted by Andy Hassall on 10/25/66 11:34

On Wed, 14 Dec 2005 10:42:56 -0500, Sugapablo <russ@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 :: andy@andyh.co.uk :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация