#17248 [Com]: # is not a valid MySQL-Link resource

From: Date: Fri, 26 Sep 2003 07:26:34 +0000
Subject: #17248 [Com]: # is not a valid MySQL-Link resource
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-48125@lists.php.net to get a copy of this message
ID: 17248 Comment by: UglyEugen at yahoo dot com Reported By: bbs at c-se dot de Status: No Feedback Bug Type: MySQL related Operating System: Linux Mandrake 8.2 PHP Version: 4.1.2 New Comment: I'm expiriencing the same bug but slightly different OS System: Linux 68.224.76.107 2.4.18-14 #1 Wed Sep 4 13:35:50 EDT 2002 i686 athlon i386 GNU/Linux PHP Version 4.2.2 code which causes error: <?php $db_host = 'localhost'; $db_user = 'db_user'; $db_pass = 'db_password'; $database_name = 'db_name'; $db = mysql_connect($db_host, $db_user, $db_pass) or die(mysql_error()); print "Connected successfully<br>"; mysql_select_db($database_name, $db) or die(mysql_error()); print "Database selected<br>"; ?> Browser's response: Connected successfully Warning: mysql_select_db(): 1 is not a valid MySQL-Link resource in /.../dbcon.php on line 9 Warning: mysql_error(): 1 is not a valid MySQL-Link resource in /.../dbcon.php on line 9 Please, help!!!! Previous Comments: ------------------------------------------------------------------------ [2002-08-04 04:46:59] georg@php.net No feedback was provided. The bug is being suspended because we assume that you are no longer experiencing the problem. If this is not the case and you are able to provide the information that was requested earlier, please do so and change the status of the bug back to "Open". Thank you. ------------------------------------------------------------------------ [2002-05-15 13:45:52] mfischer@php.net Sorry, but this is neither short nor looks self-contained (reference to commonlib.inc). Short is in terms of a few lines, say 10 - 25. If you can't do that, please provide all necessary files for download (via http) and add it to the report, thanks. ------------------------------------------------------------------------ [2002-05-15 10:57:30] bbs at c-se dot de I cut the script down and managed to locate the source of the error but not the reason for this. ------------------------- <? require("commonlib.inc"); error_reporting(E_ALL); $btnSenden = $GLOBALS["btnSenden"]; $btnBearbeiten = $GLOBALS["btnBearbeiten"]; $btnNeuAnlegen = $GLOBALS["btnNeuAnlegen"]; $lstArtLuftfahrzeug = $GLOBALS["lstArtLuftfahrzeug"]; $hidModus = $GLOBALS["hidModus"]; $hidFlugzeug_ID = $GLOBALS["hidFlugzeug_ID"]; $Luftfahrzeug = $GLOBALS["Luftfahrzeug"]; $txtKundenNr = $GLOBALS["txtKundenNr"]; $kdnrClub = $GLOBALS["kdnrClub"]; $hidMusterId = $GLOBALS["hidMusterId"]; // ************** // ** MAIN :-) ** // ************** Create_DB_Connection($verbindung_lfz) OR ErrorMsg("Luftfahrzeug", "Fehler beim Verbindungsaufbau"); // COMMENT: THIS ONE WORKS AND CAUSES THE FIRST TWO DEPRECATED-WARNINGS GetUserData($SID, $row); $txtKundenNr = $row['KundenNr']; ?> [ HTML ...] <? $statement = "SELECT * from Luftfahrzeuge Where KundenNr='$txtKundenNr'"; print "DEBUG_lfz: $statement<br>"; if (! $verbindung_lfz) { print "Holla, keine Verbindung!<br>"; } else { print "Verbindung ok!<br>"; } // COMMENT: THIS ONE DOESN'T WORK ANYMORE SQLExec($statement, $verbindung_lfz, $result_lfz) OR ErrorMsg("Luftfahrzeug", "Fehler bei der Datenabfrage"); Close_DB_Connection($verbindung_lfz) OR ErrorMsg("Luftfahrzeug", "Fehler beim Verbindungsabbau"); [...] ?> ------------------------- I changed SQLExec to ------------------------- function SQLExec($sqlquery, $viaconnection, &$resultset) { $db_base = $GLOBALS["CONST_DB_BASE"]; $retval = 1; $resultset = mysql_db_query($db_base, $sqlquery, $viaconnection) or $retval = 0; // THIS IS NEW if ($retval == 0) { print "DEBUG: (" . mysql_error() . ")<br>"; } return $retval; } ------------------------- In the snippet above I used SQLData: ------------------------- function SQLData($resultset) { return mysql_fetch_array($resultset); } ------------------------- GetUserData does the following: ------------------------- function GetUserData(&$usersid, &$userrow) { $login_ok = 0; if (streq($usersid, "0")) { $login_ok = 0; } else { Create_DB_Connection($verbindung_getuserdata) OR ErrorMsg("GetUserData", "Fehler beim Verbindungsaufbau"); $statement = "SELECT *, DATE_FORMAT(Faelligkeit_Rechnung, '%d.%m.%Y') AS DFaelligkeit_Rechnung, DATE_FORMAT(Verfallsdatum, '%d.%m.%Y') AS DVerfallsdatum, DATE_FORMAT(Faelligkeit_Erinnerung1, '%d.%m.%Y') AS DFaelligkeit_Erinnerung1, DATE_FORMAT(Faelligkeit_Erinnerung2, '%d.%m.%Y') AS DFaelligkeit_Erinnerung2, DATE_FORMAT(Registrierung, '%d.%m.%Y') AS DRegistrierung, DATE_FORMAT(DatumMedical, '%d.%m.%Y') AS DDatumMedical, DATE_FORMAT(Geburtsdatum, '%d.%m.%Y') AS DGeburtsdatum FROM tblKunden, tblSessions WHERE (tblKunden.KundenNr=tblSessions.KundenNr) AND (tblSessions.SessionID='$usersid')"; SQLExec($statement, $verbindung_getuserdata, $resultset_getuserdata) OR ErrorMsg("GetUserData", "Fehler beim Ermitteln der Kundennummer"); if (SQLNumRows($resultset_getuserdata) > 1) { ErrorMsg("GetUserData", "Zuviele Einträge in tblSessions für die aktuelle Kundennummer"); } elseif (SQLNumRows($resultset_getuserdata) < 1) { $usersid = 0; $login_ok = 0; } else { $userrow = SQLData($resultset_getuserdata); $statement = "UPDATE tblSessions SET LetzterZugriff=NOW() WHERE SessionID='$usersid'"; SQLExec($statement, $verbindung_getuserdata, $resultset_getuserdata) OR ErrorMsg("GetUserData", "Fehler beim Aktualisieren der SessionID"); Close_DB_Connection($verbindung_getuserdata) OR ErrorMsg("GetUserData", "Fehler beim Verbindungsabbau"); $login_ok = 1; } } return $login_ok; } ------------------------- If I don't call GetUserData with PHP 4.1.2, everything works fine. Remember: The script works with PHP 4.0.3 no matter if I call GetUserData or not. I would have changed it if it didn't work a year ago. Here's the output of the script: ------------------------- Warning: Undefined index: btnSenden in /var/www/html/dokumente/mitglieder/mygat24/LFZ_Luftfahrzeug.inc on line 5 Warning: Undefined index: btnBearbeiten in /var/www/html/dokumente/mitglieder/mygat24/LFZ_Luftfahrzeug.inc on line 6 Warning: Undefined index: btnNeuAnlegen in /var/www/html/dokumente/mitglieder/mygat24/LFZ_Luftfahrzeug.inc on line 7 Warning: Undefined index: lstArtLuftfahrzeug in /var/www/html/dokumente/mitglieder/mygat24/LFZ_Luftfahrzeug.inc on line 8 Warning: Undefined index: hidModus in /var/www/html/dokumente/mitglieder/mygat24/LFZ_Luftfahrzeug.inc on line 9 Warning: Undefined index: hidFlugzeug_ID in /var/www/html/dokumente/mitglieder/mygat24/LFZ_Luftfahrzeug.inc on line 10 Warning: Undefined index: Luftfahrzeug in /var/www/html/dokumente/mitglieder/mygat24/LFZ_Luftfahrzeug.inc on line 11 Warning: Undefined index: txtKundenNr in /var/www/html/dokumente/mitglieder/mygat24/LFZ_Luftfahrzeug.inc on line 12 Warning: Undefined index: kdnrClub in /var/www/html/dokumente/mitglieder/mygat24/LFZ_Luftfahrzeug.inc on line 14 Warning: Undefined index: hidMusterId in /var/www/html/dokumente/mitglieder/mygat24/LFZ_Luftfahrzeug.inc on line 16 // COMMENT: THESE TWO ARE FROM GetUserData DEBUG_SQLExec: query (SELECT *, DATE_FORMAT(Faelligkeit_Rechnung, '%d.%m.%Y') AS DFaelligkeit_Rechnung, DATE_FORMAT(Verfallsdatum, '%d.%m.%Y') AS DVerfallsdatum, DATE_FORMAT(Faelligkeit_Erinnerung1, '%d.%m.%Y') AS DFaelligkeit_Erinnerung1, DATE_FORMAT(Faelligkeit_Erinnerung2, '%d.%m.%Y') AS DFaelligkeit_Erinnerung2, DATE_FORMAT(Registrierung, '%d.%m.%Y') AS DRegistrierung, DATE_FORMAT(DatumMedical, '%d.%m.%Y') AS DDatumMedical, DATE_FORMAT(Geburtsdatum, '%d.%m.%Y') AS DGeburtsdatum FROM tblKunden, tblSessions WHERE (tblKunden.KundenNr=tblSessions.KundenNr) AND (tblSessions.SessionID='643732d72c264e8c996f05bf64725218')) Warning: mysql_db_query is deprecated; use mysql_select_db() and mysql_query() instead in /var/www/html/include/functions_database.inc on line 100 DEBUG_SQLExec: query (UPDATE tblSessions SET LetzterZugriff=NOW() WHERE SessionID='643732d72c264e8c996f05bf64725218') Warning: mysql_db_query is deprecated; use mysql_select_db() and mysql_query() instead in /var/www/html/include/functions_database.inc on line 100 DEBUG_lfz: SELECT * from Luftfahrzeuge Where KundenNr='10011' Verbindung ok! // COMMENT: THE RESULT FROM GetUserData IS OK BECAUSE WE SEE KundenNr HERE DEBUG_SQLExec: query (SELECT * from Luftfahrzeuge Where KundenNr='10011') // COMMENT: THIS ONE IS FROM THE SQLExec IN THE SCRIPT Warning: mysql_db_query is deprecated; use mysql_select_db() and mysql_query() instead in /var/www/html/include/functions_database.inc on line 100 Warning: 20 is not a valid MySQL-Link resource in /var/www/html/include/functions_database.inc on line 100 DEBUG: () Es ist ein Fehler aufgetreten: Modul: Luftfahrzeug Beschreibung: Fehler bei der Datenabfrage: ------------------------- What I don't understand: First: mysql_db_query seems to return an error in SQLExec but no errormessage for mysql_error? If I ignore the warning from SQLExec, I'll get an error in Close_DB_Connection. Second: GetUserData uses its own connection (Create, Query, Close) with unique variable names. So where's the problem with this: Create connection A Create connection B Query via connection B Close connection B Query via connection A ? Third: Why does it work on 4.0.3 but not on 4.1.2? Please tell me where I make my mistake. I can't believe this to be a bug in PHP anymore. Thanks, Christian ------------------------------------------------------------------------ [2002-05-15 09:26:47] mfischer@php.net It seems like a bug in your code/logic. Please paste a small, self-contained example showing the problem. Also make sure you run everything with error_reporting(E_ALL); ------------------------------------------------------------------------ [2002-05-15 09:19:42] bbs at c-se dot de Hi! I just recently switched an application from Debian Woody with PHP 4.0.3 PL1 to Mandrake Linux 8.2 / PHP 4.1.2 (as an RPM out of the box). The same script that worked fine for over a year now makes trouble on the new machine: /* two function definitions */ Create_DB_Connection($verbindung_lfz) OR ErrorMsg("Module", "connection could not be created"); if ($kdnrClub) { /* GetUserData creates its own connection to the db and closes it after use */ GetUserData($SID, $row); [...] } [...] /* some php-code and some db-queries with $verbindung_lfz but different $result-vars */ [...] if (! $verbindung_lfz) { print "No connection!<br>"; } else { print "Connection ok!<br>"; } SQLExec($statement, $verbindung_lfz, $result_lfz) OR ErrorMsg("Luftfahrzeug", "couldn't get data: " . mysql_error()); The connection still exists because there is the "Connection ok!" message. Right after that my SQLExec blows up and gives Warning: [some number] is not a valid MySQL-Link resource in [...] Later, the connection can't be closed because it does not exist. But why does my connection-check work before I call SQLExec? The SQL-statement is working fine on the console. My query works if I move it to the beginning of the script after the Create_DB_Connection. I replaced my wrapping functions with the original functions-calls but that didn't make a difference. I've got some kind of framework for my database connections. These are the used functions in this excerpt: function Create_DB_connection(&$newconnect) { $db_user = $GLOBALS["CONST_DB_USER"]; $db_host = $GLOBALS["CONST_DB_HOST"]; $db_pass = $GLOBALS["CONST_DB_PASS"]; $retval = 1; $newconnect = mysql_connect($db_host, $db_user, $db_pass) or $retval = 0; return $retval; } function SQLExec($sqlquery, $viaconnection, &$resultset) { $db_base = $GLOBALS["CONST_DB_BASE"]; $retval = 1; $resultset = mysql_db_query($db_base, $sqlquery, $viaconnection) or $retval = 0; return $retval; } So what changed between 4.0.3PL1 und 4.1.2 to cause this behaviour? There are some more scripts and I'd like to have an idea about what I should take care of. Thanks! ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=17248&edit=1

« previous php.bugs (#48125) next »