00001 <?php 00002 require_once("safely-php/assert.php"); 00003 require_once("models/soc1c.php"); 00004 require_once("models/api1c.php"); 00005 00006 if (php_sapi_name() !== 'cli') { 00007 echo 'This should be run from the command line.'; 00008 exit(1); 00009 } 00010 00011 $assert->ok(file_exists("_conf/soc1c.conf"), "configuration file not found."); 00012 $api = new SOC_API1C(new SOC_Configuration("TEST db connect", "_conf/soc1c.conf")); 00013 $assert->ok($api, "Should have a new SOC_API1C object."); 00014 $assert->ok($api->open(), "Should be able to open db."); 00015 echo "Open: ".$api->message().PHP_EOL; 00016 00017 $sql = "REPLACE INTO test (id, email, name, url, published) VALUES (1, 'rsdoiel@usc.edu', 'R. S. Doiel', 'http://rsdoiel.github.io', NOW())"; 00018 $assert->ok($api->execute($sql), "Should be able to replace a row [$sql]"); 00019 00020 $sql = "SELECT * FROM test LIMIT 1;"; 00021 $assert->ok($api->execute($sql), "Should be able to execute [$sql]"); 00022 echo "SQL [$sql]: ".$api->message().PHP_EOL; 00023 echo "Should get some rows back.".PHP_EOL; 00024 $i = 0; 00025 while ($row = $api->getRow()) { 00026 echo "Row: ".print_r($row,true).PHP_EOL; 00027 $i += 1; 00028 } 00029 $assert->ok($i > 0, "Should have more then zero rows."); 00030 $api->close(); 00031 echo "Close DB: ".$api->message().PHP_EOL; 00032 ?>