Please login or register.

Login with username, password and session length
Advanced search  

News:

You need/want an older version of sNews ? Download an older/unsupported version here.

Pages: [1] 2

Author Topic: 1.5.31 text-db  (Read 12911 times)

centered

  • Guest
1.5.31 text-db
« on: May 10, 2007, 02:01:46 PM »

Well I am trying to make 1.5.31 into Dobey's text-db version... and being the PHP-newb I am, I am not getting very far.  So if you want to try it out, be my guest.  I am getting grey hair with it, trying to make it work.  

Here is the code if anyone wants to try and make it work.   Set permissions properly for the inc folder.  API should be 755 and all its files should be the same.  dbs should be 777

http://www.mediafire.com/?a1r2zdjimuy

I think the biggest problems is the script is not accessing or quering the database, either not at all or  properly.



EDIT - just to note - THIS IS NOT A WORKING VERSION!!!
Logged

centered

  • Guest
1.5.31 text-db
« Reply #1 on: May 10, 2007, 07:06:30 PM »

My problem is here I think:

I get this using a php debugger

( ! ) Fatal error: Call to a member function query() on a non-object in /var/www/sNews15/snews.php on line 326
Call Stack
#   Time   Memory   Function   Location
1   0.0004   43152   {main}( )   ../index.php:0
2   0.1086   1345960   include( '/var/www/sNews15/snews.php' )   ../index.php:1
3   0.1087   1345984   snews_startup( )   ../snews.php:321
4   0.1087   1345984   connect_to_db( )   ../snews.php:307
5   0.2579   2903432   s( )   ../snews.php:258

when my code is this:
Code: [Select]
// CONNECT TO DATABASE

