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!
class sqlize
{
var $host="localhost";
var $user="root";
var $password="";
function sqlize($databaseName)
{
global $con;
$con=mysql_connect($this->host,$this->user,$this->pass);
$que="mysql_select_db($databaseName,$con)";
if (!$con)
{
echo "Couldn't connect : ".mysql_error();
}
else
{
if(!$que)
{
mysql_query("CREATE DATABASE $name",$con);
}
}
function close()
{
mysql_close($con);
}
}
$demo = new sqlize();
This code is giving error. The error is "Parse error: syntax error, unexpected T_VARIABLE, expecting T_FUNCTION in J:\index.php on line 30".. The error is in creating the instance... I might have done some foolish mistake; I really want to know what's the prob...
class sqlize
{
var $host="localhost";
var $user="root";
var $password="";
function sqlize($databaseName)
{
global $con;
$con=mysql_connect($this->host,$this->user,$this->pass);
$que="mysql_select_db($databaseName,$con)";
if (!$con)
{
echo "Couldn't connect : ".mysql_error();
}
else
{
if(!$que)
{
mysql_query("CREATE DATABASE $name",$con);
}
}
}
function close()
{
mysql_close($con);
}
}
$demo = new sqlize();
This code is giving error. The error is "Parse error: syntax error, unexpected T_VARIABLE, expecting T_FUNCTION in J:\index.php on line 30".. The error is in creating the instance... I might have done some foolish mistake; I really want to know what's the prob...
line 11. use $que=mysql_select_db($databaseName,$con); dont use with quotes.
append } line 30
and
if your class constructor will use parameter, you must use parameter when creating the object.
$demo = new sqlize($dbName);