Avatar billede acmed Nybegynder
10. oktober 2005 - 18:58 Der er 23 kommentarer

Mysql istedet for ODBC

Jeg har fundet et script der bruger et plugin, db_odbc.inc.
Mit problem er at min server ikke understøtter odbc - men kun mysql kommandoer.
Hvordan får jeg ændret dette script, således det virker på min server?
Avatar billede acmed Nybegynder
10. oktober 2005 - 18:59 #1
<?php
  /**************************************************************************\
  * phpGroupWare API - ODBC Database support                                *
  * Copyright (c) 1998,1999 SH Online Dienst GmbH Boris Erdmann,            *
  * Kristian Koehntopp                                                      *
  * ------------------------------------------------------------------------ *
  * This is not part of phpGroupWare, but is used by phpGroupWare.          *
  * http://www.phpgroupware.org/                                            *
  * ------------------------------------------------------------------------ *
  * This program is free software; you can redistribute it and/or modify it  *
  * under the terms of the GNU Lesser General Public License as published    *
  * by the Free Software Foundation; either version 2.1 of the License, or  *
  * any later version.                                                      *
  \**************************************************************************/
  /* $Id: class.db_odbc.inc.php,v 1.1.1.1 2001/07/11 13:51:09 sameon Exp $ */

class db {
  var $Host    = "";
  var $Database = "";
  var $User    = "";
  var $Password = "";
  var $UseODBCCursor = 0;

  var $Link_ID  = 0;
  var $Query_ID = 0;
  var $Record  = array();
  var $Row      = 0;
 
  var $Errno    = 0;
  var $Error    = "";

  var $Auto_Free = 0;    ## set this to 1 to automatically free results

  function connect() {
    if ( 0 == $this->Link_ID ) {
      $this->Link_ID=odbc_pconnect($this->Database, $this->User, $this->Password, $this->UseODBCCursor);
      if (!$this->Link_ID) {
        $this->halt("Link-ID == false, odbc_pconnect failed");
      }
    }
  }
 
  function query($Query_String) {
    $this->connect();
   
#  printf("<br>Debug: query = %s<br>\n", $Query_String);

#  rei@netone.com.br suggested that we use this instead of the odbc_exec().
#  He is on NT, connecting to a Unix MySQL server with ODBC. -- KK
#    $this->Query_ID = odbc_prepare($this->Link_ID,$Query_String);
#    $this->Query_Ok = odbc_execute($this->Query_ID);
       
    $this->Query_ID = odbc_exec($this->Link_ID,$Query_String);
    $this->Row = 0;
    odbc_binmode($this->Query_ID, 1);
    odbc_longreadlen($this->Query_ID, 4096);
   
    if (!$this->Query_ID) {
      $this->Errno = 1;
      $this->Error = "General Error (The ODBC interface cannot return detailed error messages).";
      $this->halt("Invalid SQL: ".$Query_String);
    }
    return $this->Query_ID;
  }
 
  function next_record() {
    $this->Record = array();
    $stat      = odbc_fetch_into($this->Query_ID, ++$this->Row, &$this->Record);
    if (!$stat) {
      if ($this->Auto_Free) {
        odbc_free_result($this->Query_ID);
        $this->Query_ID = 0;
      };
    } else {
      // add to Record[<key>]
      $count = odbc_num_fields($this->Query_ID);
      for ($i=1; $i<=$count; $i++)
        $this->Record[strtolower(odbc_field_name ($this->Query_ID, $i)) ] = $this->Record[ $i - 1 ];
    }
    return $stat;
  }
 
  function seek($pos) {
    $this->Row = $pos;
  }

  function metadata($table) {
    $count = 0;
    $id    = 0;
    $res  = array();

    $this->connect();
    $id = odbc_exec($this->Link_ID, "select * from $table");
    if (!$id) {
      $this->Errno = 1;
      $this->Error = "General Error (The ODBC interface cannot return detailed error messages).";
      $this->halt("Metadata query failed.");
    }
    $count = odbc_num_fields($id);
   
    for ($i=1; $i<=$count; $i++) {
      $res[$i]["table"] = $table;
      $name            = odbc_field_name ($id, $i);
      $res[$i]["name"]  = $name;
      $res[$i]["type"]  = odbc_field_type ($id, $name);
      $res[$i]["len"]  = 0;  // can we determine the width of this column?
      $res[$i]["flags"] = ""; // any optional flags to report?
    }
   
    odbc_free_result($id);
    return $res;
  }
 