function connect_to_db() {
// $db = mysql_connect(db('dbhost'), db('dbuname'), db('dbpass'));

// mysql_select_db(db('dbname')) or die(db('dberror'));
$API_HOME_DIR= "./inc/api/";
$DB_DIR = "./inc/dbs/";
if(!defined("API_HOME_DIR")) define("API_HOME_DIR" ,$API_HOME_DIR);
if(!defined("DB_DIR")) define("DB_DIR" ,$DB_DIR);
require_once(API_HOME_DIR . "resultset.php");
require_once(API_HOME_DIR . "database.php");

if(!file_exists(DB_DIR .s('dbname'))) {LINE 258
$db = new Database(ROOT_DATABASE);
$db->query("CREATE DATABASE " .s('dbname'));
}
if(!file_exists(DB_DIR .s('dbname')."/".s('prefix'). "articles.txt")) {
$db = new Database(s('dbname')) or die(s('dberror'));
$db->query("CREATE TABLE ".s('prefix')."articles(id inc, title str, seftitle str, text str, date int, category int default '0', position str, displaytitle str default 'YES', displayinfo str default 'YES', commentable str default '', published int default '1', description_meta str, keyword_meta str)");
}
if(!file_exists(DB_DIR .s('dbname')."/".s('prefix'). "categories.txt")) {
$db = new Database(s('dbname')) or die(s('dberror'));
$db->query("CREATE TABLE ".s('prefix')."categories(id inc, name str, seftitle str, description str, published str default 'YES', catorder str default '0')");
$db->query("INSERT INTO categories(id,name,seftitle,published,catorder) VALUES(0,Home,home,YES,0)");
}
if(!file_exists(DB_DIR .s('dbname')."/".s('prefix'). "comments.txt")) {
$db = new Database(s('dbname')) or die(s('dberror'));
$db->query("CREATE TABLE ".s('prefix')."comments(id inc, articleid int default '0', name str default '', url str, comment str, time int default '0000-00-00 00:00:00', approved str default 'True')");
}
if(!file_exists(DB_DIR .s('dbname')."/".s('prefix'). "settings.txt")) {
$db = new Database(s('dbname')) or die(s('dberror'));
$db->query("CREATE TABLE ".s('prefix')."settings(id inc, name str, value str)");
$db->query("INSERT INTO settings(id,name,value) VALUES ('1', 'website_title', 'sNews CMS')");

$db->query("INSERT INTO settings(id,name,value) VALUES ('2', 'home_sef', 'home')");

$db->query("INSERT INTO settings(id,name,value) VALUES ('3', 'website_description', 'sNews CMS')");

$db->query("INSERT INTO settings(id,name,value) VALUES ('4', 'website_keywords', 'new, site, snews')");

$db->query("INSERT INTO settings(id,name,value) VALUES ('5', 'website_email', 'info@mydomain.com')");

$db->query("INSERT INTO settings(id,name,value) VALUES ('6', 'contact_subject', 'Contact Form')");

$db->query("INSERT INTO settings(id,name,value) VALUES ('7', 'language', 'EN')");

$db->query("INSERT INTO settings(id,name,value) VALUES ('8', 'charset', 'UTF-8')");

$db->query("INSERT INTO settings(id,name,value) VALUES ('9', 'date_format', 'd.m.Y. H:i')");

$db->query("INSERT INTO settings(id,name,value) VALUES ('10', 'article_limit', '3')");

$db->query("INSERT INTO settings(id,name,value) VALUES ('11', 'rss_limit', '5')");

$db->query("INSERT INTO settings(id,name,value) VALUES ('12', 'display_page', '')");

$db->query("INSERT INTO settings(id,name,value) VALUES ('13', 'display_new_on_home', '')");

$db->query("INSERT INTO settings(id,name,value) VALUES ('14', 'display_pagination', '')");

$db->query("INSERT INTO settings(id,name,value) VALUES ('15', 'num_categories', 'on')");

$db->query("INSERT INTO settings(id,name,value) VALUES ('16', 'approve_comments', '')");

$db->query("INSERT INTO settings(id,name,value) VALUES ('17', 'comments_order', 'ASC')");

$db->query("INSERT INTO settings(id,name,value) VALUES ('18', 'comment_limit', '30')");

$db->query("INSERT INTO settings(id,name,value) VALUES ('19', 'word_filter_enable', '')");

$db->query("INSERT INTO settings(id,name,value) VALUES ('20', 'word_filter_file', '')");

$db->query("INSERT INTO settings(id,name,value) VALUES ('21', 'word_filter_change', '')");

$db->query("INSERT INTO settings(id,name,value) VALUES ('22', 'username', '098f6bcd4621d373cade4e832627b4f6')");

$db->query("INSERT INTO settings(id,name,value) VALUES ('23', 'password', '098f6bcd4621d373cade4e832627b4f6')");
}
$db = new Database(s('dbname')) or die(s('dberror'));

}

// STARTUP

function snews_startup() {

connect_to_db();  LINE 307
$db = new Database(s('dbname'));

if (get_id('category') == 'rss') {rss(); die;}

update_articles();

if (isset($_POST['Loginform'])) {

$user = checkUserPass($_POST['uname']);

$pass = checkUserPass($_POST['pass']);

# math captcha check

$calc = (is_numeric($_POST['calc']) == is_numeric($_POST['sum'])) ? $_POST['calc'] : null;

if (md5($user) === s('username') && md5($pass) === s('password') && $calc) {

$_SESSION[db('website').'Logged_In'] = token();

}

}

}

snews_startup();LINE 321


// SITE SETTINGS - grab site settings from database

function s($variable) {
$query = "SELECT value FROM ".db('prefix')."settings WHERE name = '$variable'";

$result = $db->query($query);LINE 326
while ($r = $result->fetch_array()) {$value = $r['value'];}

return $value;

}
Also I can't recreate it, but I got to where Text-db says it cannot read the tables in the setting database...
Logged

Patric Ahlqvist

  • Nobodys perfect, but Im pretty effing close
  • ULTIMATE member
  • ******
  • Karma: 65
  • Posts: 4867
  • I'm a self-made man and worships my creator.
    • p-ahlqvist.com
