63 $dsn = sprintf(
'mysql:dbname=%s;host=%s',
$db,
$host);
69 $this->pdo_instance =
new PDO($dsn,
$user, $passwd, $options);
70 }
catch (PDOException $e) {
71 echo
"Mysql",
"PDO instance", $e->getMessage();
90 $this->
halt(
'Mysql::connect() : This function should no longer be used');
101 if (!$this->pdo_instance) {
106 }
catch (PDOException $e) {
107 $this->
halt(
"Mysql::PDO_instance" . $e->getMessage());
121 $this->pdo_query->closeCursor();
126 return $this->pdo_instance != FALSE;
145 global $debug_alternc;
154 $debug_chrono_start = microtime(
true);
156 if ($arguments===
false) {
157 $this->pdo_query = $this->pdo_instance->query(
$Query_String);
158 $exec_state = is_object($this->pdo_query);
162 $this->pdo_query = $this->pdo_instance->prepare($this->Query_String);
163 $exec_state = ($arguments) ? $this->pdo_query->execute($arguments)
164 : $this->pdo_query->execute();
168 $debug_chrono_start = (microtime(
true) - $debug_chrono_start)*1000;
171 if ($exec_state == FALSE) {
172 if (is_object($this->pdo_query)) {
173 $this->Errno = $this->pdo_query->errorCode();
174 $this->Error = $this->pdo_query->errorInfo();
176 $this->Errno = $this->pdo_instance->errorCode();
177 $this->Error = $this->pdo_instance->errorInfo();
181 throw new \Exception(
"Mysql query failed : $this->Error");
187 if (isset($debug_alternc)) {
188 $debug_alternc->add(
"SQL Query : (".substr($debug_chrono_start,0,5).
" ms)\t $Query_String");
189 $debug_alternc->nb_sql_query++;
190 $debug_alternc->tps_sql_query += $debug_chrono_start;
206 if (!$this->pdo_query) {
207 $this->
halt(
"next_record called with no query pending.");
211 $this->Record = $this->pdo_query->fetch(PDO::FETCH_BOTH);
213 $this->Errno = $this->pdo_query->errorCode();
214 $this->Error = $this->pdo_query->errorInfo();
216 if ($this->Record == FALSE) {
217 if ($this->Auto_Free)
227 if (!$this->pdo_query) {
228 $this->
halt(
"next_record called with no query pending.");
232 $data = $this->pdo_query->fetchAll(PDO::FETCH_BOTH);
233 $this->Errno = $this->pdo_query->errorCode();
234 $this->Error = $this->pdo_query->errorInfo();
236 if ($data == FALSE) {
237 if ($this->Auto_Free)
247 if (!$this->pdo_query) {
248 $this->
halt(
"next_record called with no query pending.");
252 $data = $this->pdo_query->fetch(
$mode);
253 $this->Errno = $this->pdo_query->errorCode();
254 $this->Error = $this->pdo_query->errorInfo();
256 if ($data == FALSE) {
257 if ($this->Auto_Free)
273 if (is_array($table)) {
288 $this->
halt(
"lock($table, $mode) failed.");
303 if (!$this->
query(
'unlock tables')) {
304 $this->
halt(
"unlock() failed.");
314 if (!$this->pdo_query)
return 0;
315 return $this->pdo_query->rowCount();
318 if (!$this->pdo_query)
return 0;
319 return $this->pdo_query->rowCount();
323 if (!$this->pdo_query)
return 0;
324 return $this->pdo_query->columnCount();
344 if (isset($this->Record[$Name]))
345 return $this->Record[$Name];
357 print $this->Record[$Name];
362 return $this->pdo_instance->lastInsertId();
372 return $this->pdo_instance->quote(
$string);
382 return $this->pdo_instance->exec(
$query);
393 if ($this->
lock($this->Seq_Table)) {
395 $q = sprintf(
"select nextid from %s where seq_name = '%s'",
401 $id = $this->
f(
'nextid');
406 $q = sprintf(
"insert into %s values('%s', %s)",
415 $nextid = $currentid + 1;
416 $q = sprintf(
"update %s set nextid = '%s' where seq_name = '%s'",
423 $this->
halt(
"cannot lock ".$this->Seq_Table.
" - has it been created?");
436 $msg->raise(
"ERROR",
'Mysql',
'function is no longer implemented (metadata())');
444 if ($this->Halt_On_Error ==
"no")
449 if ($this->Halt_On_Error !=
"report")
450 die(
"Session halted.");
458 printf(
"</td></tr></table><b>Database error:</b> %s<br />\n",
$msg);
459 printf(
"<b>MySQL Error</b>: %s (%s)<br />\n",
461 implode(
"\n", $this->Error));
466 $this->
query(
"SHOW TABLES");
469 $return[] = array(
'table_name' => $this->
p(0),
'tablespace_name' => $this->Database,
'database' => $this->Database);
quote($string)
Escape a string to use it into a SQL PDO query.
free()
Discard the query result.
affected_rows()
evaluate the result (size, width)
halt($msg)
private: error handling
haltmsg($msg)
private: error handling
exec($query)
Execute a direct query, not getting any result back.
fetch($mode=PDO::FETCH_ASSOC)
lock($table, $mode="write")
table locking
query($Query_String, $arguments=false)
Perform a query.
__construct($db, $host, $user, $passwd)
Constructor: Connect to the database server.
next_record()
walk result set
nextid($seq_name)
get next sequence numbers
connect($Database="", $Host="", $User="", $Password="")
function for MySQL database connection management
metadata($table='', $full=false)
DEPRECATED return table metadata.
if(!isset($is_include)) if(! $key &&! $crt) $id
if(empty($_POST['key'])||empty($_POST['val'])) $key