473,554 Members | 2,171 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

php script can't connect to local mysql, what the heck?

35 New Member
Okay so I am at a loss here. I have a website that I've previously had no trouble connecting to the mysql DB on. I have an include to a connect file with the relevant connection info, and it was working fine until today. I am trying to implement some ajax with the javascript framework mootools (although I don't see how this is causing the problem it started happening right around this time sooo...)

I am sending info from my login form to the processLogin.ph p page, which in turn logs me in and everything, and then is supposed to write new info to the relevant div which sent the call.

But my processLogin page started saying it "couldn't connect to the localhost", which most definitely is not my intent nor have it set it to. So I included the connect.php page on the page itself; nothing. It still had a mistake (occurring right at my first query). So I wrote the connection info directly before the query, and no longer receive that error, but still no data. I echo'd the query and get nothing. So, here is the connect.php code I include in index.php, so it can call it each time:
[PHP]<?php
$dbServer = 'mysql***.secur eserver.net';
$dbDatabase = '****;
$dbUser = '****';
$dbPass = '****';

// Connect to database
$db = mysql_pconnect( $dbServer, $dbUser, $dbPass) or die("Couldn't connect to database due to error in page: " . mysql_error());
mysql_select_db ($dbDatabase, $db) or die("Couldn't select database due to error in page: " . mysql_error()); ?>[/PHP]

Neither of these error message ever appear, btw, meaning the connection is working here.

Here is the code that is throwing the error:
[php]$sql = mysql_query("SE LECT * FROM users WHERE username=" . $username . " AND password=" . $password . " AND activated='1'") ;
echo 'sql=' . $sql;
$login_check = mysql_num_rows( $sql);[/php]

Where I echo sql=$sql, I get "sql=" and nothing else, and this is the error message:

Warning: mysql_num_rows( ): supplied argument is not a valid MySQL result resource in /blahblahblah on line 51.
And finally, when I include the connect info instead of writing it straight to the page (and I'm including it to the page, as opposed to index.php [where I normally include it]):

Warning: mysql_query(): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) in /webpage on line 47
Sorry for the lengthy first post, but I wanted to get all relevant info out there.
My guess is it's because I'm calling for the page through ajax, but I can't figure out how that causes the problem or how to fix it. Any ideas or help MUCH appreciated!
Nov 19 '06 #1
4 3752
ronverdonk
4,258 Recognized Expert Specialist
Let's start with the select statement. I assume that the userid and password are CHAR fields, so you'll have to include them within quotes. The entire select string incl. the variables van be code in one double-quote enclose string. So your statement is:
[php]$sql = mysql_query("SE LECT * FROM users WHERE username='$user name' AND password='$pass word' AND activated='1'")
or die("Invalid query: " . mysql_error());
[/php]
Ronald :cool:
Nov 19 '06 #2
d3vkit
35 New Member
Let's start with the select statement. I assume that the userid and password are CHAR fields, so you'll have to include them within quotes. The entire select string incl. the variables van be code in one double-quote enclose string. So your statement is:
[php]$sql = mysql_query("SE LECT * FROM users WHERE username='$user name' AND password='$pass word' AND activated='1'")
or die("Invalid query: " . mysql_error());
[/php]
Ronald :cool:
Ah, you're right about that... but it still didn't quite fix it. When I write the connect script into the page, it works; when I include the script, it doesn't. Is this some sort of scope that I don't understand? Can it not connect to an included script with ajax maybe?
Well, it works, but not as well as I'd like, but I suppose it's all the same. Thank you for your help; I can't believe I didn't see that.
Nov 20 '06 #3
ronverdonk
4,258 Recognized Expert Specialist
Is the connect script, the one that you include, in a different path from the script that includes it and, if so, are you correctly backtracking or forward tracking the include. E.g. if the connect script is one dir below (child dir) the including script, you must include it as [php]include('connec t/dbinclude.php"' );[/php].
If it is in a dir above (parent dir) the including script you define [php]include('../dbinclude.php"' );[/php].
If it is in another dir down from the one above you (sibling dir), you do [php]include('../connect/dbinclude.php"' );[/php].
Is that the reason?