1.5.31 text-db
« Reply #2 on: May 11, 2007, 08:19:09 AM »

Centered... I can't asist you in anyway, what so ever, not even the lightest, I mearly wanted to applaude you for trying... Keep it up, and eventually there will be someone here to assist you in your endevour
Logged
"It's only dead fish that goes with the flow... "
Updated

centered

  • Guest
1.5.31 text-db
« Reply #3 on: May 11, 2007, 01:34:55 PM »

Thanks Patric.  I know some can't help in any way.  I will try and try and try again...  Dobey,  Albert...anyone... HELP!!! :(

I am stuck on the same problem I had before:

// SMART RETRIEVE FUNCTION

function retrieve($column, $table, $field, $value) {
   $resultSet = $db->executeQuery = ("SELECT $column FROM ".db('prefix')."$table WHERE $field = '$value'");
   while ($r = $resultSet->fetch_array()) {$retrieve = $r[$column];}  LINE 325
   return $retrieve;

}

My error:
 Fatal error: Call to a member function fetch_array() on a non-object in /var/www/sNews15/snews.php on line 325
Call Stack
#   Time   Memory   Function   Location
1   0.0008   43312   {main}( )   ../index.php:0  ?????
2   0.2743   1348472   title( )   ../index.php:5 ???
3   0.5546   1348584   retrieve( )   ../snews.php:349  $categoryName = retrieve('name', 'categories', 'seftitle', $categorySEF);

I guess my big question is, how important is the Smart Retrieve? it's called 21 times, can I replace it with something????
Or what am I doing wrong here? I have tried next()), fetch_array()) with no luck.. even tried a if else statement and I get a logical error....
Code: [Select]
// STARTUP

function snews_startup() {
// connect_to_db();
if (get_id('category') == 'rss') {rss(); die;}
update_articles();
if (isset($_POST['Loginform'])) {
$user = checkUserPass($_POST['uname']);
$pass = checkUserPass($_POST['pass']);
# math captcha check
$calc = (is_numeric($_POST['calc']) == is_numeric($_POST['sum'])) ? $_POST['calc'] : null;
if (md5($user) === s('username') && md5($pass) === s('password') && $calc) {
$_SESSION[db('website').'Logged_In'] = token();
}
}
}
snews_startup();

// SITE SETTINGS - grab site settings from database
function s($variable) {
connect_to_db();
$db = new Database('dbname');
$resultSet = $db->executeQuery = "SELECT value FROM ".db('prefix')."settings WHERE name = '$variable'";
$result = $db->query($resultSet);
while ($r = $resultSet->fetch_array()) {$value = $r['value'];}
return $value;
}

// SMART RETRIEVE FUNCTION
function retrieve($column, $table, $field, $value) {
$resultSet = $db->executeQuery = ("SELECT $column FROM ".db('prefix')."$table WHERE $field = '$value'");
while ($r = $resultSet->fetch_array()) {$retrieve = $r[$column];}
return $retrieve;
}
Changing the code to the below gives me the same error but in the Site settings section... I don't think the database is connecting properly... How do you guys test the connection?
Code: [Select]
// STARTUP

function snews_startup() {

connect_to_db();
$db = new Database('dbname');
if (get_id('category') == 'rss') {rss(); die;}

update_articles();

if (isset($_POST['Loginform'])) {

$user = checkUserPass($_POST['uname']);

$pass = checkUserPass($_POST['pass']);

# math captcha check

$calc = (is_numeric($_POST['calc']) == is_numeric($_POST['sum'])) ? $_POST['calc'] : null;

if (md5($user) === s('username') && md5($pass) === s('password') && $calc) {

$_SESSION[db('website').'Logged_In'] = token();

}

}

}

snews_startup();


// SITE SETTINGS - grab site settings from database

