Okay guys I see what your saying.. I fixed everything you said... I think.
I'm having a new problem now.
First of all thorpe.
What's bad about globals? I've used them quite a bit in past scripts, of course, I'm still learning so nothing major.
Anyway here's how the code looks now
class DB_sql
{
var $dbname
var $servername
var $dbusername
var $dbpassword;
function DB_sql($dbname, $servername, $dbusername, $dbpassword) {
$this->dbname = $dbname;
$this->servername = $servername;
$this->dbusername = $dbusername;
$this->dbpassword = $dbpassword;
}
//You'll never believe what this does
function connect()
{
// global $dbname, $servername, $dbusername, $dbpassword;
//connect to database
$this->id_link = @mysql_connect($this->servername, $this->dbusername, $this->dbpassword);
//check connection
if (!$this->id_link) {
$this->stop('Failed to connect to Mysql Database');
}
//pick database
if (!mysql_select_db($this->dbname, $this->id_link))
{$this->stop('DBconnection failed');
}
}
function query($string)
{
// run query, get id
return mysql_query($string, $this->id_link);
}
function fetch_arr($string)
{
$qid = mysql_query($string, $this->id_link);
while($row = mysql_fetch_array($qid)){
foreach( $row AS $key => $val ){
$record[$key] = $val;
}
}
return $record;
}
function fetch_obj($string)
{
$qid = mysql_query($string, $this->id_link);
return @mysql_fetch_object($qid);
}
function num_rows($qid)
{
//Line up soldiers, we need a haircut I mean headcount
return @mysql_num_rows($qid);
}
function close()
{
//Your not useful to us anymore, good night
return mysql_close($this->id_link);
}
function stop($statement)
{
echo $statement;
}
}
Alright... Now when I run it...
$DB->connect();
$record = $DB->fetch_arr("SELECT * FROM `users` WHERE id = 1");
for ($i = 0; $i <= count($record); $i++) {
echo $i.") ";
echo $record[$i];
echo "<br>------<br>";
}
I get this...
0) 1
1) Par
2) Jonathan
3) Parsons
4) 14f91873bc0cbecf98c0ba7606b6c6b7
5) 4
8) ParXBuster
9) 67899177
10) EW
11) none
12) 1985-12-12
13) ../images/user/Par_sym.gif
14) ../images/user/Par_char.jpg
15) 18
16) 9
17) 1986
18) USA
19) Abstract Artist
20) None. at all
asdf
k
21) Administrator : Founder
22)
23)
24)
25)
26)
27)
28)
29)
30)
31)
32)
33)
34)
35)
36)
37)
38)
39)
40)
41)
42)
43)
44)
This is just from an old Database I had that I used to test a userscript. Is it still looping as you guys said and therefore adding all this extra information in the array or am I doing something else wrong? And if it's still looping... Why?
I'm lost on this.