-1

Hello guys i am new here and i look forward to be joining you I have an assingment to finish on PHP which is next to reaching its end, but i am still finding myself struggling about finishing my shopping cart This is for the current database that my cart is using and i would apreciate if someone could help me on this bit

<?php
class database {
    private $host = "";
    private $user = "";
    private $password = "";
    private $database = "";

    function __construct() {
        $conn = $this->connectDB();
        if(!empty($conn)) {
            $this->selectDB($conn);
        }
    }

    function connectDB() {
        $conn = new mysqli("", "", "", "");
        return $conn;
    }

    function selectDB($conn) {
        new mysql_select_db($this->database,$conn);
    }

    function runQuery($query) {
        $result = mysql_query($query);
        while($row=mysql_fetch_assoc($result)) {
            $resultset[] = $row;
        }       
        if(!empty($resultset))
            return $resultset;
    }

    function numRows($query) {
        $result  = mysql_query($query);
        $rowcount = mysql_num_rows($result);
        return $rowcount;   
    }
}
?>
  • *"Error (): The mysql extension is deprecated and will be removed in the future"* - Did you not look up that error before asking? – Funk Forty Niner Mar 12 '16 at 16:01
  • Oh, and [**Can I mix MySQL APIs in PHP?**](http://stackoverflow.com/q/17498216/4577762). Spoiler alert: **no** – FirstOne Mar 12 '16 at 16:07
  • @FirstOne That too. *Oh well.* – Funk Forty Niner Mar 12 '16 at 16:10
  • @Fred-ii-, this coming from an assignment, I sincerely _hope_ that it's not how it's shown in the example from the teacher/course – FirstOne Mar 12 '16 at 16:12
  • @FirstOne Believe me, it *does* come from their 70 yr. old teacher/120 yr. old school and books with a 1/4" crust of dust on the cover. – Funk Forty Niner Mar 12 '16 at 16:13
  • You have to forgive me here guys i am a newbie on PHP and i still have a long way to run on this area, and no this is not coming from any teachers or courses i simply reesearched the whole coding bit and saw it fitting to my purposes, that is all Unfortunately the fact that they are using an older language limits things up so i guess i will probably have to modify my cart aswell as this DB before moving on :( – Ezio Auditore Rui Mar 12 '16 at 16:22
  • @EzioAuditoreRui, don't worry. In the beginning it's hard to find your way into something. Specially since there are a bunch of outdated tutorials out there ^^. Just keep practicing and remember: when things work, you learn. When things don't work, you learn even more... – FirstOne Mar 12 '16 at 18:41
  • Appreciate the kind words my friend :) BTW do you have any example from links that can contain what i seek? In case you know any The only thing that my site is missing is this part, the login bit and all that stuff is sorted out, just have this on my way – Ezio Auditore Rui Mar 12 '16 at 19:59

1 Answers1

0

In your connectDB() function you're using mysqli, so why not use it for other functions as well?

mysqli will be a whole lot better since it provides additional support like prepared statements and transactions.

For PHP version > 5.5, mysql functions are deprecated.

Indrasis Datta
  • 8,692
  • 2
  • 14
  • 32
  • Yeah it is true that mysqli is a much better source of code than its counterpart but on my case upon trying to build a shopping cart i came up with a sample that i saw with the coding on it and i found it most suiting for my site Unfortunately i am new on this so i need to follow examples to build my own – Ezio Auditore Rui Mar 12 '16 at 16:11