Pulling data from MySQl Database w/ PHP?

09-25-03, 04:42 PM
|
|
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.
|

09-25-03, 05:48 PM
|
 |
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)
|

09-26-03, 11:36 AM
|
|
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!
|

09-26-03, 08:27 PM
|
|
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***
|

10-07-03, 03:34 AM
|
 |
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?
|

10-07-03, 04:06 AM
|
|
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!
|

10-07-03, 07:01 AM
|
 |
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 ...... ?
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|