  function affected_rows() {
    return odbc_num_rows($this->Query_ID);
  }
 
  function num_rows() {
    # Many ODBC drivers don't support odbc_num_rows() on SELECT statements.
    $num_rows = odbc_num_rows($this->Query_ID);
    //printf ($num_rows."<br>");

    # This is a workaround. It is intended to be ugly.
    if ($num_rows < 0) {
      $i=10;
      while (odbc_fetch_row($this->Query_ID, $i))
        $i*=10;

      $j=0;
      while ($i!=$j) {
        $k= $j+intval(($i-$j)/2);
        if (odbc_fetch_row($this->Query_ID, $k))
          $j=$k;
        else
          $i=$k;
        if (($i-$j)==1) {
          if (odbc_fetch_row($this->Query_ID, $i))
            $j=$i;
          else
            $i=$j;
        };
        //printf("$i $j $k <br>");
      };
      $num_rows=$i;
    }

    return $num_rows;
  }
 
  function num_fields() {
    return count($this->Record)/2;
  }

  function nf() {
    return $this->num_rows();
  }
 
  function np() {
    print $this->num_rows();
  }
 
  function f($Field_Name) {
    return $this->Record[strtolower($Field_Name)];
  }
 
  function p($Field_Name) {
    print $this->f($Field_Name);
  }
 
  function halt($msg) {
    printf("<b>Database error:</b> %s<br>\n", $msg);
    printf("<b>ODBC Error</b>: %s (%s)<br>\n",
      $this->Errno,
      $this->Error);
    die("Session halted.");
  }
}
?>
Avatar billede jakobdo Ekspert
10. oktober 2005 - 19:06 #2
Om det vil virker direkte oversat ved jeg ikke!
Men mange af de funktioner du bruger på ODBC, findes også som MYSQL!
Prøv at ret fra top til bund og se om det virker.
Avatar billede knagen7100 Novice
10. oktober 2005 - 19:08 #3
Har du prøvet at kigge i din php.ini fil. Her skal odbc.dll være aktivet. Endvidere skal odbc.dll også kunne findes i dit udvidelses bibliotek som er specificeret i php.ini.
Avatar billede acmed Nybegynder
10. oktober 2005 - 19:10 #4
hm, fandt denne fil et andet sted istedet:
db_mysql.inc
Virker vist.

Tilgengæd får jeg en anden fejl:
Fatal error: Cannot instantiate non-existent class: db_item

i denne linje:
$db = new DB_Item;
Avatar billede jakobdo Ekspert
10. oktober 2005 - 19:13 #5
Prøv at ret: $db = new DB_Item;
til: $db = new DB_Item();
Avatar billede acmed Nybegynder
10. oktober 2005 - 19:18 #6
hm, samme fejl selvom jeg retter det...
Avatar billede jakobdo Ekspert
10. oktober 2005 - 19:19 #7
Har du en klasse som hedder: db_item?
Avatar billede jakobdo Ekspert
10. oktober 2005 - 19:20 #8
Tror du ikke det skal være: $db_item = new db();
Avatar billede acmed Nybegynder
10. oktober 2005 - 19:21 #9
tjah, det er som sagt bare et script jeg prøver at rette til...
Nej, der er ikke nogen klasse der hedder db_item
Avatar billede jakobdo Ekspert
10. oktober 2005 - 19:26 #10
Hvad så med: $db_item = new db();
Avatar billede acmed Nybegynder
10. oktober 2005 - 19:32 #11
Ingen forskel ;-)
Avatar billede jakobdo Ekspert
10. oktober 2005 - 19:35 #12
Prøv at post alt din kode herind!
Avatar billede acmed Nybegynder
10. oktober 2005 - 19:37 #13
well, det er flere forskellige filer. Men den fil der først giver problemer er:

