|
Posted by Sanders Kaufman on 08/26/07 22:53
stiki wrote:
> I can't seem to execute a DDL statement to create a table in my
> database.
>
> I'm able to connect to the database, because I tested if connection
> was created.
>
> I'm using fnRunSQL($sSQL) (see code below) to run the DDL command and
> the function returns false. Does anyone have any idea of what I could
> be doing wrong?
Wow - you're using code *I* wrote for CNET's Builder.com a half-decade
ago. "http://articles.techrepublic.com.com/5100-22-1045433.html"
That's cool - but it was buggy code then, and it's buggy code now.
For example - it returns a string or boolean - no telling which. And
since a string always equals true, then you can test for a false
condition, but not a true one - bad, bad, bad. *MY* bad, bad, bad.
That article encompassed the whole of my PHP db capabilities at the
time, all wrapped up into 6 buggy functions.
Today, I do all that stuff with a database class... hopefully, much better.
You can download the current version of that code at
"http://www.kaufman.net/bvckvs/redist/bvckvs_database.php.txt"
It works pretty damned well for me - but I was a buggy little
code-monkey then, and I'm a buggy little code-monkey now. That's my
warranty.
Still - to get what you wanted from that class, rename it to remove the
".txt" and set the variables at the top to your DBMS credentials and
then use this code:
require_once("bvckvs_database.php");
$oDB = new bvckvs_database();
$sSQL = "CREATE TABLE...";
if($oDB->RunSQL($sSQL) == false){
echo $oDB->ErrorMessage;
echo "<pre>" . $oDB->RecordSQL . "</pre>";
} else {
echo "OK";
}
One caveat - RunSQL is probably the only thing you can really use from
that class... unless you take out all the stuff that prefixes table
names with the unique identifier.
Hey, wait. I should refactor that right now. BRB
OK - I did it.
Setting the Unique Table Prefix to "(none)" (the default) keeps the rest
of the class from getting hinky with your table names.
Now, you can use the class's CreateTable and other functions, too.
Another caveat - actually, now I guess this is the only caveat :) - the
CreateTable function automatically creates a PK called "id" that is an
autonumber type. Because anybody who doesn't do that is an idjit and I
wanted to make it idjit-proof.
Navigation:
[Reply to this message]
|