PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
<?
//This is the file that I am using for testing
require_once("sql/mysql.php");
$DB = new MySQL();
$connection = $DB->dbconnect();
$mysql = "SELECT * FROM login";
$query = $DB->dbquery($mtsql);
//fetch all rows
while ($result = $DB->fetchRow($query))
{
$user=$row['user'];
$pass=$row['pass'];
}
echo $user .$pass;
$DB->dbclose();
?>
<html>
<head><title>Login page</title> </head>
<body bgcolor="white">
</body>
</html>
while ($result = $DB->fetchRow($query))//you declare $result as the array
{
$user=$row['user'];//you fetch data from a $row array
$pass=$row['pass'];
}
while ($result = $DB->fetchRow($query))//you declare $result as the array
{
$user=$row['user'];//you fetch data from a $row array
$pass=$row['pass'];
}
aight i changed the small stuffs, dont exacly what u mean by that.
this i changed (typo):
$query = $DB->dbquery($mtsql);
to
$query = $DB->dbquery($mysql);
please use my code and correct me please. much easier as im not that into php just yet. (learning)
while ($result = $DB->fetchRow($query))//you declare $result as the array
{
$user=$row['user'];//you fetch data from a $row array
$pass=$row['pass'];
}
while ($result = $DB->fetchRow($query))//you declare $result as the array
{
$user=$result['user'];
$pass=$result['pass'];
}
EDIT - I have just been testing out simalar code and I got this working using mysql_fetch_array rather than mysql_fetch_row in the class. Don't know whether this suits you but i think the functions are pretty similar
<?php
//This is the file that I am using for testing
require_once("class.DBC.php");
$DB = new MySQL();
$connection = $DB->dbconnect();
$mysql = "SELECT * FROM user";
$query = $DB->dbquery($mysql);
//fetch all rows
while ($result = $DB->fetchRow($query))
{
$user=$result['user']; <----- this dosnt exist in database it sais...
$pass=$result['pass']; <----- this dosnt exist in database it sais...
}
echo $user .$pass;
$DB->dbclose();
?>
<html>
<head><title>Login page</title> </head>
<body bgcolor="white">
</body>
</html>
now i have no idé why it works now instead of before (so dont ask )
Are you using mysql_fetch_row still? I think when I was testing this thats the error I got with mysql_fetch_row. Try mysql_fetch_array again or another similar function
Goofan wrote:ok so i first changed it so that it were result instead of rows and that didnt work so i tried to use array still the same
Why is it ouputting this?
dbconnect(); $mysql = "SELECT * FROM login"; $query = $DB->dbquery($mysql); //fetch all rows while ($result = $DB->fetchArray($query)) { $user=$result['user']; $pass=$result['pass']; } echo $user .$pass; $DB->dbclose(); ?>
Change <? to <?php
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Goofan wrote:it works with the array but i still got this error:
Warning: mysql_close() expects parameter 1 to be resource, null given in C:\Program Files\wamp\www\www\Projektarbete\class.DBC.php on line 28
Line 28 is the end of php " ?> "
know what it means?
O.K. so pass the $connection to the close(). Just read the error and it tells you what to do!
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
function dbclose()
{
mysql_close($this->connection);
}
becouse this is what ive got.
if not then please show me
Where do you set $this->connection?
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
well ill give u both my "pages". If i dont got it then tell me. im not that good with OOP so this is actually a piece of my own code and some taken so that i could understand more.
function dbconnect()
{
$this->connection = mysql_connect($this->host,$this->name,$this->password) or die(mysql_error());
mysql_select_db($this->database,$this->connection);
}
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.