MySQL::InsertRow PHP Method

InsertRow() public method

Inserts a row into a table in the connected database
public InsertRow ( string $tableName, array $valuesArray ) : integer
$tableName string The name of the table
$valuesArray array An associative array containing the column names as keys and values as data. The values must be SQL ready (i.e. quotes around strings, formatted dates, ect)
return integer Returns last insert ID on success or FALSE on failure
    public function InsertRow($tableName, $valuesArray)
    {
        $this->ResetError();
        if (!$this->IsConnected()) {
            $this->SetError("No connection");
            return false;
        } else {
            // Execute the query
            $sql = self::BuildSQLInsert($tableName, $valuesArray);
            if (!$this->Query($sql)) {
                return false;
            } else {
                return $this->GetLastInsertID();
            }
        }
    }

Usage Example

Beispiel #1
0
 public function addNew($data)
 {
     $db = new MySQL(true, 'color64', 'localhost', 'color64', 'nu5Jc4JdtZK4RCHH');
     $d = array('name' => MySQL::SQLValue(strtoupper(trim($data['u']))), 'password' => MySQL::SQLValue(MD5($data['p'])));
     $result = $db->InsertRow('users', $d);
     return $result;
 }
All Usage Examples Of MySQL::InsertRow