View Full Version : MYSQL connection problem
kgrimm3678
10-25-06, 01:43 PM
I have a php script that calls a mysql database. I am a student at a local community college and used a different connection string to connect to our localhost at school. Powweb gave me the following connection string to use for my powweb account.
"Driver={SQL Server}; Server=mysql15.powweb.com; Database=myDatabaseName; UID=myUsername; PWD=myPassword"
On our school server account I wrote a php page and I used a include 'db.inc'; statement for my connection information. Now I don't really know where to put the above statement or how to use it. I put it on my db.inc page, changed the generic statement above to my user information, but it doesn't work. I took off the "'s but that's a no go too.
Where does the Driver statement go? Thank you,
tbonekkt
10-25-06, 02:09 PM
I don't quite understand the connection string; however, you cannot remotely connect to the mysql servers. Any script that needs to connect to the mysql servers must be uploaded to your PowWeb hosting account.
kgrimm3678
10-25-06, 02:11 PM
I have in my powweb folder a script called upload.php and it contains include 'db.inc' which is also in my powweb folder. I need to understand how to make the connection to my powweb mysql database which is called cnyhistory_images. I am trying to transfer my pages which I created for a school assignment into my powweb account.
tbonekkt
10-25-06, 02:13 PM
You'll need to use the mysql_connect function: http://www.php.net/mysql_connect
kgrimm3678
10-25-06, 03:30 PM
This is my connect.inc
$db= mysql_pconnect('mysql15.powweb.com', 'username', 'password');
if(!$db)
{ echo 'Error in file, could not connect to database';
exit; }
mysql_select_db('table');
This is from my upload.php file
include 'connect.inc';
$query="INSERT INTO 'table' ('id','staff', 'description', 'upload_date') VALUES (NULL, '$staff', '$description', CURDATE())";
What was that whole connection script that Powweb gave me anyway? Neither works
tbonekkt
10-25-06, 03:37 PM
I have no idea what that connection string you posted earlier is.
Try echoing the mysql_error and go from there.
kgrimm3678
10-25-06, 05:58 PM
I don't get an error. It just doesn't put anything into my table. My file is at cnyhistory.org/Upload_Project/upload1.php and maybe it's not my connection script at all. Powweb sent me off on a wild goose chase with that script "Driver={SQL Server}; Server=MyServerName; Database=myDatabaseName; UID=myUsername; PWD=myPassword" statement. Maybe it's altogether something else.
I have an upload function for the pictures and also a thumbnail creation function which work fine. The images go into a folder in my server, but the corresponding information never makes it to the database.
Thanks,
Karen
mitchind
10-25-06, 06:50 PM
This is my connect.inc
$db= mysql_pconnect('mysql15.powweb.com', 'username', 'password');
if(!$db)
{ echo 'Error in file, could not connect to database';
exit; }
mysql_select_db('table');
This is from my upload.php file
include 'connect.inc';
$query="INSERT INTO 'table' ('id','staff', 'description', 'upload_date') VALUES (NULL, '$staff', '$description', CURDATE())";
What was that whole connection script that Powweb gave me anyway? Neither works
Two questions:
1. Is that the name of your table - 'table'?
2. How do you execute the query - where's the code for that?
You should check for an error right after query executes using mysql_error().
kgrimm3678
10-25-06, 07:26 PM
My username and password are not 'username' or 'password' and my table is not called 'table', I was trying not to give out too much access information for my website and database.
I follow the insert query with a select query which should bring everything out of the database and puts it in a generic table. However, I get nothing returned even if I insert a print_r $results; When I insert mysql_error(). It gives me the statement "Query was empty". This code works perfectly on my school server:
$query="select * from table";
$result=mysql_query($result);
$num_row=mysql_num_rows($result);
echo '<br /><table border=1><tr>';
$i=0;
while($i<mysql_num_fields($result))
{echo '<th>'.mysql_field_name($result,$i). '</th>';
$i++;}
for ($i=0; $i<$num_row; $i++){
echo '<tr>';
$rows=mysql_fetch_array($result, MYSQL_ASSOC);
$col=0;
foreach($rows as $col){
echo '<td>'. $col . '</td>';}
echo '</tr>';}
echo '</table>';
mitchind
10-25-06, 09:46 PM
Then I guess I shouldn't ask if the name of your database is table?
mysql_select_db('table');
But is it the name of your database at least?
And is this what you're trying to do ...
$query="select * from table";
$result=mysql_query($result);
Shouldn't that be ...
$query="select * from table";
$result=mysql_query($query);
It would be much easier to see more of your actual code rather than the snippets you're choosing to show us.
kgrimm3678
10-25-06, 10:23 PM
duh.... yes! I'll try making that obvious error correct. Sometimes I can't see what's right in front of me. Well..... it didn't fix everything, sigh. But that bit of error code gave me an error message which is helpful - I think - maybe, anyway. It says "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''images'' at line 1" but I don't see anything about "images" at line 1. Hummm. Well, it's something to start with anyway. Thanks!
Shouldn't I worry about giving too much information on the web about a database and access? I haven't figured all my code out yet and I don't want to get hacked.
mitchind
10-25-06, 10:30 PM
Don't give out usernames/passwords - and if you leave your db location at mysql## - that should be good enough.
What I'm saying is include more of your code - especially where you're actually calling the query and showing the results.
If you add an echo after your insert sql - you can get a better look at what's actually running - and compare it to what you think is happening.
Good luck on your hunt for the hidden treasure!
kgrimm3678
10-25-06, 11:02 PM
You've been EXTREMELY helpful and although my page is not working yet, my other codes are working on the other pages and updating my database so I now know that my query line is the problem on this upload page. I think it has to do with the required single and double quotes which get my head spinning, but hey! I'm going down the right track anyway. Thank you!
mitchind
10-26-06, 12:23 AM
Alright then .. good luck. I like your spirit.
vBulletin v3.6.0, Copyright ©2000-2009, Jelsoft Enterprises Ltd.