Php insert sql function

I want to create one insert function in php, which I will use to insert data into the database.

Of course, all inserts do not match, some use one table, others use another, tables have different column numbers, etc. What is the best way to do this?

Now I’m on the web page for registering participants, now I don’t want everyone to register, I want the administrator to approve which members will be approved and which will not, so I set one hidden field for 0 and after approval it becomes one .

CASE: Someone comes to the site and changes the value of the input field to 1 using firebug and sends the registration, automatically gets approval, I have not tried this, I'm just considering the possibility. Now, if I put member_active inside the insert function, it will not work for other insert queries with small / smaller column columns of the database.

What is the way to do this, in general it’s a good idea to insert in general / in general, I pretty much know how to program all of this, but lately I have become more careful about data / performance and things that can make your site better / worse so I want a good start. thank you

+3
source share
4 answers

CodeIgniter , :

function Insert($table, $data, $ignore = false)
{
    $sql = array();

    if (is_array($sql) === true)
    {
        $sql['query'] = 'INSERT ';

        if ($ignore === true)
        {
            $sql['query'] .= 'IGNORE ';
        }

        foreach ($data as $key => $value)
        {
            $data[$key] = Tick($key) . ' = ' . Quote($value);
        }

        $sql['query'] .= 'INTO ' . Tick($table) . ' SET ' . implode(', ', $data);
    }

    return implode('', $sql);
}

, Tick() Quote() escape .

+3

, , (. Zend_Db_Select, Doctrine_Query, Propel Criteria ..).

, , - , , ... , , .

+2

SQL- : (SP) DB.

, , , ( , ).

SP, SQL- :

$query = "EmployeeAdd('joe','smith','1970-12-22')";

( ), . , , , EmployeeGet() EmployeeUpdate(), , , : EmployeeGetByID() EmployeesGetByJobID()

, , Data + Action+. , , GetEmployeeByID(), SP, , .

+1

, , ( , , ). CI 0 , .

0

Source: https://habr.com/ru/post/1725989/


All Articles