function s($variable) {
$resultSet = $db->executeQuery = "SELECT value FROM ".db('prefix')."settings WHERE name = '$variable'";

// $result = $db->query($resultSet);

while ($r = $resultSet->fetch_array()) {$value = $r['value'];}

return $value;

}

// SMART RETRIEVE FUNCTION

function retrieve($column, $table, $field, $value) {
$resultSet = $db->executeQuery = ("SELECT $column FROM ".db('prefix')."$table WHERE $field = '$value'");
while ($r = $resultSet->fetch_array()) {$retrieve = $r[$column];}
return $retrieve;

}
Logged

centered

  • Guest
1.5.31 text-db
« Reply #4 on: May 11, 2007, 02:33:57 PM »

I guess my big questions are these, and they relate to all php gurus mysql, sqlite, text-db, etc:

1.  How would you basically test a connection to a database (more specifically, using snews.php for the devs)
2.  Assuming number 1, can I make a simple function call to test the objects?
ex.
function blah() {
connect_to_db()
$db = new Database('dbname') or die ('dberror')
Select settings table
return line 4
echo line 4
or echo db error
}
( I am new to php please don't yell about the bad php!!)
3.  (relating to #2) How would one normally fix a function call to a non-object, and more so, what does it mean exactly?

I guess if I have a better understanding of what is going on,I can probably pinpoint the problems and work them.
Logged

Keyrocks

  • Doug
  • ULTIMATE member
  • ******
  • Karma: 449
  • Posts: 6019
  • Semantically Challenged
    • snews.ca
1.5.31 text-db
« Reply #5 on: May 11, 2007, 03:01:01 PM »

Like Patric, I cannot help you in any way with this either. Learning to work with MySQL is on my TO-DO list, but it keeps getting pushed further down the list these days. The good thing is that you are sticking with it on your own so far. Take a break now and then to relieve your frustrations and keep at it. Browse the web for simple tutorials on MySQL querying and you will eventually sort it all out. :)
Logged
Do it now... later may not come.
-------------------------------------------------------------------------------------------------
sNews 1.6 MESU | sNews 1.6 MEMU

codetwist

  • Hero Member
  • *****
  • Karma: 50
  • Posts: 940
1.5.31 text-db
« Reply #6 on: May 11, 2007, 04:21:07 PM »

Quote from: centered
3.  (relating to #2) How would one normally fix a function call to a non-object, and more so, what does it mean exactly?
This error means that either something has been wrong before this call already (like creation of object actually failed) or object variable name was mistyped.

For example:

    // You create some object accessible through variable $db
    $db = New Database();

    // You call method (function) defined for that object of class Database()
    $db->query(); // Here everything should be fine if no problems before and query() is valid at all

    // You call method on some $db1 which hasn't been defined before as object like $db was
    $db1->query(); // Here is call on non-object

Note, that code here is just mock-up.

One way to check if object was created is to use it in if () statement

if ($db) {
   echo 'Object created';
}
else {
   echo 'No $db object created';
}
Logged

centered

  • Guest
1.5.31 text-db
« Reply #7 on: May 11, 2007, 06:40:51 PM »

Key, how can you tell I am getting frustrated?!?!?!?1 :rolleyes:

Code, thanks. It helped because:

// SMART RETRIEVE FUNCTION

function retrieve($column, $table, $field, $value) {
//   $resultSet = $db->executeQuery("SELECT $column FROM ".db('prefix')."$table WHERE $field = '$value'");
if ($db) {
   echo 'Object created';
}
else {
   echo 'No $db object created';
}
   while ($r = $resultSet->fetch_array()) {$retrieve = $r[$column];}
   return $retrieve;

}

Gives me this error:

No $db object created
( ! ) Fatal error: Call to a member function fetch_array() on a non-object in /var/www/snews15a/snews.php on line 330
Call Stack
#   Time   Memory   Function   Location
1   0.0002   43128   {main}( )   ../index.php:0
2   0.1066   1345656   title( )   ../index.php:5
3   0.2142   1345768   retrieve( )   ../snews.php:354

Further Uncommenting the queries and results I get a snews screen with No $db object created

Partial Code being here:
Code: [Select]
// STARTUP

function snews_startup() {

connect_to_db();
$db = new Database('dbname');
if (get_id('category') == 'rss') {rss(); die;}

update_articles();

if (isset($_POST['Loginform'])) {

$user = checkUserPass($_POST['uname']);

$pass = checkUserPass($_POST['pass']);

# math captcha check

$calc = (is_numeric($_POST['calc']) == is_numeric($_POST['sum'])) ? $_POST['calc'] : null;

if (md5($user) === s('username') && md5($pass) === s('password') && $calc) {

$_SESSION[db('website').'Logged_In'] = token();

}

}

}

snews_startup();


// SITE SETTINGS - grab site settings from database

function s($variable) {
if ($db) {
   echo 'Object created';
}
else {
   echo 'No $db object created';
}
// $resultSet = $db->executeQuery("SELECT value FROM ".db('prefix')."settings WHERE name = '$variable'");

// while ($r = $resultSet->fetch_array()) {$value = $r['value'];}

return $value;

}

// SMART RETRIEVE FUNCTION

function retrieve($column, $table, $field, $value) {
// $resultSet = $db->executeQuery("SELECT $column FROM ".db('prefix')."$table WHERE $field = '$value'");

if ($db) {
   echo 'Object created';
}
else {
   echo 'No $db object created';
}
// while ($r = $resultSet->fetch_array()) {$retrieve = $r[$column];}
return $retrieve;

}
So knowing this, leads me to believe that the database is being created but not being written to or more importantly, being read.

Further helping, I am getting slight help from the TExt-db forums here:
http://codeforum.ch/index.php/topic,3460.0.html

EDIT  - Finsihing the commenting, the queries from all functions below do not have objects created:
Site settings
Smart retrieve
display categories
display pages
extra content
center
menu articles
new comments
Find cate through SEF ...
Logged

centered

  • Guest
1.5.31 text-db
« Reply #8 on: May 11, 2007, 09:18:55 PM »

Ok I had a revelation

What does the .s and s function do? I know in 1.4, it called the database with a $s so i attributed it to be a variable.  Now in 1.5 the database is called for $db.  If I change the .s and s in the (s(dbname')) and .s('dbname') calls, would that work?

I ask because I tried removing the s and .s from all the dbame, prefix, and dberror calls resulting in the script to creating a new folder under db called dbname with files called prefixarticle.txt.  I am thinking, if I take away the dbs folder and name the database and prefix in the beginning Database functions, maybe I will be moving ahead with the script reading and writing to the database...

What I am thinking is this, if root owns the folder and its files, it can access everything correctly because it knows the paths it sets.  It sounds funny because the paths are set and the database is created with the correct permissions at the start (dbs folder is set to 777 and the script does the work by creating the files and they are all owned by root).  This may be a redundancy, but it may help with the quering problem and the table reading.

I will try it when I get home.

Now another question, and it will show my PHP newbiness.  Is sNews 1.5 done with OOP?  Was this done with 1.4?  I guess what I am trying to get at, when the script is trying to query and object, is the object in the database or within the script?  My assumtion is it would be in the script, with the information contained within the database.  Why I ask is that I can better define where the problem is, if it's within a line within the script or with the database.  I have asked for someone in the text-db forums to review the database definition and the creation function, hence my question in the beginning of this post.  If everything is good, then the error should be in a php call.  I still think it is a DB error more than anything.  Every change I do in the php lines show me a call to a non-object, or a failed fetch or next function.  The error of Php not reading the table assures that, but doesn't help solve the problem.

Sometimes I think I am so close to making this work, then I get some error that holds me back...

Thanks for letting me rant, if one would call it that..
Logged

codetwist

  • Hero Member
  • *****
  • Karma: 50
  • Posts: 940
1.5.31 text-db
« Reply #9 on: May 11, 2007, 09:23:36 PM »

Well, centered, looking at Your code one thing is for sure - if You really want to handle this task then it's right time to look into introductory chapters of php manual. Read about variable scopes, objects, etc ;)

And sNews 1.5 isn't made using OOP, while txt-db library uses it. But that's not a problem.
Logged

centered

  • Guest
1.5.31 text-db
« Reply #10 on: May 11, 2007, 09:30:02 PM »

Thanks codetwist, that is good knowledge on the OOP

Yes I also got a few php books (PHP4 - big book!!, PHP and Mysql for dummies, OOP for PHP5, and a book on Sqlite, which may be my next project but I will read this one without going into it head first like here), so I have alot of reading to take care of!!!
Logged

codetwist

  • Hero Member
  • *****
  • Karma: 50
  • Posts: 940
1.5.31 text-db
« Reply #11 on: May 11, 2007, 09:37:36 PM »

Books ... oh, well, probably Yours are good ones ;) I recall that mines were kind of old right out of the print ;) I think that php own manual available online and for download at php.net is quite good reading for getting up to speed.
Logged

centered

  • Guest
1.5.31 text-db
« Reply #12 on: May 11, 2007, 10:43:33 PM »

I will do that too Code, I sometimes get sidetracked being online.  I like books too so i can bookmark and reference at any given time.  I have a ton of books from Design to web building. The other thing is, I usually can pick up something pretty quick just by playing around after a while, I know most people can do that too.  But with all the logic programming, I don't know if I can pick that up as quickly, so taking time out to dedicate reading will help alot!

Keyrocks, I think I will take that break this weekend... My brain may be fried after this afternoon!!!
Logged

centered

  • Guest
1.5.31 text-db
« Reply #13 on: May 12, 2007, 12:45:37 AM »

OMG!!!!

I just changed the $db in Codetwist's script to db and I get this:

// SMART RETRIEVE FUNCTION

function retrieve($column, $table, $field, $value) {
if (db) {
   echo 'Object created';
}
else {
   echo 'No $db object created';
}
   $resultSet = $db->executeQuery("SELECT $column FROM ".db('prefix')."$table WHERE $field = '$value'");
   while ($r = $resultSet->fetch_array()) {$retrieve = $r[$column];}
   return $retrieve;

}

REsults this:
Object created
( ! ) Fatal error: Call to a member function executeQuery() on a non-object in /var/www/snews15c/snews.php on line 328
Call Stack
#   Time   Memory   Function   Location
1   0.0003   43136   {main}( )   ../index.php:0
2   0.1321   2815888   title( )   ../index.php:5
3   0.2689   2815904   retrieve( )   ../snews.php:353

And then I see 1.6 is coming out soon.... great... :(

Ok so how do I make the resultSet calls work?!?!?!?!?!? I have changed all the $db's to db and I get T errors...
damnit!!

unexpected T_OBJECT_OPERATOR
$resultSet = db->executeQuery("SELECT $column FROM ".db('prefix')."$table WHERE $field = '$value'");

HELP!!!! I think I am so close!!!!!!!!!
Logged

centered

  • Guest
1.5.31 text-db
« Reply #14 on: May 12, 2007, 06:58:22 AM »



Well as you can see, I got alot farther this time around, I get a snews site coming up.

Again I am stuck on a non-object, yet again.  This time I don't know if I can fix...
         $db = new Database(db('dbname')) or die(db('dberror'));

         $result_articles = $db->executeQuery($query_articles);
         $numrows_articles = $resultSet->getRowCount($result_articles); non-object on this line....Codetwist's if then script showed there is an object, but some rewriting of the line may need to completed first....

http://www.mediafire.com/?cduoiz2bhc5
If anyone wants to try...
Logged
Pages: [1] 2