1

If I use methods e.g. insert, update in ZF Will I be safe(mysql injection)?

for example a part of code:

            $data = array(
                'autor' => $autor,
                'title' => $title,
                'text' => $text,
                'date' => $date,
            );
            $news = new News();
            $news->insert($data); // safe?
1
  • May be this answer can help. Commented Oct 14, 2011 at 7:17

3 Answers 3

1

Similar question here:

How to prevent SQL Injection attack in applications programmed in Zend Framework?

Always make sure you sanitize user input values using mysql_real_escape_string

Sign up to request clarification or add additional context in comments.

Comments

1

I think it will be fine just the way you have it. I mean one of the advantages of using PDO ext is to prevent SQL injections using PHP instead of MySQL to query the database. Here is more from devzone.zend.com

Comments

1

It's fine the way you are doing it. But be careful with mysql-expressions. There you should use a Zend_Db_Expr-Object:

$data = array(
    'author' => 'John Doe',
    'title' => 'Headline goes here',
    'text' => 'The content...',
    'date' => new Zend_Db_Expr('NOW()') //  <--- use this for SQL-Expressions
);
$news = new News();
$news->insert($data);

2 Comments

Actually any expression containing () will be converted automaticaly ;)
framework.zend.com/manual/en/zend.db.table.html Look at Example #13 and the text above: By default, the values in your data array are inserted as literal values, using parameters. If you need them to be treated as SQL expressions, you must make sure they are distinct from plain strings. Use an object of type Zend_Db_Expr to do this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.