<?
// Shopping cart -- Argus & Freeland -- uses PHP4 sessions


// Set these to suit
$self = $PHP_SELF;  // this script
$shop = "shop.htm";  // return page
$ckout = "cart0.php";


/* Things your script can set on query string:
  item=xxx  Add item
  qty=n      Quantity to add (default 1)
  del=n    Delete n

*/


session_register("cart");

include("itemdb.inc");



function getitem($it) {  // look up item, price, etc.
  $db_item = new db();
  $db->query("select * from items where iid='$it'");
  if (!$db->next_record()) {
  return array("0.00","***");
  }
  return array($db->f("iunit"),$db->f("idesc"));
  }





// inform checkout that we were here
$cart[0]="ready";

if ($contpage!="") $shop=$contpage;
function delit($del) {
  global $cart;
  for ($i=$del;$i<count($cart)-1;$i++) {
  $cart[$i]=$cart[$i+1];
  }
  unset($cart[$i]);
  }

// getting ready to leave so update totals
if ($More!="" || $Update!="" || $Out!="") {
  for ($i=count($cart)-1;$i>0;$i--)
  {
  if ($q[$i]==0) {
      delit($i);
  } else {
    list($v,$oq)=$cart[$i];
    $cart[$i]=array($v,$q[$i]);
    }
  }
}
if ($Out!="") {  // checkout
header("Location: $ckout?" . SID);
exit;
}

if ($More!="") {  // continue shopping
  header("Location: $shop");
  exit;
  }


if ($del!="") {  // delete item
  delit($del);
// get rid of query string
  header("Location: $self?" . SID);
  exit;

  }

if ($item!="") {  // insert item
  list ($d1,$d2) = getitem($item);
  $n=1;
  if ($qty!="")  $n=$qty;
  if ($d2!="***")
    $cart[]=array($item,$n);
// get rid of query string
  header("Location: $self?" . SID);
  exit;
  }


?>
<HTML>
<HEAD><TITLE>Your shopping cart</TITLE>
</HEAD>
<body background="glotextb.gif">
<CENTER>
<IMG SRC=banner.gif HEIGHT=60 WIDTH=600>
</CENTER>
<h1>Your Shopping Cart</H1>
<FORM ACTION=<? print $self; ?> METHOD=POST>
<TABLE BORDER=1 WIDTH=75%>
<? if (count($cart)>1) { ?>
<TR BGCOLOR=GRAY><B>
<TD><B>Item</B></TD><TD><B>Quantity</B></TD>
<TD><B>Description</B></TD><TD><B>Unit Price</B></TD>
<TD><B>Total</B></TD><TD>&nbsp;</TD></TR>
<? } ?>
<?
$ptotal=0;
for ($i=1 ; $i<sizeof($cart);$i++) {
list($it,$q) = $cart[$i];
if ($it=="*deleted*") continue;
list($p,$d) = getitem($it);

print "<TR><TD>" . $it . "</TD>";
print "<INPUT TYPE=HIDDEN NAME='fit[$i]' VALUE='$it'>";
print "<TD><INPUT SIZE=5 NAME=\"q[$i]\" VALUE=" . $q . "></TD>";
print "<TD>" . $d . "</TD>";
print "<INPUT TYPE=HIDDEN NAME='fd[$i]' VALUE='$d'>";
print "<TD ALIGN=RIGHT >" . sprintf("%01.2f",$p) . "</TD>";
print "<INPUT TYPE=HIDDEN NAME='fp[$i]' VALUE='$p'>";
$lv =sprintf("%01.2f", $p * $q);
$ptotal = $ptotal + ($p * $q);
 
print "<TD ALIGN=RIGHT>" . $lv . "</TD>";
print "<TD ALIGN=CENTER>" . "<a href=$self?del=" . $i . ">Delete</A></TR>";
}
?>
</TABLE>
<?
  if (count($cart)<=1) print "<P>Your cart is empty</P>";
