LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 11-11-2004, 11:22 PM   #1
flamesrock
Member
 
Registered: Aug 2003
Distribution: Gentoo 2006.1
Posts: 405

Rep: Reputation: 30
php: Why Can't I Query Mysql DB??


Ok, I have a database, set up as follows:

It extracts the data from cities contained in a simcity 4 region. The table I'm interested in-- 'regions', in that DB contains the population numbers for an entire region (per row):

id name total_pop total_R total_C total_I vrestrict created modified

1 SimNation_II 2035783 1332966 504280 198537 0 2004-10-22 11:39:39 2004-11-11 03:55:37


Anyways, the code is supposed to connect to mysql, extract these values, and display them, but it returns '0' and NOTHING else for any of the values: http://dyslexitech.com/stats.php

Here is the code:
Code:
<?php

$link = mysql_connect('localhost', 'root', 'blasdfadfs');
if (!$link) {
   die('Not connected : ' . mysql_error());
}

// make simnationII the current db
$db_selected = mysql_select_db('simnationII');
if (!$db_selected) {
   die ('Can\'t use foo : ' . mysql_error());
}
//
$sql = "SELECT * FROM regions"; 
$region = mysql_query($sql); 
//
if (!$region) {
   die('SCORE is unavailable: ' . mysql_error());
}
if ($region) { 
 while ($row = mysql_fetch_row($region)) { 
  echo "<br>";
   echo "
   <div style=\"margin-bottom: 10px; width: 100%; height: 149\">
    <br>
    - <b>Created</b>: {$region['created']}
    <br>
    - <b>Last Updated</b>: {$region['modified']}
    <p>
    - <b>Total Population</b>: ".number_format($region['total_pop'])."
    <br>
    &nbsp;&nbsp;
    <b>R</b>: ".number_format($region['total_R'])."
    <br>
    &nbsp;&nbsp;
    <b>C</b>: ".number_format($region['total_C'])."
    <br>
    &nbsp;&nbsp;
    <b>I</b>: ".number_format($region['total_I'])."
    <p>
    - <b>Total Funds</b>: $".number_format($region['total_money'])."
    <p>
    <div style=\"width:300px; height: 100px; overflow:auto\">
    ".nl2br($region['description'])."
    </div>
    <p>
    ";
   
   // are we making available zip archives of each region?
  
   // do we have config.bmp and terrain maps for this region?

   // close out the div
    echo "
   </div>
   <br>";
   }
 } 
?>
I would greatly appreciate ANY help.

-thanks in advance.

Last edited by flamesrock; 11-11-2004 at 11:23 PM.
 
Old 11-11-2004, 11:39 PM   #2
masand
Guru
 
Registered: May 2003
Location: INDIA
Distribution: Ubuntu, Solaris,CentOS
Posts: 5,522

Rep: Reputation: 58
hi

ry these out!!

see that the database is runnig and listening on a specific port
for this u can portscan then machine

and try browsing ur database from the shell aslo / or any gui

regards
 
Old 11-12-2004, 12:31 AM   #3
flamesrock
Member
 
Registered: Aug 2003
Distribution: Gentoo 2006.1
Posts: 405

Original Poster
Rep: Reputation: 30
Its running alright I checked with phpMyAdmin and also through ssh.

And the mysql port (3306) is open too...

any more suggestions?

-thanks
 
Old 11-12-2004, 12:49 AM   #4
masand
Guru
 
Registered: May 2003
Location: INDIA
Distribution: Ubuntu, Solaris,CentOS
Posts: 5,522

Rep: Reputation: 58
hi there

is this username "root" working fine with PHPmyadmin??
if not try out with blan username and password...

regards
 
Old 11-12-2004, 08:12 PM   #5
cbe
LQ Newbie
 
Registered: Jul 2001
Posts: 19

Rep: Reputation: 0
I think I see your problem,


try using: mysql_fetch_array($region) instead of mysql_fetch_row($region)

mysql_fetch_array() Returns an array that corresponds to the fetched row and is an extended version of mysql_fetch_row()

also

try using: {$row['created']} instead of {$region['created']}

remember that $row is the array, not $region.


mysql_fetch_array() creates an array using $row with each value returned from mysql.

see:
http://us2.php.net/manual/en/functio...etch-array.php
http://us2.php.net/manual/en/function.echo.php



Hope this helps...
 
Old 11-12-2004, 09:46 PM   #6
flamesrock
Member
 
Registered: Aug 2003
Distribution: Gentoo 2006.1
Posts: 405

Original Poster
Rep: Reputation: 30
THANKYOU so much! That did it.

And I was about to give up

And thankyou too masand. (BTW, root does work in phpMyAdmin)
 
Old 11-14-2004, 03:08 PM   #7
marks_linux
LQ Newbie
 
Registered: Jul 2004
Posts: 11

Rep: Reputation: 0
I'd be tempted to set up another mysql user with proper granted permissions pretty soon, and use that for your mysql connection. I have a read-only (select) user and at least one other user with insert etc permissions - save some potential heartache!
 
Old 11-16-2004, 12:36 AM   #8
cryptwizard
Member
 
Registered: Aug 2004
Location: Sydney, Australia
Distribution: Debian Squeeze
Posts: 49

Rep: Reputation: 15
I think the is a place where you need to put a MYSQL_ASSOC flag to return an associative array (an array with named elements ($a["b"] as opposed to $a[0])
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
php mcrypt cookie - mysql query lemack Linux - Security 3 02-09-2005 09:21 AM
php/,mysql problem: can't query JJX Linux - General 4 01-06-2005 05:10 PM
php mysql variable arguments in query. ldp Linux - Software 0 10-26-2004 07:56 AM
PHP MySQL Query Question vi0lat0r Programming 1 07-15-2004 05:02 AM
Mysql/PHP query problem with datetime field. Pcghost Programming 2 11-11-2003 12:24 PM


All times are GMT -5. The time now is 05:37 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration