PHP - 如何在函数中使用SWITCH

I am trying to cut down on the amount of select statements, updates etc in my code so I thought that I would try to create a function for this, however I am puzzled that my efforts are failing at the first hurdle.

I have Googled this issue quite comprehensively (I feel) and I can't find any differences in the examples that I have found.

This is my function complete with print statements to help me diagnose the issue.

function select_statement($action, $table, $where){
print $action.' - ';

switch ($action){
    case 'select':
        print 'select used - ';
        $thequery = 'SELECT * FROM '. $table . ' WHERE '. $where;
    case 'insert':
        print 'insert used - ';
        $thequery = 'INSERT INTO '. $table;
    case 'update':
        print 'update used - ';
        $thequery = 'UPDATE ' . $table . ' SET ';
    }
print $thequery;
mysql_query($thequery);

}

This is the line that calls the function:-

$logins = select_statement('select', 'users', 'user_id=1');//calls function

This is the result:-

select - select used - insert used - update used - UPDATE users SET 

As you can see the code is triggering each of the print statements and seemingly ignoring the 'case' statements.

I'm really not sure what it is that I am doing wrong here?

You forgot to use break. Without it each case statement will "fall through" to the next one and continue operating. break stops execution at the end of each case statement`;

switch ($action){
    case 'select':
        print 'select used - ';
        $thequery = 'SELECT * FROM '. $table . ' WHERE '. $where;
        break;
    case 'insert':
        print 'insert used - ';
        $thequery = 'INSERT INTO '. $table;
        break;
    case 'update':
        print 'update used - ';
        $thequery = 'UPDATE ' . $table . ' SET ';
        break;
    }