<?php class database { var $connection; /* Creates a connection with the database. @param string: database name */ function db ($name) { $this->connection = new mysqli('localhost',$name,'root',''); if (mysql_connect_errno()) { } } /* Executes queries. @param string: sql query */ function execute($sql) { $result = $this->connection->query($sql); return $result; } /* Disconnnects with the database. */ function disconnect() { $this->connection->close(); } } $db = new database('comicsite'); $db->execute("SELECT * FROM cms_users"); $db->disconnect(); ?>
tresc błędu przy wywołaniu dla linii
<?php $db->execute("SELECT * FROM cms_users"); ?>
to
Cytat
Fatal error: Call to a member function query() on a non-object in db.class.php on line 23
a dla
<?php $db->disconnect(); ?>
to
Cytat
Fatal error: Call to a member function close() on a non-object in db.class.php on line 35