?>
<BR>
<? if (count($cart)>1) {
$fmt=sprintf("<BR>Total = %01.2f<BR>",$ptotal);
print $fmt;
}
?>
<BR>
<TABLE>
<TR><TD><INPUT TYPE=Submit Value="Continue Shopping" Name=More></TD>
<? if (count($cart)>1) { ?>
<TD><INPUT TYPE=Submit Value="Update Totals" Name=Update></TD>
<TD><Input Type=Submit Value="Check Out" Name=Out></TD>
<?  } ?>
</TR></TABLE>
</FORM>

</BODY>
</HTML>
Avatar billede acmed Nybegynder
10. oktober 2005 - 19:38 #14
jeg har så brugt db_mysql.inc istedet for db_odbc.inc
Avatar billede jakobdo Ekspert
10. oktober 2005 - 19:38 #15
Hvad har du i denne fil: include("itemdb.inc");
Avatar billede acmed Nybegynder
10. oktober 2005 - 19:40 #16
<?
include("db_mysql.inc");

$server =  '****';
$login =  ***';
$pass =  '***';
$db =  '***';


?>
Avatar billede jakobdo Ekspert
10. oktober 2005 - 19:41 #17
Hvad så i: include("db_mysql.inc");
Avatar billede acmed Nybegynder
10. oktober 2005 - 19:43 #18
Det bliver en masse kode der er postet efterhånden ;-)

<?php
  /**************************************************************************\
  * phpGroupWare API - MySQL database support                                *
  * Copyright (c) 1998-2000 NetUSE AG Boris Erdmann, Kristian Koehntopp      *
  * ------------------------------------------------------------------------ *
  * This is not part of phpGroupWare, but is used by phpGroupWare.          *
  * http://www.phpgroupware.org/                                            *
  * ------------------------------------------------------------------------ *
  * This program is free software; you can redistribute it and/or modify it  *
  * under the terms of the GNU Lesser General Public License as published    *
  * by the Free Software Foundation; either version 2.1 of the License, or  *
  * any later version.                                                      *
  \**************************************************************************/

  /* $Id: class.db_mysql.inc.php,v 1.1.1.1 2001/07/11 13:51:09 sameon Exp $ */

class db {
 

  /* public: connection parameters */
  var $Host    = $server;
  var $Database = $db;
  var $User    = $login;
  var $Password = $pass;

  /* public: configuration parameters */
  var $use_pconnect      = True;
  var $auto_stripslashes = False;
  var $Auto_Free    = 0;    ## Set to 1 for automatic mysql_free_result()
  var $Debug        = 0;    ## Set to 1 for debugging messages.
  var $Halt_On_Error = "yes"; ## "yes" (halt with message), "no" (ignore errors quietly), "report" (ignore errror, but spit a warning)
  var $Seq_Table    = "db_sequence";

  /* public: result array and current row number */
  var $Record  = array();
  var $Row;

  /* public: current error number and error text */
  var $Errno    = 0;
  var $Error    = "";

  /* public: this is an api revision, not a CVS revision. */
  var $type    = "mysql";
  var $revision = "1.2";

  /* private: link and query handles */
  var $Link_ID  = 0;
  var $Query_ID = 0;
 


  /* public: constructor */
  function db($query = "") {
      $this->query($query);
  }

  /* public: some trivial reporting */
  function link_id() {
    return $this->Link_ID;
  }

  function query_id() {
    return $this->Query_ID;
  }

  /* public: connection management */
  function connect($Database = "", $Host = "", $User = "", $Password = "") {
    /* Handle defaults */
    if ("" == $Database)
      $Database = $this->Database;
    if ("" == $Host)
      $Host    = $this->Host;
    if ("" == $User)
      $User    = $this->User;
    if ("" == $Password)
      $Password = $this->Password;

    /* establish connection, select database */
    if ( 0 == $this->Link_ID )
    {
      if ($this->use_pconnect)
        $this->Link_ID=mysql_pconnect($Host, $User, $Password);
      else
        $this->Link_ID=mysql_connect($Host, $User, $Password);

      if (!$this->Link_ID)
      {
        $this->halt("connect($Host, $User, \$Password) failed.");
        return 0;
      }

      if (!@mysql_select_db($Database,$this->Link_ID)) {
        $this->halt("cannot use database ".$this->Database);
        return 0;
      }
    }
   
    return $this->Link_ID;
  }

