Linux - ServerThis forum is for the discussion of Linux Software used in a server related context.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
$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.
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.