Jump to content

[SOLVED] OOP query problem


env-justin

Recommended Posts

Im retrieving this error.

 

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\wamp\www\cvc\classLibrary\UserLogin.php on line 14

 

When I place the while loop into the runQuery() method it works as planned so I know it is connecting to the database properly. Any suggestions?

 

Thanks!

 

<?php

 

class mysqlConnect

{

 

private $host;

private $conn_user;

private $conn_pass;

private $database;

 

function connect()

{

 

require_once('************');

 

$connection = mysql_connect($this->host, $this->conn_user, $this->conn_pass);

$dbSelect = mysql_select_db("cvc", $connection);

 

if (!$connection)

{

die('Could not connect: ' . mysql_error());

}

 

if (!$dbSelect)

{

  die ('Can\'t use selected database : ' . mysql_error());

}

 

}

 

function runQuery($query)

{

$result = mysql_query($query);

}

 

 

}

 

?>

 

<?php

 

class userLogin

{

function __construct($username, $password)

{

require('classLibrary/MysqlConnect.php');

 

$mysqlConnect = new mysqlConnect;

$conn = $mysqlConnect->connect();

 

$result = $mysqlConnect->runQuery("SELECT username, password, level FROM employees WHERE username='$username'");

 

while ($row = mysql_fetch_array($result))

{

echo $row[0] . $row[1];

}

 

$mysqlConnect->close();

 

}

}

 

?>

Link to comment
https://forums.phpfreaks.com/topic/87156-solved-oop-query-problem/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.