    /* This only affects systems not using persistant connections */
    function disconnect()
    {
        if($this->Link_ID <> 0)
        {
            @mysql_close($this->Link_ID);
            $this->Link_ID = 0;
            return 1;
        }
        else
        {
            return 0;
        }
    }

  function limit($start)
  {
    global $phpgw_info;

        echo '<b>Warning: limit() is no longer used, use limit_query()</b>';

    if ($start == 0) {
        $s = "limit " . $phpgw_info["user"]["preferences"]["common"]["maxmatchs"];
    } else {
        $s = "limit $start," . $phpgw_info["user"]["preferences"]["common"]["maxmatchs"];
    }
    return $s;
  }

  /* public: discard the query result */
  function free() {
      @mysql_free_result($this->Query_ID);
      $this->Query_ID = 0;
  }

  /* public: perform a query */
  /* I added the line and file section so we can have better error reporting. (jengo) */
  function query($Query_String, $line = "", $file = "") {
    /* No empty queries, please, since PHP4 chokes on them. */
    if ($Query_String == "")
      /* The empty query string is passed on from the constructor,
      * when calling the class without a query, e.g. in situations
      * like these: '$db = new db_Subclass;'
      */
      return 0;

    if (!$this->connect()) {
      return 0; /* we already complained in connect() about that. */
    };

    # New query, discard previous result.
    if ($this->Query_ID) {
      $this->free();
    }

    if ($this->Debug)
      printf("Debug: query = %s<br>\n", $Query_String);

    $this->Query_ID = @mysql_query($Query_String,$this->Link_ID);
    $this->Row  = 0;
    $this->Errno = mysql_errno();
    $this->Error = mysql_error();
    if (! $this->Query_ID) {
      $this->halt("Invalid SQL: ".$Query_String, $line, $file);
    }

    # Will return nada if it fails. That's fine.
    return $this->Query_ID;
  }

    // public: perform a query with limited result set
    function limit_query($Query_String, $_offset, $line = '', $file = '')
    {
        global $phpgw_info;

        if (is_array($_offset))
        {
            list($offset,$num_rows) = $_offset;
        }
        else
        {
            $num_rows = $phpgw_info['user']['preferences']['common']['maxmatchs'];
            $offset = $_offset;
        }

        if ($offset == 0)
        {
            $Query_String .= ' LIMIT ' . $num_rows;
        }
        else
        {
            $Query_String .= ' LIMIT ' . $offset . ',' . $num_rows;
        }

        if ($this->Debug)
        {
            printf("Debug: limit_query = %s<br>offset=%d, num_rows=%d<br>\n", $Query_String, $offset, $num_rows);
        }

        return $this->query($Query_String, $line, $file);
    }

  /* public: walk result set */
  function next_record() {
    if (!$this->Query_ID) {
      $this->halt("next_record called with no query pending.");
      return 0;
    }

    $this->Record = @mysql_fetch_array($this->Query_ID);
    $this->Row  += 1;
    $this->Errno  = mysql_errno();
    $this->Error  = mysql_error();

    $stat = is_array($this->Record);
    if (!$stat && $this->Auto_Free) {
      $this->free();
    }
    return $stat;
  }

  /* public: position in result set */
  function seek($pos = 0) {
    $status = @mysql_data_seek($this->Query_ID, $pos);
    if ($status)
      $this->Row = $pos;
    else {
      $this->halt("seek($pos) failed: result has ".$this->num_rows()." rows");

      /* half assed attempt to save the day,
      * but do not consider this documented or even
      * desireable behaviour.
      */
      @mysql_data_seek($this->Query_ID, $this->num_rows());
      $this->Row = $this->num_rows;
      return 0;
    }

    return 1;
  }

    function transaction_begin()
    {
        return True;
    }

    function transaction_commit()
    {
        return True;
    }

