本文整理汇总了PHP中pdo::exec方法的典型用法代码示例。如果您正苦于以下问题:PHP pdo::exec方法的具体用法?PHP pdo::exec怎么用?PHP pdo::exec使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pdo
的用法示例。
在下文中一共展示了pdo::exec方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: array
function __construct($host, $username, $password, $db)
{
$conn_para = "mysql:{$host};{$db};charset=utf8";
$opt = array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC);
$this->_pdo = new PDO($conn_para, $username, $password, $opt) or die('There is problem in connecting to database');
$this->_pdo->exec("USE " . $db);
self::$_instance = $this;
}
示例2: postCheckdb
public function postCheckdb()
{
if (!Session::get('step2')) {
return Redirect::to('install/step2');
}
$dbhost = Input::get('dbhost');
$dbuser = Input::get('dbuser');
$dbpass = Input::get('dbpass');
$dbname = Input::get('dbname');
Session::put(array('dbhost' => $dbhost, 'dbuser' => $dbuser, 'dbpass' => $dbpass, 'dbname' => $dbname));
try {
$dbh = new pdo("mysql:host={$dbhost};dbname={$dbname}", $dbuser, $dbpass, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
$sql = file_get_contents($_SERVER['DOCUMENT_ROOT'] . '/install/res/dump.sql');
$result = $dbh->exec($sql);
$databaseFile = file_get_contents($_SERVER['DOCUMENT_ROOT'] . '/install/res/database.php');
$databaseFile = str_replace(array('{DBHOST}', '{DBNAME}', '{DBUSER}', '{DBPASS}'), array($dbhost, $dbname, $dbuser, $dbpass), $databaseFile);
file_put_contents($_SERVER['DOCUMENT_ROOT'] . '/apps/frontend/config/database.php', $databaseFile);
file_put_contents($_SERVER['DOCUMENT_ROOT'] . '/apps/backend/config/database.php', $databaseFile);
Session::put('step3', true);
return Illuminate\Support\Facades\Redirect::to('install/step4');
} catch (PDOException $ex) {
Session::put('step3', false);
return Illuminate\Support\Facades\Redirect::to('install/step3')->with('conerror', 'Date invalide');
}
}
示例3: __construct
/**
* @param array $config
*/
public function __construct($config)
{
$_alldbtype = array('mysql', 'pgsql', 'mssql', 'sybase', 'dblib');
$driver_options = array(PDO::ATTR_EMULATE_PREPARES => false, PDO::ATTR_PERSISTENT => $config['persistent'], PDO::ATTR_CASE => PDO::CASE_LOWER, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC);
if (in_array($config['dbtype'], $_alldbtype)) {
$dsn = $config['dbtype'] . ':dbname=' . $config['dbname'] . ';host=' . $config['dbhost'] . ';charset=' . $config['charset'];
if (!empty($config['dbport'])) {
$dsn .= ';port=' . $config['dbport'];
}
$driver_options[PDO::ATTR_ERRMODE] = PDO::ERRMODE_EXCEPTION;
} elseif ($config['dbtype'] == 'oci') {
$dsn = 'oci:dbname=//' . $config['dbhost'] . ':' . $config['dbport'] . '/' . $config['dbname'] . ';charset=AL32UTF8';
$driver_options[PDO::ATTR_STRINGIFY_FETCHES] = true;
} elseif ($config['dbtype'] == 'sqlite') {
$dsn = 'sqlite:' . $config['dbname'];
} else {
trigger_error($config['dbtype'] . ' is not supported', 256);
}
$this->server = $config['dbhost'];
$this->dbtype = $config['dbtype'];
$this->dbname = $config['dbname'];
$this->user = $config['dbuname'];
try {
parent::__construct($dsn, $config['dbuname'], $config['dbpass'], $driver_options);
parent::exec("SET SESSION time_zone='" . NV_SITE_TIMEZONE_GMT_NAME . "'");
$this->connect = 1;
} catch (PDOException $e) {
trigger_error($e->getMessage());
}
}
示例4: dbConnect
function dbConnect($timeout, $options = array())
{
$db = new pdo(PDO_dsn, PDO_username, PDO_password);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
$db->setAttribute(PDO::ATTR_TIMEOUT, "0");
foreach ($options as $option) {
$db->exec($option);
}
return $db;
}
示例5: microtime
$var2 = microtime(true);
$var3 = $var2 - $var1;
// echo $var3;
// echo $object_public_url."<br>";
// print $thisfile;
// print $thatfile;
// var_dump($_FILES);
$db = new pdo('mysql:unix_socket=/cloudsql/ordinal-gear-93506:testdb;dbname=g1', 'root', '');
$stmt1 = $db->prepare("select * from another where filename='{$thatfile}'");
$stmt1->execute();
$row = $stmt1->fetch();
if ($row > 0) {
echo "duplicate entry";
// $db->exec("insert into users values('8975','200')");
} else {
$db->exec("insert into another values('','{$thatfile}','{$var6}','{$object_public_url}','{$var1}')");
// $db->exec("insert into finaltest values('','$thatfile','filesize($thisfile)','$object_public_url','$var3')");
$stmt = $db->prepare("select * from another ORDER BY filesize;");
$stmt->execute();
echo "<table border='2'>";
echo '<tr>';
echo '<th>ID:</th>';
echo '<th>FileName:</th>';
echo '<th>FileSize:</th>';
echo '<th>FileURL:</th>';
echo '<th>Tie Taken to upload:</th>';
echo '</tr>';
while ($row = $stmt->fetch()) {
$id = $row['id'];
$filename = $row['filename'];
$filesize = $row['filesize'];
示例6: exec
public function exec($sql)
{
if ($this->path_log_file) {
file_put_contents($this->path_log_file, $sql . "\n\n", FILE_APPEND);
}
++$this->querycount;
return parent::exec($sql);
}
示例7: array
)', 'implieds.csv::bind', 'licenses.csv::bind'), array('SELECT oc.licenses_upsert(
:id_label::text, :id_version::text, :name::text, :family::text, :name_of_equiv::text, :json_info::json
)', 'redundants.csv::bind')], 'openCoherence' => [array("SELECT oc.cached_xpaths_upsert(:jkey_group::int, :jkey::text, :transducer::int, :xpath_str::text, :dtds::text, :xpath_ns::text)", 'xpathTransducers.csv::bind'), array("INSERT INTO oc.repositories(repo_label,repo_name,repo_wikidataID,repo_url,repo_info) \n\t\t VALUES (:label, :name, :repo_wikidataID, :url, :json_info)", 'sciRepos.csv', 'lawRepos.csv'), array("SELECT oc.docs_upsert(\n\t\t\t 'lex:'||substring(:doc_authority from 1 for 2), NULL, \n\t\t\t (:doc_type||':'||:doc_year||':'||:doc_code)::text, \n\t\t\t NULL::xml, :json_info::JSON,\n\t\t\t :tmp_id::int, 1\n\t\t\t)", 'lawDocs.csv::bind', 'samples'), array("INSERT INTO oc.cited_objs(doc_id,citObj_theme,cited_info) \n\t\t VALUES (oc.docs_tmp2real(:tmp_id::int), :citObj_theme, :cited_info::JSON)", 'lawDocs-citationCases.csv')]];
$sql_delete = ' -- prepare to full refresh of oc.scheme
DELETE FROM oc.docs_tmp_relations WHERE session_id=1;
DELETE FROM oc.cached_xpaths;
DELETE FROM oc.cited_objs;
DELETE FROM oc.docs;
DELETE FROM oc.repositories;
DELETE FROM oc.licenses;
DELETE FROM oc.license_families;
';
// // //
// INITS:
$db = new pdo($dsn, $PG_USER, $PG_PW);
$stmt = $db->exec($sql_delete);
$SEP = ',';
$nmax = 0;
// 0 or debug with ex. 10
$n = 0;
foreach ($items as $prj => $r) {
foreach ($r as $dataset) {
$folder = $projects[$prj];
$sql = array_shift($dataset);
print "\n\n---- PRJ {$prj} {{ {$sql} }}";
$stmt = $db->prepare($sql);
$jpack = json_decode(file_get_contents("{$folder}/datapackage.json"), true);
$ds = array();
// only for "bind check".
foreach ($dataset as $i) {
$i = str_replace('::bind', '', $i, $bind);
示例8: pdo
// Connect from App Engine.
try {
$db = new pdo('mysql:unix_socket=/cloudsql/jens-first-php:sqlinstance2;dbname=guestbook2', 'root', '');
} catch (PDOException $ex) {
die(json_encode(array('outcome' => false, 'message' => 'Unable to connect.')));
}
} else {
// Connect from a development environment.
try {
$db = new pdo('mysql:host=127.0.0.1:3306;dbname=guestbook', 'root', '');
} catch (PDOException $ex) {
die(json_encode(array('outcome' => false, 'message' => 'Unable to connect')));
}
}
$sql = "CREATE TABLE MyFoodLog (\n id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,\n vitA INT(6) UNSIGNED,\n vitB12 INT(6) UNSIGNED\n ) ";
$db->exec($sql);
?>
<form method="post" action="/submit">
<table>
<tr>
<td>
Item
</td>
<td>
VitA
</td>
<td>
VitB12
</td>
</tr>