LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 12-09-2006, 12:13 PM   #1
radiodee1
Member
 
Registered: Oct 2006
Location: New York
Distribution: Debian
Posts: 675
Blog Entries: 11

Rep: Reputation: 36
php mysql db code question


Does anybody know about php and mysql? I ran both on an old XP installation, and now I'm trying to move all the db files over to linux. I'm using Debian 3.1 and apache2... php 4 and mysql along with phpmyadmin. I moved my db files over from my windows partition, and can look at the contents of the files with phpmyadmin. This makes me think I moved them OK.

I start my php aplication from my browser using localhost. It seems my php application can read from the first table fine, even multiple times from the first table, then when the application tries to read for the first time from another table (in the same database) I get an error. mysql_select_db() has trouble selecting the database, so the next line, mysql_query() doesn't work.

Code:
//this is from the second file

mysql_select_db($DBname, $link); // this line fails
$Result = mysql_query($sql, $Link);
There is another wrinkle. The two tables are accessed in totally different files. I seperated the code in order to maintain order, but after the first table is accessed program control changes to a different file, and then the second table (from the same database) is accessed. I establish the link with mysql_connect() all over again in the second file.

I was working on XP with php5. I don't know if this is a problem. I am prepared to go through my code and change lines one by one (in fact I expect to) but only when it makes sense. I would like a php.ini setting or something that will make this work.

Last edited by radiodee1; 12-09-2006 at 05:44 PM.
 
Old 12-11-2006, 12:34 AM   #2
Wim Sturkenboom
Senior Member
 
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Ubuntu 12.04, Antix19.3
Posts: 3,794

Rep: Reputation: 282Reputation: 282Reputation: 282
And what is the error? One thing I notice is that you use $link and $Link.
 
Old 12-11-2006, 06:29 AM   #3
radiodee1
Member
 
Registered: Oct 2006
Location: New York
Distribution: Debian
Posts: 675

Original Poster
Blog Entries: 11

Rep: Reputation: 36
The actual code looks like this:
Code:
	$Link = mysql_connect($host, $user, $password);
	if(!mysql_select_db($DBname, $Link))
	{
		print("'mysql_select_db()' Error Here in<br>\n");
		print("game_resume.php<br>\n");
		exit;
	}
		
	$sql = "SELECT * from pwdlist WHERE usernum = '0'";

	// use query with link
	if(!$Result = mysql_query($sql, $Link))
	{
		print("Removed Select Statement in game_resume");
		exit;
	}
my program prints the error on the 4th line; "mysql_select_db() Error Here in game_resume.php". game_resume.php is the name of the second file.

BUT it doesn't matter right now!! In an attempt to fix this problem I tried to reinstall php4, and in the process messed things up and now do not have working mysql at all. I apologize to anyone reading this. I really messed up!! Sorry.

Last edited by radiodee1; 12-11-2006 at 06:32 AM.
 
Old 12-11-2006, 10:15 PM   #4
Wim Sturkenboom
Senior Member
 
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Ubuntu 12.04, Antix19.3
Posts: 3,794

Rep: Reputation: 282Reputation: 282Reputation: 282
For when it's working again:
1)
You no not check the result of the connect. If it fails, you don't know and you pass an invalid connection to mysql_select_db.
2)
It's nice to have your own error message, but it does not tell you what goes wrong.
Use of mysql_error() is often more usefull.
 
Old 12-12-2006, 08:22 AM   #5
radiodee1
Member
 
Registered: Oct 2006
Location: New York
Distribution: Debian
Posts: 675

Original Poster
Blog Entries: 11

Rep: Reputation: 36
I got php4 and mysql to work again, but the same exact problem as above appears.

If I take out the if() statements and the personalized error statements, the code looks something like this:

Code:
	$Link = mysql_connect($host, $user, $password);
	mysql_select_db($DBname, $Link);
		
	$sql = "SELECT * from pwdlist WHERE usernum = '0'";

	$Result = mysql_query($sql, $Link);

	$row = mysql_fetch_array($Result);
The error I get says this, and refers to the last line of the code.

Quote:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /var/www/rms/game_resume.php on line 47
I thought it might be my firewall settings, but after disabling the firewall, the problem was not fixed. Any help would be apreciated....

Last edited by radiodee1; 12-12-2006 at 08:26 AM.
 
Old 12-12-2006, 11:15 AM   #6
radiodee1
Member
 
Registered: Oct 2006
Location: New York
Distribution: Debian
Posts: 675

Original Poster
Blog Entries: 11

Rep: Reputation: 36
When I moved my database from Windows to linux I retyped the name of the database folder wrong. I changed an uppercase letter to a lowercase letter. Then when I was trying to get my php scripts to work I must have made the same change on some of my scripts in the declaration for the variable "$DBname". I have gotten everything to work now. ALSO, I tried mysql_error() and it was helpfull. Thanks to everyone who looked at this. Thanks Wim.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP Code in MySQL RodimusProblem Programming 1 02-20-2005 03:55 PM
php mysql question infected Programming 2 10-31-2004 09:50 PM
PHP code question latino Programming 2 08-26-2004 04:57 AM
PHP MySQL code pnh73 Programming 13 09-29-2003 01:56 PM
PHP MySQL code problem pnh73 Programming 3 09-15-2003 01:01 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 09:47 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration