├── README.md └── public └── samples └── index.php /README.md: -------------------------------------------------------------------------------- 1 | # PHP Novice to Ninja 2 | 3 | Use the "Change Branch" above to select the relevant code sample. -------------------------------------------------------------------------------- /public/samples/index.php: -------------------------------------------------------------------------------- 1 | 2 | setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); 6 | 7 | } 8 | catch (PDOException $e) { 9 | echo '
' . $e . '
'; 11 | die; 12 | } 13 | 14 | 15 | try { 16 | //sample user might not exist so the query may throw an exception, that's fine, ignore it. 17 | try { 18 | //Drop the user, there's a chance the password has been changed 19 | $pdo->query('DROP USER \'ijdb_sample\'@\'localhost\''); 20 | } 21 | catch (PDOException $e) {} 22 | 23 | //Create the user for the sample code to use 24 | $pdo->query('CREATE USER \'ijdb_sample\'@\'localhost\' IDENTIFIED BY \'mypassword\''); 25 | 26 | //Drop the database, only one sample should be used at once. 27 | 28 | $pdo->query('DROP DATABASE IF EXISTS ijdb_sample'); 29 | 30 | 31 | $pdo->query('CREATE DATABASE ijdb_sample'); 32 | $pdo->query('GRANT ALL PRIVILEGES ON ijdb_sample.* To \'ijdb_sample\'@\'localhost\''); 33 | $pdo->query('FLUSH PRIVILEGES'); 34 | $pdo->query('USE ijdb_sample'); 35 | 36 | if (file_exists('../../database.sql')) { 37 | $pdo->exec(file_get_contents('../../database.sql')); 38 | } 39 | 40 | } 41 | catch (PDOException $e) { 42 | echo 'Could not create sample database/user'; 43 | echo $e->getMessage(); 44 | } 45 | 46 | 47 | exec('git status', $output); 48 | $branchName = str_replace('On branch ', '', $output[0]); 49 | 50 | if (isset($_GET['branch'])) { 51 | exec('git status', $status); 52 | $status = implode("\n", $status); 53 | if (strpos($status, 'nothing to commit') == false) { 54 | 55 | 56 | 57 | $parts = explode('_Modified', $branchName); 58 | $newBranchName = $parts[0] . '_Modified-' . date('Y-m-d-H.i.s'); 59 | 60 | 61 | exec('git checkout -b ' . $newBranchName . ' 2>&1', $z); 62 | 63 | exec('git add -A 2>&1', $x); 64 | exec('git commit -m "user modified sample" 2>&1', $y); 65 | 66 | var_dump($z); 67 | var_dump($y); 68 | var_dump($x); 69 | } 70 | exec('git checkout "' . $_GET['branch'] . '"', $n); 71 | $branchName = $_GET['branch']; 72 | } 73 | 74 | if (!isset($branchName)) { 75 | exec('git status', $output); 76 | $branchName = str_replace('On branch ', '', $output[0]); 77 | } 78 | 79 | 80 | ?> 81 | 82 | 83 |Click on a file to view in your browser
112 | 113 |