Re: [PHP] See if this makes any sense




You do *NOT* want to re-connect to the database on every InsertDB!

That's very expensive in resources/time.

Do that once in the constructor and be done with it for as many
Inserts as you need.

I'm baffled why you'd be rolling your own instead of using an existing
abstraction layer, and even more baffled why you wouldn't just skip
all this and just do:

$query = "insert ...";
$insert = mysql_query($query, $connection);

It's not like you can take your MySQL user-creating queries and
directly map them to ANY other database on the planet...

So what does the DB abstraction and class OOP stuff gain you?

Nada.

On Thu, October 5, 2006 2:18 pm, Deckard wrote:
Hi,

I've burned my brain, checked other sites and come to a code that
works.

I ask you, please, to see if this makes any sense and/or can be
improved.

I'd really appreciate.

Warm Regads,
Deckard

dbInsert.php:
-------------------------------------------------------------------
<?php

/*
* class to make inserts
*
*/


// includes
include_once('/var/www/html/config.inc.php');
include_once('adodb/adodb.inc.php');

class dBInsert
{
// global variables
var $table;
var $sql;

// constructor
function dBInsert($table, $sql)
{
$this->table = $table;
$this->sql = $sql;

return(TRUE);
}


// function that constructs the sql and inserts it into the database
function InsertDB($table, $sql)
{

print($sql);
// connect to MySQL
$conn = &ADONewConnection('mysql');
$conn->debug=1;
$conn->PConnect('localhost', 'gamito', 'ble', 'wordlife');

// execute the insert
if ($conn->Execute($sql) === false)
print 'error inserting: '.$conn->ErrorMsg().'<BR>';

return (TRUE);

}

}

?>
------------------------------------------------------

testedb.php
------------------------------------------------------
<?php

include_once("classes/dBInsert.php");

$sql = "INSERT INTO wl_admins VALUES ('',3)";
$dBInsert = new dBInsert('wl_admins', $sql);
$dBInsert->InsertDB('wl_admins', $sql);

?>
------------------------------------------------------

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




--
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some starving artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?
.



Relevant Pages

  • Re: Techniques for Vulneability discovery
    ... in mind) so i searched the net for some free database driven software and came ... the first thing i did was grab some info about PHP programming and some MySQL ... I did some more reasearch on different types of web based "input validation" ... PHP and SQL docs, etc.. ...
    (Vuln-Dev)
  • Re: Techniques for Vulneability discovery
    ... in mind) so i searched the net for some free database driven software and came ... the first thing i did was grab some info about PHP programming and some MySQL ... I did some more reasearch on different types of web based "input validation" ... PHP and SQL docs, etc.. ...
    (Security-Basics)
  • Help! PHP/SQL Brain freeze
    ... This is my first venture into PHP and SQL so i'm pretty much throwing ... this database and displayed in the browser window. ... I've set up apache http server and PHP ... stopped working completely. ...
    (comp.lang.php)
  • Re: [PHP] is there a problem with php script pulling HTML out of database as it writes the page??
    ... I even had one tell me "SQL injection? ... The big Daddy database spends lots of CPU cycles on the big Momma ... And PHP can't be used for foreign language sites, ...
    (php.general)
  • Re: PHP MySQL Single Iteration for data manipulation
    ... In both cases increment the question count and move ... you want only 1 row from the database. ... If you want to use MySQL, I would suggest reading some tutorials on SQL / ... don't try to let PHP sort it out. ...
    (comp.lang.php)