Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7574317
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T16:24:25+00:00 2026-05-30T16:24:25+00:00

I have created my own mvc pattern based on the codeigniter framework style. My

  • 0

I have created my own mvc pattern based on the codeigniter framework style. My problem now is that i want to prevent from SQL injection, and for that purpose i would like to use mysql_real_escape_string(). But for when i use it, it keeps erroring since it apparently don’t have a the “link/source” to the database?

I get the php error:

Warning: mysql_real_escape_string(): Can’t connect to local MySQL
server through socket ‘/var/lib/mysql/mysql.sock’ (2) in
/hsphere/local/home/../dev/simple_blog/models/users_model.php on line
8

Warning: mysql_real_escape_string(): A link to the server could not be
established in
/hsphere/local/home/../dev/simple_blog/models/users_model.php on line
8

I don’t quite understand why though, since i can get stuff in and out of my DB but for some reason i can’t protect it???

Here is my function giving the error

public function getUserByName($username){
    $username = mysql_real_escape_string($username);
    $sql = "SELECT * FROM ".$this->db_table." WHERE username='".$username."' LIMIT 1";
    $q = $this->db->query($sql);

    if($q->rowCount() > 0){
      foreach($q->fetch() as $key => $row){
        $data[$key] = $row;
      }
      return $data;
    }
  }

As you can see I use mysql_real_escape_string() at the top, and then later on, do query stuff. Anyone know why this don’t work and if yes, how would i fix it?

NOTE: Im not a shark to PDO, and $this->db is the PDO class.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T16:24:26+00:00Added an answer on May 30, 2026 at 4:24 pm

    To use mysql_real_escape_string you’ll need to connect to the database server first, using the MySQL Functions, which you probably don’t have done.

    You are mixing up two completely different PHP extensions: mysql and PDO!

    Also, you don’t need to escape strings, when using PDO prepared statements, that’s done via PDO for you.

    An example using PDO:

    $userDataStmt = $this->database->prepare('SELECT * FROM ' . $this->db_table . ' WHERE username = :username LIMIT 1');
    $userDataStmt->bindValue(':username', $username);
    $userDataStmt->execute();
    if(!$userDataStmt->rowCount() <= 0)
    {
        $result = $userDataStmt->fetchAll();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have create my own NSOpenGLView class, right now the data that i want
I have my own hand-rolled PHP MVC framework for some projects that I'm working
Fairly straightforward question: I know that Codeigniter is a MVC framework - however what
I'm implimenting my own ApplicationContext class that uses the singleton pattern. I want to
I have just started playing with the ASP.Net MVC framework, and today I created
I have a problem with the understanding MVC architecture. It's not that I don't
I have created my own Tree implementation for various reasons and have come up
I have created my own Attached Property like this: public static class LabelExtension {
I have my own asp.net cookie created like this: var authTicket = new FormsAuthenticationTicket(
i have a big Joomla 1.5 Problem. I'll create my own Gallery Component/PlugIn and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.