    function transaction_abort()
    {
        return True;
    }


  /* public: table locking */
  function lock($table, $mode="write") {
    $this->connect();
   
    $query="lock tables ";
    if (is_array($table)) {
      while (list($key,$value)=each($table)) {
        if ($key=="read" && $key!=0) {
          $query.="$value read, ";
        } else {
          $query.="$value $mode, ";
        }
      }
      $query=substr($query,0,-2);
    } else {
      $query.="$table $mode";
    }
    $res = @mysql_query($query, $this->Link_ID);
    if (!$res) {
      $this->halt("lock($table, $mode) failed.");
      return 0;
    }
    return $res;
  }
 
  function unlock() {
    $this->connect();

    $res = @mysql_query("unlock tables");
    if (!$res) {
      $this->halt("unlock() failed.");
      return 0;
    }
    return $res;
  }


  /* public: evaluate the result (size, width) */
  function affected_rows() {
    return @mysql_affected_rows($this->Link_ID);
  }

  function num_rows() {
    return @mysql_num_rows($this->Query_ID);
  }

  function num_fields() {
    return @mysql_num_fields($this->Query_ID);
  }

  /* public: shorthand notation */
  function nf() {
    return $this->num_rows();
  }

  function np() {
    print $this->num_rows();
  }

  function f($Name, $strip_slashes = "")
  {
    if ($strip_slashes || ($this->auto_stripslashes && ! $strip_slashes)) {
        return stripslashes($this->Record[$Name]);
    } else {
        return $this->Record[$Name];
    }
  }

  function p($Name) {
    print $this->Record[$Name];
  }

  /* public: sequence numbers */
  function nextid($seq_name) {
    $this->connect();
   
    if ($this->lock($this->Seq_Table)) {
      /* get sequence number (locked) and increment */
      $q  = sprintf("select nextid from %s where seq_name = '%s'",
                $this->Seq_Table,
                $seq_name);
      $id  = @mysql_query($q, $this->Link_ID);
      $res = @mysql_fetch_array($id);
     
      /* No current value, make one */
      if (!is_array($res)) {
        $currentid = 0;
        $q = sprintf("insert into %s values('%s', %s)",
                $this->Seq_Table,
                $seq_name,
                $currentid);
        $id = @mysql_query($q, $this->Link_ID);
      } else {
        $currentid = $res["nextid"];
      }
      $nextid = $currentid + 1;
      $q = sprintf("update %s set nextid = '%s' where seq_name = '%s'",
              $this->Seq_Table,
              $nextid,
              $seq_name);
      $id = @mysql_query($q, $this->Link_ID);
      $this->unlock();
    } else {
      $this->halt("cannot lock ".$this->Seq_Table." - has it been created?");
      return 0;
    }
    return $nextid;
  }

  /* public: return table metadata */
  function metadata($table='',$full=false) {
    $count = 0;
    $id    = 0;
    $res  = array();

    /*
    * Due to compatibility problems with Table we changed the behavior
    * of metadata();
    * depending on $full, metadata returns the following values:
    *
    * - full is false (default):
    * $result[]:
    *  [0]["table"]  table name
    *  [0]["name"]  field name
    *  [0]["type"]  field type
    *  [0]["len"]    field length
    *  [0]["flags"]  field flags
    *
    * - full is true
    * $result[]:
    *  ["num_fields"] number of metadata records
    *  [0]["table"]  table name
    *  [0]["name"]  field name
    *  [0]["type"]  field type
    *  [0]["len"]    field length
    *  [0]["flags"]  field flags
    *  ["meta"][field name]  index of field named "field name"
    *  The last one is used, if you have a field name, but no index.
    *  Test:  if (isset($result['meta']['myfield'])) { ...
    */

    /* if no $table specified, assume that we are working with a query */
    /* result */
    if ($table) {
      $this->connect();
      $id = @mysql_list_fields($this->Database, $table);
      if (!$id)
        $this->halt("Metadata query failed.");
    } else {
      $id = $this->Query_ID;
      if (!$id)
        $this->halt("No query specified.");
    }

    $count = @mysql_num_fields($id);

    /* made this IF due to performance (one if is faster than $count if's) */
    if (!$full) {
      for ($i=0; $i<$count; $i++) {
        $res[$i]["table"] = @mysql_field_table ($id, $i);
        $res[$i]["name"]  = @mysql_field_name  ($id, $i);
        $res[$i]["type"]  = @mysql_field_type  ($id, $i);
        $res[$i]["len"]  = @mysql_field_len  ($id, $i);
        $res[$i]["flags"] = @mysql_field_flags ($id, $i);
      }
    } else { /* full */
      $res["num_fields"]= $count;
   
      for ($i=0; $i<$count; $i++) {
        $res[$i]["table"] = @mysql_field_table ($id, $i);
        $res[$i]["name"]  = @mysql_field_name  ($id, $i);
        $res[$i]["type"]  = @mysql_field_type  ($id, $i);
        $res[$i]["len"]  = @mysql_field_len  ($id, $i);
        $res[$i]["flags"] = @mysql_field_flags ($id, $i);
        $res["meta"][$res[$i]["name"]] = $i;
      }
    }
   
    /* free the result only if we were called on a table */
    if ($table) @mysql_free_result($id);
    return $res;
  }

