FTP user. I upload some files. I create a database called
testOfSetupScript and then I create a database user named setup.
I write some PHP code which should, I think, be able to to auto create
the tables.
The SQL looks like this:
$str4 = <<<EOD
CREATE TABLE whatBelongsToWhat (
id int(11) NOT NULL auto_increment,
what int(11) NOT NULL default '0',
belongsToWhichPage int(11) NOT NULL default '0',
type varchar(255) NOT NULL default '',
belongsToWhichWebsite varchar(255) NOT NULL default '',
PRIMARY KEY (id)
) TYPE=MyISAM;
EOD;
global $db;
$formInputs = $GLOBALS["formInputs"];
if (is_object($db)) {
if (is_array($formInputs)) {
extract($formInputs);
$query = "SHOW TABLES FROM $dbName";
$result = $db->query($query);
$num = mysql_num_rows($result);
// 11-23-04 - this code runs every time the pages loads. Obviously
we don't want to
// run this code if the tables already exist. So we check for tables
first.
if ($num == 0) {
$db->query($str1);
$db->query($str2);
$db->query($str3);
$db->query($str4);
$query = "SHOW TABLES FROM $dbName";
$result = $db->query($query);
$num = mysql_num_rows($result);
if ($num == 4) {
echo "<p>The 4 parts of the database have been successfully
created</p>";
} else {
$errmsg = 'Query error: ' . mysql_error();
echo "<p>Awful sorry, there is a problem. The database should
have 4 tables but only has '$num'. $errmsg ";
}
} else {
if ($num < 4) {
echo "<p>The 4 parts of the database have been successfully
created</p>";
} else {
$errmsg = 'Query error: ' . mysql_error();
echo "<p>Awful sorry, there is a problem. The database should
have 4 tables but only has $num. $errmsg</p>";
}
}
}
} else {
echo "<p>Awful sorry, but the software expects a database object that
will allow us to connect to the database, but we don't seem able to
find or create the database object. Please make sure that the file
McDatastoreConnectorMySql.php was uploaded and is in the 'neededFiles'
folder.</p>";
}
}
I'm only showing one of the SQL statements for simplicity.
But I get these warnings:
Warning: Supplied argument is not a valid MySQL-Link resource in
/home/httpd/vhosts/publicdomainsoftware.org/httpdocs/setup/neededFiles/McDatastoreConnectorMySql.php
on line 349
Here is the method that is being flagged:
/*
error function
==============
terminates script execution with a message
*/
function error() {
die('('.mysql_errno($this->pp_linkid).')
'.mysql_error($this->pp_linkid));
}
Also I get this:
Warning: Supplied argument is not a valid MySQL result resource in
/home/httpd/vhosts/publicdomainsoftware.org/httpdocs/setup/neededFiles/createTheDatabaseTables.php
on line 175
which points to the last line here:
$query = "SHOW TABLES FROM $dbName";
$result = $db->query($query);
$num = mysql_num_rows($result);
I'm using this method to connect to the database. How do I trouble
shoot what the problem is?
/**
*
* 11-23-04 - this class gets called at the top of setup.php and it
becomes a
* global variable for the setup script. However, there is no
constructor so
* nothing is initialized. It's simply held in global space, ready to
be used.
*
*
*
*
*
*/
function connectToDs() {
// $db = $dbName;
// $server = "localhost";
// $user = "usr226042127";
// $password = "38F1yumgErcUY";
// $port = $db_port;
$formInputs = $GLOBALS["formInputs"];
if (is_array($formInputs)) {
extract($formInputs);
if ($dbUsername && $dbPassword && $dbName) {
$this->pp_linkid = mysql_connect($server.':'.$port, $user,
$password);
if ($this->pp_linkid) {
return true;
} else {
echo "<p>Awful sorry, but when we tried to reach the database,
using the username and password you provided, we failed to make a
connection. The most likely reason is that you mis-entered the database
username and password. Remember that the database username and password
are different from the username and password you'll use to reach the
cms.</p>";
}
$this->selectdb($dbName);
} else {
echo "<p>Awful sorry, but we're being asked to contact the
database, yet we don't yet have a database username or a database
password, nor the name of the database. Please fill those in and try
again. Use Plesk or talk to your admin to get a database username and
password. Please note that the database username and password are going
to be different from the username and password that you'll use to login
to the cms.</p>";
}
}
}
/*
selects the active database
===========================
*/
function selectdb($db) {
if (FALSE === @mysql_select_db($db, $this->pp_linkid)) {
$this->error();
}
}