PDA

View Full Version : DB query help


deafboyzaudio
04-02-2013, 12:49 AM
Hello,
I am trying to use a code snippet from vidiscript CMS on a non vidiscript page. The problem is that this code snippet references items that are not defined on non-vidiscript pages. So basically trying to mesh the 2 together but... I lack the coding knowledge to do so.


I have this....
$db->query("SELECT * FROM sitead WHERE adname='ad2'") ; if ($db->numRows() > 0) { $ares = $db->fetch() ; $adtext = $ares['adtext'] ;
}


and I have $db defined via an include higher up in the page...


function db_connect() {
global $db_host,$db_user,$db_password,$db_database ;
$db = new mysql($db_host, $db_user, $db_password, $db_database) ;
if (!$db) die (ERROR);
return $db ;
}



when i try to run the page i get this error
Fatal error: Call to a member function query() on a non-object in C:\xampp\htdocs\index.phpon line 526


line 526 is the first code snippet in this post. I have a feeling I am getting this error because this page uses MYSQL queries and I am trying to run a mysqli or pdo query on the page (not sure which, im that dumb, haha) Totally lost, thank you!

edbr
04-02-2013, 01:02 AM
are you connecting with the data base? and are all your names( datsbase table feld ) correct?
just re read and you are probably correct in your assumption. are you using FETCH_ ALL to return objects?

deafboyzaudio
04-02-2013, 01:13 AM
I have the db connection details included earlier in the script. and i know it works b/c the same DB is used for data immedietly before this part. mysql_select_db($db_database, $dbvidiscript);
$sql = "SELECT * FROM `category` WHERE `ptr` = 0 AND parent = '0' ORDER BY name ASC" ;
$result = mysql_query($sql) or die(mysql_error()) ;
if ($result) {
that is what works earlier in the script.

then using
$db->query("SELECT * FROM sitead WHERE adname='ad2'") ;
if ($db->numRows() > 0) {

does not. not entirely familiar with fetch_all but I did look it up and I believe my problem to be prior to putting the data into an array, like a connection problem with the style of connection im using, but i do know the connection details are correct, checked them.

edbr
04-02-2013, 01:39 AM
ok, not 100% sure but I think you are not returning objects. it not really a mix and match the best features of PDO is perhaps the prepare and try which is major against SQL injection as you have probably read.

edbr
04-02-2013, 01:40 AM
there is a dreamweaver extension for PDO i saw ( or was) but i dont have a link you would have to yahoogle

edbr
04-02-2013, 01:48 AM
here look at this
http://stackoverflow.com/questions/10911757/how-to-use-pdo-to-fetch-results-array-in-php

deafboyzaudio
04-02-2013, 02:27 AM
So I'm a lil confused but is the $db->query type query a PDO query? I have to admit I know very little about pdo and sqli. But with a push in the right direction I can make sure I get everything I'm missing in there.

What all do I need to run a query like that? Like in terms of defining the db, and credentials etc.

edbr
04-02-2013, 02:45 AM
its is code to return an object so is general . this is a saey guide that will give you a start with PDO better than i could.

http://lynx.io/article/pdo-basics

edbr
04-02-2013, 02:47 AM
and here is a dw extension and tut http://www.pziecina.com/design/dreamweaver/pdo_extension.php

deafboyzaudio
04-08-2013, 05:47 PM
Thanks for those tuts. I read them over and installed the extension, I wasnt able to use the DW code but it did give me the hints to get the code i needed to make the vidiscript query work. For any new pages I make i will deff use the DW extension though