I have 2 files: apix.php and crud.php. I am trying to convert the fetched data from php to a jason print. The issue is that the function does not the results for me to parse in the next section of my code. The CRUD.php: class crud { private $db; function __construct($DB_con) { $this->db = $DB_con; } public function dataview_new($query) { $stmt = $this->db->prepare($query); $stmt->execute(); $users = array(); while($row = $stmt->fetch(PDO::FETCH_ASSOC)){ array_push($users, $row); } return $users; } } the APIX.php: require_once 'crud.php'; $crud = new crud($DB_con); $res = array('error' => false); $action = 'read'; if(isset($_GET['action'])){ $action = $_GET['action']; } if($action == …

Member Avatar
Member Avatar
+0 forum 1

Hi guys, I wonder if you can help. As I've started as a programmer, I've been told I have to practice OO a bit more. I've done the theory, but I think I will have to take another look at it. , Above all though, I have to do exercises. What I'm looking for is for suggestions: things I have to practice are: -Inheritance -Interfaces -Polymorphism -And in general anything to do with OO. Ideally I don't really need to do any complicated exercise, even simple scenarios would do as long as I can put into practice the theory, printing …

Member Avatar
Member Avatar
+1 forum 3

This is a continuation of our basic tutorial on MVC Framework. In this section, we will be creating the template files for both the TBS and the Smarty template engines. **The recap** In [part one](http://www.daniweb.com/web-development/php/tutorials/476695/part-one-php-mvc-framework-understanding-the-basics), we have created application controllers, models, and the one and only lone View class. Once again, please allow me to present few segments of those Classes here. **Main Controller** We will use this as our example. All of our application controllers have the method called index(). If we can recall from part one, we made the parent controller as an abstract class with an abstract …

Member Avatar
Member Avatar
+3 forum 9

Normally you can do this and pass the reference type by reference and the new keyword won't make the variables point to different objects: static void Main(string[] args) { Object origObj = new Object(); ExampleMethod(ref origObj); } void ExampleMethod(ref Object newObj) { //origObj will also reference the newly created object with the following line. origObj and newObj will point to the same object. newObj = new Object(); } I'd like to do this, without using a method to do it: static void Main(string[] args) { Object origObj = new Object(); Object newObj; // something that would mean the same as …

Member Avatar
Member Avatar
+0 forum 3

Although objects collections have a place in the PHP world many years now , their use is now flourishing because more and more PHP programmers turn to OOP. This tutorial is a sequel of https://www.daniweb.com/programming/web-development/tutorials/500118/a-simple-data-layer-for-oop-php-applications (we will refer to it as “previous tutorial”) and https://www.daniweb.com/programming/web-development/tutorials/500118/a-simple-data-layer-for-oop-php-applications , in order to understand what we are doing I would strongly recommend to read those (and even better to make your own tests). Keeping objects of the same class in an array , in PHP isn't something new. We will do a brief explanation of what we will do using arrays , that most …

Member Avatar
Member Avatar
+2 forum 1

Here is what i have to do Create Class CSalary with private member variables string m_strProfession double m_dSalary Constructors:Default,Copy,Explicit Functions: 1/string GetProf(void),double GetSalary(void) 2/SetProf(const string val),SetSalary(const double val) 3/Output(ostream&) and Input(istram&) 4/Operators:<<,>>,=,==,<,double operator*(const CSalary&obj) Create Class CCalcCorr with private member variables: vector<CSalary>m_vCity1//data for city 1 vector<CSalary>m_vCity2//data for city 2 double m_dCorr//correlation coefficient Constructors: Explicit by data filenames string fNmae1,string fName2 CCalcCorr(const string& strFileName1,const string& strFileName2) <profession> <salary> Web Developer 5000 Functions:/I want help for these functions/ Colculate correlation coefficient btw 2 vectors in m_dCorr and return it in dCorr.Return false if can't calculate Formulas: Corr=SUMxy/sqrt(SUMxxSUMyy) where : SUMxx = SUM(City1City1)-SUM(City1)SUM(City1)/n …

Member Avatar
Member Avatar
+0 forum 1

Hello, This tutorial is the next of “[A simple Data Layer for OOP PHP Applications](https://www.daniweb.com/programming/web-development/tutorials/500118/a-simple-data-layer-for-oop-php-applications)” so having read it and made your own tests is needed to understanding what we are doing. So far we have a Db object (child of PDO that standardize and simplifies its use) , a Db factory object (because our web app may need more than one DB object) and Data Workers (for working with data from DB) (there are in the tutorial mentioned above) . We are going to do it in such way that can be implemented without the use of any framework …

Member Avatar
Member Avatar
+4 forum 1

First off, here is the code I will be referencing: package com.airamerica.dataConversion; import com.airamerica.Airports; import com.airamerica.Person; import com.airamerica.Products.Products; import com.airamerica.Products.Tickets; public class FindObject { public static Airports findAirport(String airportCode, Airports [] airportsArray){ Airports airport = null; for(int j = 0; j < airportsArray.length; j++) { if (airportCode.equals(airportsArray[j].getCode())){ airport = airportsArray[j]; break; } } return airport; } public static Tickets findTicket(String productCode, Products[] productArray){ Tickets product= null; String matchCode = null; for(int j = 0; j < productArray.length; j++) { matchCode = productArray[j].getCode(); if (matchCode.equals(productCode)){ product = (Tickets) productArray[j]; break; } } return product; } public static Person findPerson(String personCode, Person[] …

Member Avatar
Member Avatar
+0 forum 1

Hi I am trying to create a update function. But it not updating in the database. Please help me to fix. **Test-2.php** $whereString = ''; $bind = NULL; if(isset($_POST['Submit'])) { if($_POST) { $SCYQ64UKID = $_GET['SCYQ64UKID']; $SCYQ64AVGP = $_POST['SCYQ64AVGP']*100; $searchFields = array('SCYQ64EMAL'=>$_POST['SCYQ64EMAL'],'SCYQ64EV01'=>$_POST['SCYQ64EV01'],'SCYQ64EV02'=>$_POST['SCYQ64EV02'],'SCYQ64EV03'=>$_POST['SCYQ64EV03'],'SCYQ64EV04'=>$_POST['SCYQ64EV04'],'SCYQ64EV05'=>$_POST['SCYQ64EV05'],'SCYQ64EV06'=>$_POST['SCYQ64EV06'],'SCUSER'=>$_POST['SCUSER'],'SCYQ64AVGP'=>$SCYQ64AVGP,'SCYQ64TZ'=>$_POST['SCYQ64TZ'],'SCJOBN'=>gethostname(),'SCPID'=>'SSWEB','SCUPMJ'=>$_POST['SCUPMJ'],'SCUPMT'=>$_POST['SCUPMT']); if($post = array_filter($_POST)) { if($fields = array_intersect_key($searchFields, $post)) { $where = array(); $bind = array(); foreach($fields as $key=>$field) { $where[] = "$key LIKE '%$field%'"; $bind[":$key"] = $_POST[$key]; $gwhere[] = "$key=$field"; $gbind[":$key"] = $_POST[$key]; } //$whereString = ' WHERE ' . implode(' AND ', $where); $gwhereString = implode(',', $gwhere); } $Users = new Users($db); $query = $Users->smipleUpdate('FQ64000',$gwhereString,'SCYQ64UKID='.$SCYQ64UKID); } } } …

Member Avatar
Member Avatar
+0 forum 12

Hi I am trying to display count of a row using function with get values. Please help me to fix the issue **class** class Users { private $conn; private $db_name= "DATABASE"; public function __construct($db) { $this->conn = $db; } /*Join Two Tables with where condition and order by*/ public function getJoinRows($tablen1,$tablen2,$where,$order_by){ $query = $this->conn->prepare("select * FROM $this->db_name.$tablen1,$this->db_name.$tablen2 where $where ORDER BY $order_by DESC"); try { $query->execute(); return $query; }catch(PDOException $e) { die($e->getMessage()); } } /**/ public function transCount($tablen,$whereCondition) { $query = $this->conn->prepare("select count(*) from $this->db_name.$tablen where $whereCondition"); try{ $query->execute(); return $row_count = $query->fetchAll(); }catch(PDOException $e) { die($e->getMessage()); } } } …

Member Avatar
Member Avatar
+0 forum 5

I have created a function. if i provide correct username and password. i am getting a error message as **Sorry, that username / password is invalid !** can any one please help me to fix the issue. **login.php** <?php require 'include/init.php'; $general->logged_in_protect(); if(empty($_POST) === false) { $username = trim($_POST['username']); $password = trim($_POST['password']); if(empty($username)===true || empty($password)=== true) { $errors[] = 'Sorry, But we need your username and passowrd.'; } else { $login = $users->login($username, $password); if($login === false) { $errors[] = 'Sorry, that username / password is invalid'; } else { $_SESSION['user_'] = $login; header('Location: dashboard.php'); exit(); } } } ?> …

Member Avatar
Member Avatar
+0 forum 3

Hi I am trying to connection my database ODBC using function. I am getting an error **Connection error: could not find driver** **mycode is** <?php class Database{ // specify your own database credentials private $host = "servername"; private $db_name = "databsename.schemaname"; private $username = "username"; private $password = "password"; public $conn; // get the database connection public function getConnection(){ $this->conn = null; try{ $this->conn = new PDO("odbc:host=" . $this->host . ";dbname=" . $this->db_name, $this->username, $this->password); }catch(PDOException $exception){ echo "Connection error: " . $exception->getMessage(); } return $this->conn; } } ?> Please help me to fix the issue.

Member Avatar
Member Avatar
+0 forum 12

This tutorial is intended for people who are looking for alternative to PHP template engines like smarty, twig, dwoo, TBS, and others. Not all developers are willing to take the extra efforts needed to learn the template engine syntax. Some are just left behind thinking that PHP is a template engine itself and there is no need for another template engine. Regardless of what you think about PHP, it has been proven that PHP can be written in procedural, OOP, CLI interface, and spaghetti style .In this particular tutorial, I will be demonstrating how to use PHP effectively as a …

Member Avatar
Member Avatar
+7 forum 3

Hi, Reading CodeIgnitier documentation I saw some statements having this form: $this->someword->somefunction(); and I don't know what is that. Is someword an multi-dimensional/associative array? I know that if I create an instance of a class I can access its properties and functions with a single -> operator or with :: operator. But I don't know what means usage of 2 -> parameters. Thanks!

Member Avatar
Member Avatar
+0 forum 1

Hi all, I've been working with PHP, using procedural methods, for several years now, and have begun to explore the object-oriented side of it. While it didn't take me long to understand the potential advantages that come with working in this manner, I'm still having some trouble wrapping my head around doing the things I used to do procedurally in an object-oriented manner. A lot of the tutorials cover the basic applications of classes, properties, and methods, but I'm having trouble applying them to projects I'm working on. For instance, I have a form, that I put a class together …

Member Avatar
Member Avatar
+0 forum 15

Hello everyone. I am currently making some database connection modules in Python inb order to learn Python's approach to OOP and also to lear how to connect to databases via Python. I successfully made a package with modules for postgres, mysql, sqlite3, and MongoDB. The classes simply connect, disconnect and run queries of any type. Everything is working fine now. However I noticed that the code is nearly the same. For example, the connect and disconnect methods are exactly the same. Also, postgress and mysql connections have exactly the same number of attributes. Inheritance came to mind, but some classes …

Member Avatar
Member Avatar
+0 forum 16

Greetings, I'm having problems with my output. Essentially I am just trying to print out any Cat who is over 3 years old and has Claws. But my output keeps printing out either nothing at all or the 3rd cat 3 times. I've struggled with this for hours trying to figure out why.. any ideas? This is my driver java file. It will compile and run just fine but it doesn't work like it is supposed to.. import java.util.Scanner; public class NathanialProg6 { public static void main(String[] args) { Scanner input = new Scanner(System.in); Cat cat1 = new Cat(); Cat …

Member Avatar
Member Avatar
+0 forum 3

I'm trying to write a boolean function that takes two Mytime objects, t1 and t2 as arguments, and returns True if the object falls inbetween the two times. This is a question from the How to Think Like a Computer Scientist book, and I need help. What I've gotten so far: class MyTime: def __init__(self, hrs=0, mins=0, secs=0): self.hours = hrs self.minutes = mins self.seconds = secs def between(t1, t2): if t1 <= t2: return True else: return False I just don't understand how to make a function that uses MyTime objects into the boolean function? Any help would be …

Member Avatar
Member Avatar
+0 forum 4

please tell me in how many ways OBJECT ORIENTED PROGRAMMING is different from procedural programming in JAVA

Member Avatar
Member Avatar
+0 forum 6

**Part One**: Learning the Basic Patterns **Disclaimer**: please pardon my spellogrammatico errors. I am not really a rough draft person. I type and write codes the split seconds as they crossed my mind, otherwise I will get extremely lazy and then will eventually hibernate like a tardigrade. I hope I do not add more confusion to this subject matter. Today is the last day of my very short Spring Break and I pretty much did not do anything productive for days, except for learning the new programming language called hack from facebook. I thought it would be something that I …

Member Avatar
Member Avatar
+3 forum 1

I can't seem to get a response from my query method. I have a database connection from method ping_server and use mysqli as connector. Can anyone help me figure out why I cannot print results from mysqli_fetch_array. dbclass.php class db { private $connection; private $selectdb; private $lastQuery; private $config; function __construct($config) { $this->dbConfig = $config; } function __destruct() { } public function openConn() { try { if($this->dbConfig->connector == "mysqli") { $this->connection = mysqli_connect($this->dbConfig->hostname, $this->dbConfig->username, $this->dbConfig->password); $this->selectdb = mysqli_select_db($this->dbConfig->database,$this->connection); } } catch(exception $e) { echo'Caught Exception:', $e->getMessage(), "\n"; } } public function closeConn() { try { if($this->dbConfig->connector == "mysqli") { mysqli_close($this->connection); …

Member Avatar
Member Avatar
+0 forum 4

I'm trying to modify this code to take advantage of classes and some other oop features. However, I'm struggling with getting beyond the basics. This is the code that I started with which I am trying to change and make more class absed. import glob import os import sys print(os.getcwd()) dir= raw_input(["Please enter directory location of dcp_inspect output"]) print (dir) os.chdir(dir) print(os.getcwd()) cpl = [] content = [] errors = [] contentkind = [] summary = [] for file in glob.glob("*"): try: print (file,'\t Was Successfully Opened') #file = DcpParse() newfile = file print('Scanning...', newfile) data = open(newfile) for each_line …

Member Avatar
+0 forum 0

First things first, the story about this article. Recently I've created an Wordpress Plugin [WordPress - WP - Keywords To Tooltip | CodeCanyon](http://codecanyon.net/item/wp-keywords-to-tooltip/6513598) After a few days, somebody asked me if it's working with Wordpress Multi Site, initially scared, I didn't expect it to be so easy, I've achieved the transition and make it compatible in under an hour. Why ? Because all the code written was OOP, so it was a piece of cake to modify where needed public function _activationHook() { global $wpdb; $query = file_get_contents($this->scriptBasePath . 'model/install.sql'); $query = str_replace($this->database->_table_prefix , $wpdb->base_prefix . $this->database->_table_prefix, $query); $queries = …

Member Avatar
Member Avatar
+2 forum 3

Hi guys, Tomorrow is my theory paper exam of C++ OOP and Data Strucutre. Paper will be based on 50% theory Q/A and 50% on coding implentaion. Can you give me some hints to prepare for this coming exam? PS. I have gone throw all lectures slides and course material, but you know what I am asking for, how can I prepare my se;f to do 100% job? Thanks, Regards, Umer Jamil.

Member Avatar
Member Avatar
+0 forum 1

hlo all, i need to write a code in php oop for registration without using form and data directly goes in the database. i try to write the code for this. i show u that code and help me to correct that or by giving me another code. the database name is # *bhumi_regn* # and there is an error " # Fatal error # : Call to a member function prepare() on a non-object in C:\wamp\www\bhumi regn\ADAO.php on line 20" thanks `ADAO.php` <?php include 'connect.php'; class ADAO { public static function registerUsers($users,$dbh){ try { } catch (PDOException $e) { …

Member Avatar
Member Avatar
+0 forum 6

This started out as `I love PHP traits! I'm going to use them everywhere! ^_^` and now it has turned into a `Thought Exercise / Learning Experience >_<`. Consider the following example: trait TheErrorOfYourWays{ public function booboo(){ echo 'You had a booboo :('; } } trait SpectacularStuff1 { use TheErrorOfYourWays; } trait SpectacularStuff2 { use TheErrorOfYourWays; } class DoSomethingSpectacular { use SpectacularStuff1, SpectacularStuff2; } This results in (obviously): > Fatal error: Trait method booboo has not been applied, because there are collisions with other trait methods on DoSomethingSpectacular. **So my question: How do I resolve method conflicts in traits? Is …

Member Avatar
Member Avatar
+2 forum 6

Having just found 'traits' - see http://www.daniweb.com/web-development/php/threads/468928/php-trait-method-conflicts-trait-inheritance#post2043565 I was wondering whether they could be used to share a DB connection object across disparate classes, or would the old singleton or dependency injection methods still be the way to go? I'd value any views on this.

Member Avatar
Member Avatar
+2 forum 2

Hi All, I am trying to add insert/update and delete to an OOP singleton database connection using public functions like this, not sure if it is correct? example code public function insert($sql){ if($this->_execute= $this->_mysqli->_execute($sql)){ while ($row = $this->_execute->fetch_object()){ $this->_results[] = $row; } $this->_count = $this->_execute->num_rows; } return $this; } //page index.php <?php require_once 'classes/db.php'; function Users(){ $users = DB::getInstance()->query('SELECT UserID, UserFullName, UserEmail, UserLastPassword, UserName, UserActive FROM Users'); if ($users->count()){ foreach ($users->results() as $user){ echo $user->UserName, $user->UserActive,$user->UserLastPassword,'<br />'; } } } Users(); //page db.php <?php class DB { private $_mysqli, $_query, $_results = array(), $_count=0, $_last_id = -1; public static $instance; …

Member Avatar
Member Avatar
+0 forum 17

Hi All, I am trying to connect to a database OOP singleton method. I am getting an error "syntax error, unexpected 'function_construct'" and I unable to find the syntax error in the code. Any help with this would be appreciated. Thanks in advance David // Page: index.php <?php require_once 'classes/db.php'; echo '<pre>', print_r(DB::getInstance()->query('SELECT * FROM Users')->results()), '</pre>'; //classes/db.php <?php //classes/db.php class DB { private $_mysqli, $_query, $_results = array(), $_count=0; public static $instance; public static function getInstance(){ if (isset(self::$instance)){ self::$instance = new DB(); } return self::$instance; } public function_construct(){ $this->_mysqli = new mysqli('localhost','xxxx','xxxxx','db301847341'); if($this->_mysqli->connect_error) { die($this->_mysqli->connect_error); } } public function …

Member Avatar
Member Avatar
+0 forum 5

please can you help me to solve this problem :>>> no develop a bookstore information system. The bookstore manages a collection of books it is selling, book orders, and customers who purchased from the store. A book store also has a counter that accepts cash from book sales. Each book Customer can search for a book by its ID, title, author, publisher, edition, year of publication and price. The book store also records the number of copies available for each book. Customers can order a book from the bookstore. The bookstore needs to keep information about its customers such as …

Member Avatar
Member Avatar
+0 forum 6

The End.