The following warnings occurred:
Warning [2] Undefined variable $unreadreports - Line: 26 - File: global.php(961) : eval()'d code PHP 8.2.25 (Linux)
File Line Function
/global.php(961) : eval()'d code 26 errorHandler->error
/global.php 961 eval
/printthread.php 16 require_once



UserSpice
PDO newbie loop question - Printable Version

+- UserSpice (https://userspice.com/forums)
+-- Forum: Miscellaneous (https://userspice.com/forums/forumdisplay.php?fid=28)
+--- Forum: Off-topic Discussions (https://userspice.com/forums/forumdisplay.php?fid=10)
+--- Thread: PDO newbie loop question (/showthread.php?tid=342)



PDO newbie loop question - palmeros - 11-10-2016

Hi
i'm totally new with PDO but i'm thinking it might be good to reuse the userspice connection. so if anyone could give a hint in how i loop out the data i got with below query i would be grateful.

Code:
$clist = DB::getInstance()->query("SELECT * FROM company")
Code:
echo $clist->count()
works just fine but i cant figure out how get that to a foreach or while loop...
Code:
foreach ($clist as $row) {echo $row["xyz"];}
does not work...


PDO newbie loop question - palmeros - 11-10-2016

update:
I found this so i'm up and running
Code:
$x = $query->results();
but i'm still having trouble with swedish umlauts like åäö, i think something like this need to go into db.php:
Code:
array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8")
on line 31.

I also could not find any way of editing my first post so i had to reply to my own post...


PDO newbie loop question - mudmin - 11-10-2016

I will definitely tinker with that. That makes sense to me.


PDO newbie loop question - palmeros - 11-10-2016

if i replace
Code:
array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET SESSION sql_mode = ''"));
with
Code:
array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8")
you get UTF-8 to work, but i suppose the first one need to be there too Smile


PDO newbie loop question - mudmin - 11-12-2016

Get all the classes from 3.2 or 4.1 and copy them into the models folder.

Then edit the config.php file in the models folder and after
require_once("funcs.php");

Add these lines...
require_once("classes/Config.php");
require_once("classes/Cookie.php");
require_once("classes/DB.php");
require_once("classes/Hash.php");
require_once("classes/Input.php");
require_once("classes/Redirect.php");
require_once("classes/Session.php");
require_once("classes/Token.php");
require_once("classes/Validate.php");

Primarily you'll want to use the db class and the input class. You may want to implement the token class.

Just to be sure...if you want to TRY to install 3.2 on your server to see if it works, you can go into the install/install.php file and delete lines 58-64 of the install file and see if it works. It's 50/50 if it will, but it might be worth a 5 minute test.