Altec Posted January 2, 2009 Share Posted January 2, 2009 Well, I knew this was not going to work, but I had to try. Currently I'm sending my queries through this class I made: class dbConnection { public $table_s = NULL; function __construct(/*$link_ident = NULL,*/$server = 'localhost',$user = 'meh',$pass = 'meh') { if(!mysql_connect($server, $user, $pass)) { throw_error('Error connecting to database: '.mysql_error(),E_ERROR); exit; } /*if($link_ident == NULL) { if(!mysql_connect($server,$user,$pass)) { throw_error('Error connecting to database: '.mysql_error(),E_ERROR); exit; } } else { }*/ } function select($database,$table = 'false') { if(!mysql_select_db($database)) { throw_error('Error selecting table "'.$database.'": '.mysql_error(),E_ERROR); exit; } ($table == 'false') ? $this->table_s = NULL : $this->table_s = $table; } function query($mysql_query) { if(!mysql_query($mysql_query)) { throw_error('Error sending data to database: '.mysql_error(),E_ERROR); exit; } return true; } function disconnect() { mysql_close(); } } In the future, I'm hoping to extend this class for other database types, but for right now I'm focusing on the core of the script. Anyway, I'm trying to do this: $d = mysql_fetch_assoc($comm_conn->query($query)); Which returns this: Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in index.php on line 15 How can I resolve this error without losing the class? Link to comment https://forums.phpfreaks.com/topic/139169-solved-supplied-argument-is-not-a-valid-mysql-resource/ Share on other sites More sharing options...
corbin Posted January 2, 2009 Share Posted January 2, 2009 The query() method doesn't return anything. Make it return the value of mysql_query. Link to comment https://forums.phpfreaks.com/topic/139169-solved-supplied-argument-is-not-a-valid-mysql-resource/#findComment-727918 Share on other sites More sharing options...
Altec Posted January 2, 2009 Author Share Posted January 2, 2009 That would work, except: if($comm_conn->query($query)) { echo 'Comment added successfully.'; } How can I check if the query ran? If I return the results, would that count as true? Link to comment https://forums.phpfreaks.com/topic/139169-solved-supplied-argument-is-not-a-valid-mysql-resource/#findComment-727920 Share on other sites More sharing options...
Altec Posted January 2, 2009 Author Share Posted January 2, 2009 Oh, nevermind. Just read the PHP manual in-depth. Link to comment https://forums.phpfreaks.com/topic/139169-solved-supplied-argument-is-not-a-valid-mysql-resource/#findComment-727922 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.