Current location: Hot Scripts Forums » Programming Languages » PHP » Pulling data from MySQl Database w/ PHP?


Pulling data from MySQl Database w/ PHP?

Reply
  #1 (permalink)  
Old 09-25-03, 04:42 PM
dayzeday dayzeday is offline
Newbie Coder
 
Join Date: Sep 2003
Location: Joplin, MO
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Pulling data from MySQl Database w/ PHP?

I need help pulling data from mysql database and discplaying it in a table all rows using a php, command. Here is the command I have been trying to uses and it gives me an error message that it could not connect to database. FYI: this is my learning datbase... nothing important in it at all. Yes! i know the pass word is blank.

<?php
$user="cathelet_DB";
$host="localhost";
$password="";
$database = "property";
$connection = mysql_connect($host,$user,$password)
or die ("couldn't connect to server");
$db = mysql_select_db($database,$connection)
or die ("Couldn't select database"); ?>
<?php
$maxRows_Recordset1 = 10;
$pageNum_Recordset1 = 0;
if (isset($HTTP_GET_VARS['pageNum_Recordset1'])) {
$pageNum_Recordset1 = $HTTP_GET_VARS['pageNum_Recordset1'];
}
$startRow_Recordset1 = $pageNum_Recordset1 * $maxRows_Recordset1;

mysql_select_db(cathelet_DB);
$query_Recordset1 = "SELECT * FROM property";
$query_limit_Recordset1 = sprintf("%s LIMIT %d, %d", $query_Recordset1, $startRow_Recordset1, $maxRows_Recordset1);
$Recordset1 = mysql_query(cathelet_DB) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);

if (isset($HTTP_GET_VARS['totalRows_Recordset1'])) {
$totalRows_Recordset1 = $HTTP_GET_VARS['totalRows_Recordset1'];
} else {
$all_Recordset1 = mysql_query($query_Recordset1);
$totalRows_Recordset1 = mysql_num_rows($all_Recordset1);
}
$totalPages_Recordset1 = ceil($totalRows_Recordset1/$maxRows_Recordset1)-1;
<?php $dbh=mysql_connect ("localhost", "cathelet_DB", "test") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("cathelet_DB");
?>

__________________
I have also used this as the connection line and it says error in line 1 near cathelet_DB

<?php $dbh=mysql_connect ("localhost", "cathelet_DB", "") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("cathelet_DB");
$query="select contact name from property"?>


Maybe you guys will see what I am doing wrong. I appricate any help I can get.
Dayze

Last edited by dayzeday; 09-25-03 at 04:54 PM.
Reply With Quote
  #2 (permalink)  
Old 09-25-03, 05:48 PM
YourPHPPro's Avatar
YourPHPPro YourPHPPro is offline
Community VIP
 
Join Date: Aug 2003
Posts: 430
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by dayzeday
it gives me an error message that it could not connect to database
If it gives you an error check the username, password, server name, and database name. Make sure those are correct (including the CaSe)
Reply With Quote
  #3 (permalink)  
Old 09-26-03, 11:36 AM
dayzeday dayzeday is offline
Newbie Coder
 
Join Date: Sep 2003
Location: Joplin, MO
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by YourPHPPro
If it gives you an error check the username, password, server name, and database name. Make sure those are correct (including the CaSe)
I have and it is correct!
Reply With Quote
  #4 (permalink)  
Old 09-26-03, 08:27 PM
SleeperZ SleeperZ is offline
Newbie Coder
 
Join Date: Jun 2003
Posts: 65
Thanks: 0
Thanked 0 Times in 0 Posts
Looking over your code the only thing I could see that might be causing a slight problem is the in fact "" in the password section, I would advise if your not sending a password through to not even put "" in there.

The code itself is fine, so I would go through and check your user settings for MYSQL.

if ya havn't deleted 'root' as a user yet, try using root as your username, and see if it will connect then.

/SleeperZ
__________________
***Expect the Unexpected***
Reply With Quote
  #5 (permalink)  
Old 10-07-03, 03:34 AM
mdhall's Avatar
mdhall mdhall is offline
Aspiring Coder
 
Join Date: Oct 2003
Posts: 510
Thanks: 1
Thanked 1 Time in 1 Post
Quote:
Originally Posted by dayzeday
I need help pulling data from mysql database and discplaying it in a table all rows using a php, command. Here is the command I have been trying to uses and it gives me an error message that it could not connect to database. FYI: this is my learning datbase... nothing important in it at all. Yes! i know the pass word is blank.

<?php
$user="cathelet_DB";
$host="localhost";
$password="";
$database = "property";
$connection = mysql_connect($host,$user,$password)
or die ("couldn't connect to server");
$db = mysql_select_db($database,$connection)
or die ("Couldn't select database"); ?>
<?php
$maxRows_Recordset1 = 10;
$pageNum_Recordset1 = 0;
if (isset($HTTP_GET_VARS['pageNum_Recordset1'])) {
$pageNum_Recordset1 = $HTTP_GET_VARS['pageNum_Recordset1'];
}
$startRow_Recordset1 = $pageNum_Recordset1 * $maxRows_Recordset1;

mysql_select_db(cathelet_DB);
$query_Recordset1 = "SELECT * FROM property";
$query_limit_Recordset1 = sprintf("%s LIMIT %d, %d", $query_Recordset1, $startRow_Recordset1, $maxRows_Recordset1);
$Recordset1 = mysql_query(cathelet_DB) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);

if (isset($HTTP_GET_VARS['totalRows_Recordset1'])) {
$totalRows_Recordset1 = $HTTP_GET_VARS['totalRows_Recordset1'];
} else {
$all_Recordset1 = mysql_query($query_Recordset1);
$totalRows_Recordset1 = mysql_num_rows($all_Recordset1);
}
$totalPages_Recordset1 = ceil($totalRows_Recordset1/$maxRows_Recordset1)-1;
<?php $dbh=mysql_connect ("localhost", "cathelet_DB", "test") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("cathelet_DB");
?>

__________________
I have also used this as the connection line and it says error in line 1 near cathelet_DB

<?php $dbh=mysql_connect ("localhost", "cathelet_DB", "") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("cathelet_DB");
$query="select contact name from property"?>


Maybe you guys will see what I am doing wrong. I appricate any help I can get.
Dayze
On the fifth line, you have this...
$database = "property";

On the 17th line you have this...
mysql_select_db(cathelet_DB);

Are you sure your username and database names are in the correct places?
Reply With Quote
  #6 (permalink)  
Old 10-07-03, 04:06 AM
dayzeday dayzeday is offline
Newbie Coder
 
Join Date: Sep 2003
Location: Joplin, MO
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Figures it out!

I figure the problem out! A few days ago. Thanks for the input!
Reply With Quote
  #7 (permalink)  
Old 10-07-03, 07:01 AM
YourPHPPro's Avatar
YourPHPPro YourPHPPro is offline
Community VIP
 
Join Date: Aug 2003
Posts: 430
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by dayzeday
I figure the problem out! A few days ago. Thanks for the input!
And the resolution was ...... ?
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP and MySQL ? rob2132 Hot Scripts Forum Questions, Suggestions and Feedback 4 08-29-08 02:22 AM
one-page form/catalog in php, data fed in with .csv file? domaky PHP 2 10-25-03 09:32 AM
Send sms via php and mysql database help meeeeee eggdesign PHP 2 10-03-03 12:29 AM
retrieve data from database vioss PHP 4 08-03-03 04:51 AM
MySQL with PHP question. HELP for a newbie kenfused PHP 3 08-02-03 12:53 AM


All times are GMT -5. The time now is 06:19 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.