Jump to content

Search the Community

Showing results for tags 'oop syntax'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


  • Welcome to PHP Freaks
    • Announcements
    • Introductions
  • PHP Coding
    • PHP Coding Help
    • Regex Help
    • Third Party Scripts
    • FAQ/Code Snippet Repository
  • SQL / Database
    • MySQL Help
    • PostgreSQL
    • Microsoft SQL - MSSQL
    • Other RDBMS and SQL dialects
  • Client Side
    • HTML Help
    • CSS Help
    • Javascript Help
    • Other
  • Applications and Frameworks
    • Applications
    • Frameworks
    • Other Libraries
  • Web Server Administration
    • PHP Installation and Configuration
    • Linux
    • Apache HTTP Server
    • Microsoft IIS
    • Other Web Server Software
  • Other
    • Application Design
    • Other Programming Languages
    • Editor Help (PhpStorm, VS Code, etc)
    • Website Critique
    • Beta Test Your Stuff!
  • Freelance, Contracts, Employment, etc.
    • Services Offered
    • Job Offerings
  • General Discussion
    • PHPFreaks.com Website Feedback
    • Miscellaneous

Find results in...

Find results that contain...

Date Created

  • Start


Last Updated

  • Start


Filter by number of...


  • Start





Website URL








Donation Link

Found 1 result

  1. I am converting my existing code to a more friendly version for PHP5, and since commands like "mysql_real_escape_string" are being deprecated, I figured I would embrace OOP fully moving forward. The problem I am having is the "nesting" of OOP commands. $db_connection = new mysqli("localhost","db_user","db_pw","db_name"); if(mysqli_connect_errno()){ printf("Connection fails: %s\n", mysqli_connect_error()); } $username = $db_connect->real_escape_string($_POST['username']); $stmt = $db_connection->stmt_init(); .... and so on The problem I am having happen when I want to take it one step further and put all that in a class. class Make_Connection { pivate $db_connection function __construct(){ $this->make_connection(); } public function make_connection(){ $this->db_connection = new mysqli("localhost","db_user","db_pw","db_name"); if(!$this->db_connection){ die("Databse connction failed: %s\n", mysqli_connect_error()); } else { $stmt = $this->db_connection->stmt_init() <===========This does not work obviously. ... } } public function clean_sql($value){ $value = $this->db_connection->real_escape_string($value) <===========This does not work obviously. } } $db = new Make_Connection(); Now I know I need "$this" the reference a variable within itself, because this works just fine: public function make_connection(){ $this->db_connection = mysqli_connection("localhost","db_user","db_pw","db_name"); if(!$this->db_connection){ die("Databse connction failed: %s\n", mysqli_error()); } else { $db_select = mysqli_select_db($this->dbconnection, "db_name"); if(!$db_select){ die("Databse selction failed: %s\n", mysqli_error()); } } } Even if I left this part untouch it does not help with the "real_escape_string()". As well, like I said I want to make this most current moving forward, so I would like to impliment the stmt_init() command. I belive it comes down to syntax, if I am wrong please do excuse me. I tried serveral variation, including $this->db_connection::real_escape_strig(), all of them wrong of course. So if someone could clarify where I went wrong, or point me to the correct direction I would be greatful. Thanks all the same in advance.
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.