I keep getting a :
Warning: mysql_error(): supplied argument is not a valid MySQL-Link resource in /home/bogdan/public_html/work/database/CData.php on line 105
respectively: line 117
This is my code in the class:
Code: Select all
class CSql
{
var $sqlHost;
var $sqlUser;
var $sqlPass;
var $sqlDbName;
var $sqlError;
var $sqlHandler;
var $sqlLink;
// function constructor
function CSql()
{
$this->sqlHost = "localhost";
$this->sqlUser = "root";
$this->sqlPass = "";
$this->sqlDbName = "DnD";
$this->sqlError = "";
}
// function connect
function Open($sqlHost="",$sqlUser="",$sqlPass="",$sqlDbName ="")
{
if ($sqlHost != "") $this->sqlHost = $sqlHost;
else $sqlHost = $this->sqlHost;
if ($sqlUser != "") $this->sqlUser = $sqlUser;
else $sqlUser = $this->sqlUser;
if ($sqlPass != "") $this->sqlPass = $sqlPass;
else $sqlPass = $this->sqlPass;
if ($sqlDbName != "") $this->sqlDbName = $sqlDbName;
else $sqlDbName = $this->sqlDbName;
$this->sqlHandler=mysql_connect($sqlHost,$sqlUser,$sqlPass);
if (!$this->sqlHandler)
{
return($this->GetError());
//exit;
}
else
{
$this->sqlUse =mysql_select_db($this->sqlDbName,$this->sqlHandler);
if ($this->sqlUse)
{
return true;
}
else
{
return ($this->GetError());
mysql_close($this->sqlHandler);
//exit;
}
}
}
//// create database
function CreateDb($sqlDbName)
{
$this->sqlHandler = mysql_query("create database $sqlDbName");
if (! $this->sqlHandler)
{
return $this->GetError();
mysql_close($this->sqlHandler);
//exit;
}
else
{
$this->sqlDbName = $sqlDbName;
return true;
}
}
/////
function GetError()
{
$this->sqlError=mysql_error("$this->sqlHandler"); // this is line 105
if ($this->sqlError)
{
return("$this->sqlError");
}
else return true;
}
/////
function Close()
{
mysql_close("$this->sqlHandler"); //this is line 117
}
}This from where I run it:
Code: Select all
include "CData.php";
$sqlCon = new CSql();
$sqlCon->Open("localhost","aaa","","DnD");
$sqlCon->CreateDb("alfa");
$sqlCon->Close();User aaa can not create a database;
Use root instead of aaa. error still applies so
Any help is greately apreciated.
Regards