Ronald :cool:
Nov 20 '06 #4
d3vkit
35 New Member
Is the connect script, the one that you include, in a different path from the script that includes it and, if so, are you correctly backtracking or forward tracking the include. E.g. if the connect script is one dir below (child dir) the including script, you must include it as [php]include('connec t/dbinclude.php"' );[/php].
If it is in a dir above (parent dir) the including script you define [php]include('../dbinclude.php"' );[/php].
If it is in another dir down from the one above you (sibling dir), you do [php]include('../connect/dbinclude.php"' );[/php].
Is that the reason?

Ronald :cool:
I'm sorry I never replied to you; I was going to that night, then got busy and it never let up apparently.

Just wanted to say thanks for the suggestions. I went to the code, did the include as I normally would (backtracking to the scripts directory), and it worked no problem. No idea what I was doing wrong before, but it's all sorted out now. Seemed I had done this in the first place, but oh well. I do appreciate thehelp; I learned that I don't need to include variables in my mysql call with periods. Forgot what that's called. Dang it.
Dec 14 '06 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

5
2875
by: steve | last post by:
Hi, I finally figured out the best way to synch local and remote script folders, containing many php script files. What I used to do before was try to ftp all the changed files, etc. which was tedious and often broke. It was also very slow. What I do now is to pkzip the folder up, ftp the pkzip’ed data to remote, and then unzip it...
1
2577
by: Peter Nikolaidis | last post by:
Greetings, I am attempting to get MySQLdb 0.9.2 installed on Mac OS 10.2 with a Fink distribution of Python 2.2.2. I have seen only a few posts on the subject, some of them relate to "conflicting header files," but I don't know what to do about conflicting header files, or where I would find them, and once I found them, which ones to...
0
2399
by: Bill Hernandez | last post by:
Hi, I've been writing software on the mac since 1987, but am brand new at unix/php/mysql, and that's where I'm headed so I'm reading everything I can get my hands on, but like anything else there's going to be a learning curve, that having been said... I followed the install instructions at http://entropy.ch , and was able to get mySql &...
0
3276
by: Ian | last post by:
Dear All, I just downloaded & installed MYSQL. It seemed to work and I can start it and enter my password and change a directory but that is about all. I have been ready and playing "hit & miss" all afternoon and it seems to have something to do with the "mysql_install_db" not being installed correctly -- I have tried multiple installs...
3
17789
by: Pugi! | last post by:
On a freshly installed Fedora C3 (incl. webserver apache php mysql) i get the following problem when connecting to mysql through a browser (phpMyAdmin): : #2002 Can't connect to local MySQL server through socket /var/lib/mysql/mysql.sock On the website of MySQL this error is mentioned but I found no solution. In /var/log/messages the...
1
121514
by: jiing | last post by:
Now let me describe what I have done and my purpose: Originally, I want to user ports to install phpBB But I found that phpBB doesn't support mysql 5.x (but the ports installed mySQL 5.0.0 alpha) so I deinstall mysql5-server and mysql5-client And then I install mysql41-server and mysql41-client on FreeBSD 5.3 by ports but now , mysql is...
5
1747
by: news | last post by:
I have a new situation I'm facing and could use a suggestion or two, as I don't seem to be able to think in the abstract very well. We have a local server which holds all of our image files. We have a remote server that runs our public Web server and mySQL database. I need to be able to run a script that will: Read the contents of a dir on...
14
6076
by: mistral | last post by:
Need php script to create mySQL database programmatically; since hosting configuration may not allow create database from script, script also need eliminate/rewrite all restrictions in appropriate places in that hosting.
1
8695
by: sasimca007 | last post by:
Hi friends, I installed mysql in ubuntu but, i don't know how to connect to that mysql. Actually we connect to postgresql by psql command, but when i tried to connect mysql with mysql command but it displaying this error: ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) ...
0
7605
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7808
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8047
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7570
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7893
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6156
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5441
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3556
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
845
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.