  /* private: error handling */
  function halt($msg, $line = "", $file = "")
  {
    global $phpgw;
    $this->unlock();                /* Just in case there is a table currently locked */

    $this->Error = @mysql_error($this->Link_ID);
    $this->Errno = @mysql_errno($this->Link_ID);
    if ($this->Halt_On_Error == "no")
      return;

    $this->haltmsg($msg);
   
    if ($file) {
        printf("<br><b>File:</b> %s",$file);
    }
    if ($line) {
        printf("<br><b>Line:</b> %s",$line);
    }

    if ($this->Halt_On_Error != "report") {
        echo "<p><b>Session halted.</b>";
        $phpgw->common->phpgw_exit(True);
    }
  }

  function haltmsg($msg)
  {
    printf("<b>Database error:</b> %s<br>\n", $msg);
    if ($this->Errno != "0" && $this->Error != "()") {
        printf("<b>MySQL Error</b>: %s (%s)<br>\n",$this->Errno,$this->Error);
    }
  }

  function table_names() {
    $this->query("SHOW TABLES");
    $i=0;
    while ($info=mysql_fetch_row($this->Query_ID))
    {
      $return[$i]["table_name"]= $info[0];
      $return[$i]["tablespace_name"]=$this->Database;
      $return[$i]["database"]=$this->Database;
      $i++;
    }
  return $return;
  }

  function create_database($adminname = "", $adminpasswd = "") {
        $currentUser = $this->User;
        $currentPassword = $this->Password;
        $currentDatabase = $this->Database;

        if ($adminname != "")
        {
            $this->User = $adminname;
            $this->Password = $adminpasswd;
            $this->Database = "mysql";
        }
        $this->disconnect();
        $this->query("CREATE DATABASE $currentDatabase");
        $this->query("grant all on $currentDatabase.* to $currentUser@localhost identified by '$currentPassword'");
        $this->disconnect();

        $this->User = $currentUser;
        $this->Password = $currentPassword;
        $this->Database = $currentDatabase;
        $this->connect();
        /*return $return; */
  }
}
?>
Avatar billede jakobdo Ekspert
10. oktober 2005 - 19:45 #19
Hmm, så burde $myDB = new db(); altså også virke!
Avatar billede acmed Nybegynder
10. oktober 2005 - 19:50 #20
ja... Kan det være noget server relateret?
Avatar billede jakobdo Ekspert
10. oktober 2005 - 19:52 #21
Nej, eller jo! (jeg tror det er php relateret) :o)
Avatar billede acmed Nybegynder
31. oktober 2005 - 20:23 #22
Har opgivet at bruge det alligevel - men smid et svar...
Avatar billede jakobdo Ekspert
31. oktober 2005 - 21:02 #23
Svar!
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Vi tilbyder markedets bedste kurser inden for webudvikling

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester